All Projects → andywer → plow

andywer / plow

Licence: MIT license
👨‍🌾 Postgres migrations and seeding made easy

Programming Languages

typescript
32286 projects
Dockerfile
14818 projects
shell
77523 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to plow

Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+59223.08%)
Mutual labels:  postgres, migrations, migration
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+6346.15%)
Mutual labels:  postgres, migrations, migration
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+17707.69%)
Mutual labels:  postgres, migrations, migration
Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+16146.15%)
Mutual labels:  postgres, migrations, migration
Express Typescript Boilerplate
A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
Stars: ✭ 2,293 (+17538.46%)
Mutual labels:  migrations, seed, seeding
Rpg Boilerplate
Relay (React), Postgres, and Graphile (GraphQL): A Modern Frontend and API Boilerplate
Stars: ✭ 62 (+376.92%)
Mutual labels:  postgres, migrations
Fizz
A Common DSL for Migrating Databases
Stars: ✭ 92 (+607.69%)
Mutual labels:  postgres, migrations
Polluter
The easiest solution to seed database with Go
Stars: ✭ 146 (+1023.08%)
Mutual labels:  postgres, seed
Fluentmigrator
Fluent migrations framework for .NET
Stars: ✭ 2,636 (+20176.92%)
Mutual labels:  postgres, migration
Postgres Migrations
🐦 A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations
Stars: ✭ 161 (+1138.46%)
Mutual labels:  postgres, migrations
migrations
Migrations is a database migration tool that uses go's database/sql from the standard library
Stars: ✭ 17 (+30.77%)
Mutual labels:  migrations, migration
East
node.js database migration tool
Stars: ✭ 53 (+307.69%)
Mutual labels:  postgres, migration
Typescript Seed
Typescript Seed Project (Angular, Hapi, Cookie Auth, TypeORM, Postgres)
Stars: ✭ 12 (-7.69%)
Mutual labels:  postgres, seed
shyft
⬡ Shyft is a server-side framework for building powerful GraphQL APIs 🚀
Stars: ✭ 56 (+330.77%)
Mutual labels:  postgres, migrations
pg-migrate
PostgreSQL migration tool
Stars: ✭ 39 (+200%)
Mutual labels:  migrations, migration
pg global temp tables
Oracle-style global temporary tables for PostgreSQL
Stars: ✭ 16 (+23.08%)
Mutual labels:  postgres, migration
butterfly
Application transformation tool
Stars: ✭ 35 (+169.23%)
Mutual labels:  migrations, migration
node-starter-kit
Node.js / GraphQL project template pre-configured with TypeScript, PostgreSQL, login flow, transactional emails, unit tests, CI/CD workflow.
Stars: ✭ 76 (+484.62%)
Mutual labels:  postgres, seed
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (+3846.15%)
Mutual labels:  postgres, migrations
upscheme
Database migrations and schema updates made easy
Stars: ✭ 737 (+5569.23%)
Mutual labels:  migrations, migration

Plow 👨‍🌾

Postgres migrations & seeding made easy

Plow is a no-non-sense tool to quickly and easily apply database migrations and seed PostgresQL databases.

The migrations are managed using postgres-migrations.

Installation

$ npm install @andywer/plow

Usage - Command line tool

Usage
  $ plow migrate ./migrations/*.sql
  $ plow seed ./seeds/*.sql

General options
  --help                Print this usage help
  --verbose             Enable more detailed logging
  --version             Print the installed plow version

Connection options
  --database <name>     Name of the database
  --host <host>         Database host, defaults to "localhost"
  --port <port>         Port the database listens on, defaults to 5432
  --user <name>         User name to authenticate as
  --password <password> Password to use for authentication

Environment variables
  You can also configure the connection using these environment variables.

  PGDATABASE, PGHOST, PGPASSWORD, PGPORT, PGUSER

Use npx to run a locally installed plow like this:

npx plow migrate ./migrations

Usage - Docker

Use the andywer/plow docker image. You can add it to your docker-compose.yml file like this:

version: "3.7"
services:
  postgres:
    image: postgres:12-alpine
    environment:
      POSTGRES_PASSWORD: $PGPASSWORD
    ports:
      - 5432:5432
  db_seeder:
    image: andywer/plow:0.0.0
    depends_on:
      - postgres
    env_file: ./.env
    environment:
      PGHOST: postgres
    restart: "no"
    volumes:
      - ./migrations:/migrations
      - ./seeds:/seeds

Now every time you run docker-compose up your database will automatically have all migrations and seeds applied! 🚀

Note that we assume you have a local migrations and a seeds directory that we can mount into the container and that you have a .env file next to your docker-compose file:

PGDATABASE=postgres
PGHOST=localhost
PGUSER=postgres
PGPASSWORD=postgres

The output of docker-compose up will look something like this:

$ docker-compose up
twitter-daily_postgres_1 is up-to-date
Creating twitter-daily_db_seeder_1 ... done
Attaching to twitter-daily_postgres_1, twitter-daily_db_seeder_1
...
postgres_1   | 2020-01-05 04:50:04.266 UTC [1] LOG:  database system is ready to accept connections
db_seeder_1  | Database migration done.
db_seeder_1  | Migrations run:
db_seeder_1  |   - create-migrations-table
db_seeder_1  |   - v0.1.0-initial
db_seeder_1  | Database seeded.
db_seeder_1  | Applied seeds:
db_seeder_1  |   (None)
twitter-daily_db_seeder_1 exited with code 0

Migration files

Migration files can either be plain SQL files or JavaScript files. There are only up migrations, no down migrations – this is a design decision. Read more about it here.

A good scheme to name your migration files is:

<serial>-<version>-<description>.sql

So the very first migration file would be called 01-v0.1.0-initial.sql or similar.

Seed files

Seed files are supposed to be plain SQL files.

/* example.seed.sql */

INSERT INTO users
  (name, email, email_confirmed)
VALUES
  ('Alice', '[email protected]', TRUE);

FAQs

Error: Migration failed. Reason: Hashes don't match for migrations

Plow uses postgres-migrations which sets up a migration table and stores a hash for every migration run. You will see this error if you change a migration file (during development, I hope) that you already applied and run plow again.

Only during development: Assuming that you have no valuable data in your local development database, it's easy to just whipe the whole database and restart the containers to re-run the migrations to start off fresh again. If you have a local docker-compose setup with a database container without a mount, then just run docker-compose rm --stop postgres && docker-compose up to re-initialize the whole database.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].