How to migrate Postgres databases

1. Use pg-migrate as a global command

migration-folder
--up
----001-add-sample-1.sql
----001-add-sample-2.sql
----001-add-sample-3.sql
--down
----001-add-sample-1.sql
----001-add-sample-2.sql
----001-add-sample-3.sql
pg-migrate up - migration-folder your-migration-folder - host host-name - database database-name - port port - user user-name - password password
pg-migrate up - migration-folder ./db-migration - host localhost - database sample - port 5432 - user postgres - password postgres
Migration table
pg-migrate up 002-add-sample-2 - migration-folder ./db-migration - host localhost - database sample - port 5432 - user postgres - password postgres
pg-migrate down 002-add-sample-2 - migration-folder ./db-migration - host localhost - database sample - port 5432 - user postgres - password postgres
Parameters

2. Use pg-migrate as a local command

Install the package as a dep dependency in your project

npm install - save-dev @tqt/pg-migrate
yarn add -D @tqt/pg-migrate
npx pg-migrate up - migration-folder your-migration-folder - host host-name - database database-name - port port - user user-name - password password

3: Run it in your code

Install the package as a dep dependency in your project

npm install - save-dev @tqt/pg-migrate
yarn add -D @tqt/pg-migrate
nodejs script

--

--

Software developer. Interested in web/mobile application development with React, React Native, Typescript, Nodejs and AWS.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store