#TypeORM Migrations

6 messages · Page 1 of 1 (latest)

fiery iris
#

Hey all, I have made a project in the past without migrations, which I now deeply regret. I have since created and setup migrations for this project but now the issue is implementing this with my production environment. For my dev environment I scrapped the entire database making the transition seamless (just without data...)

In my production environment we obviously don't want to delete the databases and the data. We do have backups of the databases, but we would like guidance on how we can implement our new migrations into the production environment. I have made an attempt to do it, however the migrations is giving me errors that the tables already exist (obviously), and when I remove the CREATE TABLE definitions in my migration file, I then get errors with my constraints.

What would be the easiest way to go about this?

limber helm
#

postgres has create if not exists

fiery iris
# limber helm postgres has create if not exists

So even if I wasn't creating the tables I still get errors with the keys for my ALTER TABLE definitions when adding the constraints.

The specific error would be "Duplicate key on write or update". As I stated previously, I already have this database setup and the schema is essentially the same, but some constraints dont exist, while some do (from my poor database management in the past). Should transitioning from a non-migration-ready project to a migration-ready project be seamless? Or is it bound to have errors

limber helm
#

sorry, don't know that much about this kind of thing :c

stiff bay
#

How about setting up a second instance that uses a different database which gets managed through migrations?
Then export and import the data from the production to this second db .. if it works you are fine and might only switch the live system over to the new database. If it does not work, you can fiddle around what needs to be changed in order to make the import work.
And of course once the import works, you want to have a small maintenance window so nobody is writing to the database while migrating the data.

#

The specific error would be "Duplicate key on write or update". looks like some entries might be wrong though, so you would manually need to either remove the duplicate insert line or de-duplicate those keys.
I have the feeling when importing on a fresh database, you clearly see the error upon inserting data - which makes it easier to find and fix one problem at a time.