-
Notifications
You must be signed in to change notification settings - Fork 4
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
BUG: TypeORM does not generate correct migrations. #1344
Comments
There is a merged PR that should resolve the issue with the database name in the migrations: typeorm/typeorm#8038 which is still not in a release. |
After merging of typeorm/typeorm#5714 they've change the default Possible Solutions:
There are some disturbing queries in the migrations: `ALTER TABLE \`alkemio2\`.\`credential\` DROP COLUMN \`id\``
`ALTER TABLE \`alkemio2\`.\`credential\` ADD \`id\` char(36) NOT NULL PRIMARY KEY` DOWN: `ALTER TABLE \`alkemio2\`.\`credential\` DROP COLUMN \`id\``
`ALTER TABLE \`alkemio2\`.\`credential\` ADD \`id\` varchar(36) NOT NULL`
`ALTER TABLE \`alkemio2\`.\`credential\` ADD PRIMARY KEY (\`id\`)` This migrations are dropping and recreating the ID column for a few tables. MySQL doesn't have a mechanism to generate UUID ids automatically out of the box and additional code might be required. |
I've tested solution 2 briefly and it might not work. :( |
Option 2 sounds like the better option. Suprised there is not an option in their config that we can set what the default for ON UPDATE should be. Re the migrations that are dropping / recreating ids, are these in our existing migrations or in the new ones that are being generated? |
The new ones. |
New release is out that seems to have some updates in migrations: https://github.com/typeorm/typeorm/releases/tag/0.2.38 |
and another release: https://github.com/typeorm/typeorm/releases/tag/0.2.39 - with another at least one migration fix... |
and two more releases...https://github.com/typeorm/typeorm/releases/tag/0.2.41 |
typeorm/typeorm#8038 from 0.2.38 also breaks pretty much anyone with existing data generated by an older TypeORM version (0.2.37 in this case). It is now attempting to recreate tables that already exist. I imagine a fix would be to dump -> drop -> recreate -> reimport, but that's very high effort and requires a real maint window. |
Describe the bug
After upgrading to nestJS 8 and typeORM 0.2.35 the generated migrations contain a lot of differences.
To Reproduce
Steps to reproduce the behavior:
npm run migration:run
npm run migration:generate <name for the migration>
Expected behavior
The newly migration should contains empty UP and Down methods
The newly generated migration should not contain the schema name.
Additional context
Sometimes the typeorm doesn't take into account the env variables from the
.env
file.The generated FKs, PKs and indexies are different than existing one, so the issue maybe related to changes in our model.
This two queries are from the first and last migrations. The SQL from the last migration has been amended (removed the schema name, and escape backslashes) to look like the one from the first.
It seems like we updated the
ON UPDATE
action without generating a new query. Unfortunately there is no change in the code related to theON UPDATE
action, so the problem seems related to the TypeORM and changes they've made between0.2.32
and0.2.35
versionsThe text was updated successfully, but these errors were encountered: