Skip to content

Instantly share code, notes, and snippets.

@theptrk theptrk/readme.md
Last active Jan 21, 2019

Embed
What would you like to do?
Migrate a postgres database with sequelize.js

Migrate postgres database with sequelize.js

Part I: Set up postgres and sequelize

  • Start the postgresql server using brew and ensure relaunch on login more
$ brew services start postgresql

If needed, install postgresql with $ brew install postgresql and note the version installed.

  • Create a postgres database to use
$ psql postgres
psql> CREATE DATABASE kale;

Note the ending semi-colon ;

  • Install postgresql sequelize and sequelize cli for your project
$ npm i --save pg sequelize sequelize-cli
  • Run the sequelize init command
$ node_modules/.bin/sequelize init

This will create the folders config, migrations, models and seeders

Part II: Create and run migrations

  • Create the model and migration files
$ node_modules/.bin/sequelize model:generate --name User \
  --attributes firstName:string,lastName:string,email:string

This will:

  • Create a user model file in our models directory

  • Create a timestamped migration file in our migrations directory

  • Run the migration

$ node_modules/.bin/sequelize db:migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.