Skip to content

alpersonalwebsite/node-typescript-express-postgresql-db-migrate

Repository files navigation

Node, TS, Express, PostgreSQL and migrations with db-migrate

Under development

Overview

This is an easy, basic and raw example of HOW to implement ???

Requirements

  • Node 12+
  • NPM
  • PostgreSQL
  • db-migrate package as a global dependency

Install dependencies

npm install

DB

Create databases

(... for dev and test)

createdb test_db
createdb test_db_test

Migration

Run the first migration

db-migrate create migration-for-users-table --sql-file

Add the SQL statements

... to the newly created *.sql files.

migrations/sqls/20210811211022-migration-for-users-table-up.sql

CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(50), age integer);

migrations/sqls/20210811211022-migration-for-users-table-down.sql

DROP TABLE users;

Run the migration

npm run migrate:up

This will run migrations for the dev environment.

If you want to do it in other environment, for example test, you need to have the stage and its configuration data in the database.json file and pass the proper flag.

Sample usage:

db-migrate up --env test 

Running the server

Development

npm run dev

Production

npm run build

npm start

About

Node, Typescript, Express, PostgreSQL and migrations with db-migrate

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published