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

Squashed migrations #39

Closed
jukkah opened this issue Nov 26, 2015 · 6 comments
Closed

Squashed migrations #39

jukkah opened this issue Nov 26, 2015 · 6 comments
Milestone

Comments

@jukkah
Copy link
Contributor

jukkah commented Nov 26, 2015

Is there any way to combine migrations to squashed migrations and run them instead of the original migrations? Currently no, I guess.

As you know, if there is a zillion of migrations, running them all from the beginning to the end may take a while. In addition, if you have [email protected] and you upgrade it to [email protected], performance of the database migration matters.

For example, Django have some kind of implementation for squashed migrations. I'm not sure if Django replaces migrations with squashed ones, but I think it's better to save them just in case. So there should be all the migrations plus some squashed migrations.

migrations

In the picture above, black dots are migrations created between releases. Bellow the migrations are squashed migrations. In this example, there are squashes for each minor and major release and one from the beginning to the latest release.

I think, in umzug, we need only

  • a list of migrations combined into each squashed migration,
  • a way to figure out what squash to use if any, and
  • a way to make difference between migrations and squashes.

I can implement this feature but it needs some discussion first.

@sdepold
Copy link
Member

sdepold commented Nov 26, 2015

How would this mechanism be applied? Is that a runtime feature that is executed when running up or down or is it an extra command that squashes the existing migrations?

@jukkah
Copy link
Contributor Author

jukkah commented Nov 26, 2015

This would be a runtime feature. Because we don't care about implementations of up and down functions, we don't need to analyze them to figure out how to squash them. If some other libraries can create migrations they should also squash them.

My vision of squash file is to follow syntax of migration file:

'use strict';

var Bluebird = require('bluebird');

module.exports = {
  // List of migrations squashed in this squash file.
  migrations: ['some-id', 'some-other-id'],

  up: function () {
    return new Bluebird(function (resolve, reject) {
      // Describe how to achieve the task.
      // Call resolve/reject at some point.
    });
  },

  down: function () {
    return new Bluebird(function (resolve, reject) {
      // Describe how to revert the task.
      // Call resolve/reject at some point.
    });
  }
};

When running up and down we (un)log each of listed migrations.

These files should be stored in squashes sub-directory or something like that. Another way is to use file names not starting with number. This allows us to require them all at the beginning and then figure out the "best way".

@sdepold
Copy link
Member

sdepold commented Nov 27, 2015

tbh I don't see a major benefit unless we are also implementing this:

then running an optimizer over them to try and reduce the length of the list - for example, it knows that CreateModel and DeleteModel cancel each other out, and it knows that AddField can be rolled into CreateModel.

are you planning to do this too? or are we just talking about the amount of migrations being executed?

@jukkah
Copy link
Contributor Author

jukkah commented Nov 27, 2015

Yeah, of course, you got the point. 👍

@sdepold
Copy link
Member

sdepold commented Nov 30, 2015

Alright. The interesting part is that umzug is a framework agnostic tool which you may or may not use with Sequelize. While I don't mind have a good portion of sequelize specific helpers in umzug please keep in mind that umzug is can also be used without sequelize and with any available sequelize versions out there.

jukkah added a commit to jukkah/umzug that referenced this issue Dec 8, 2015
Added support for squashed migrations. Running migrations will try to apply
some squashes and run them as they were regular migrations. Running squash
will (un)log multiple migrations at the same time.

See [Django documentation][1] for more information of squashed migrations.

[1]: https://docs.djangoproject.com/en/1.9/topics/migrations/#squashing-migrations
@jukkah jukkah added this to the 2.0 milestone Mar 31, 2016
@papb
Copy link
Member

papb commented Oct 11, 2020

tbh I don't see a major benefit unless we are also implementing this:

then running an optimizer over them to try and reduce the length of the list - for example, it knows that CreateModel and DeleteModel cancel each other out, and it knows that AddField can be rolled into CreateModel.

are you planning to do this too? or are we just talking about the amount of migrations being executed?

I agree, without this there wouldn't be an advantage. And this would clash with umzug being framework agnostic.

I will close as wontfix. Maybe this can be implemented in the Sequelize CLI at some point. But I also think this is too complex to be worth it right now 😅

@papb papb closed this as completed Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants