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

Make it easier to change migrations in development #88

Open
pcaisse opened this issue Apr 20, 2020 · 1 comment
Open

Make it easier to change migrations in development #88

pcaisse opened this issue Apr 20, 2020 · 1 comment

Comments

@pcaisse
Copy link
Contributor

pcaisse commented Apr 20, 2020

Detailed Description/Context

Currently, the "happy path" workflow for adding a new migration is straightforward:

  1. Make changes to an entity that would necessitate a migration
  2. Run ./scripts/yarn server migration:generate to generate the new migration, determining what changes are necessary based on changes to the entity
  3. Run ./scripts/migration to apply the migration to your development database

However, if you need to make further changes to a migration after you've generated it -- eg. rename a field, add a missing constraint -- without wanting to generate a new migration for just that change, that's where things get weird. If you want a totally new migration you need to first:

  1. Revert the applied migration that you want to change if needed (this makes sense)
  2. Delete the auto-generated migration (this makes sense)
  3. Delete the dist files generated for the migration you want to edit (path is configured in ormconfig.js, currently src/server/dist/server/migrations/).

This is because the files within dist are what typeorm actually uses to know what should happen to your database.

Alternatives/Possible Solutions

To work around it, we could:

  1. Never update a migration and just keep creating new ones. The downside to this is there will potentially be a bunch of artifact migrations that reflect intermediate steps in the development process, perhaps akin to unsquashed commits, except they could actually impact production.
  2. Create migrations by hand or edit existing migrations by hand (this seems error prone)

To mitigate/solve it:

  1. Document deleting files in the dist directory
  2. Create some scripts/tooling for updating a migration more seamlessly in development
  3. Maybe there's a better way to handle this ???
@maurizi
Copy link
Contributor

maurizi commented May 12, 2022

I think after looking into this a bit recently, we could switch to using ts-node to run migrations, so it would use the TypeScript files instead of the compiled JS files, which would make this a bit less painful.

Not sure if that would have any implications on running migrations in staging / production; I'm fairly certain we ship .ts files even if we only run the compiled .js files normally, but it would be important to test before making such a change.

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

5 participants