Home > Back-end >  Getting SQL query from a database
Getting SQL query from a database

Time:05-30

We have a postgres database which is connected using typeorm, and unfortunately all development was done using {synchronize: true} option in typeorm configuration settings leaving us with no migration. Now writing migration for each one of it will be a heavy task.

I was curious if we can get the SQL query for creating the db with existing tables and columns??

CodePudding user response:

You should be able to dump the entire database and then import it.

CodePudding user response:

With typeorm you can do:

npx typeorm migration:generate -n InitialMigration

see enter link description here

P.s. if it doesn't create the table query because they are already in the DB, drop everything from Database and run the command. Or run the migration command pointing to an empty database.

P.p.s. If the command is not found with npx, you can try

./node_modules/.bin/ts-node ./node_modules/.bin/typeorm migration:generate ...
  • Related