Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration #13

Open
stombre opened this issue Sep 4, 2020 · 0 comments
Open

Migration #13

stombre opened this issue Sep 4, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@stombre
Copy link
Contributor

stombre commented Sep 4, 2020

Make a system to manage migration?

we could do a up / down system? to apply / migrate data depending of the stage?

// Or connector?
await ilorm.applyMigration()

Schema.version(timestamp or version? or both?, DEF)
  .up((old, new) => {})
  .down((old, new) => {})

ex;

// Always most recent version;
const userSchema = new Schema({
  id: Schema.string(),
  firstName: Schema.string(),
  lastName: Schema.string(),
  age: Schema.number(),
})

// Declare old version of the schema;
userSchema.version(3232323, {
  id: Schema.string(),
  name: Schema.string(),
  age: Schema.string(),
})
.up(UserModel => {
  UserModel.query()
    .stream()
    .on('data', user => {
      const [firstName, lastName] = user.name.split(' ');
      user.firstName = firstName;
      user.lastName = lastName;
      user.age = parseInt(user.previous.age)
      user.save();
    });
})
.down(UserModel => {
  UserModel.query()
    .stream()
    .on('data', user => {
       user.name = `${user.firstName} ${user.lastName}`;
       user.age = `${user.previous.age}`
       user.save();
     });
});

Keep in mind;

  • We probably want a way to up / down, and change multiple model at once.
  • We want to apply up and down for similar version schema on different model at the same time.

The way to proceed is probably;
for each schema version;

  1. Create new column / alter old column (for keeping data)
  2. Run up on every schema of the given version of the schema
  3. Drop old column
@stombre stombre added the enhancement New feature or request label Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant