GithubHelp home page GithubHelp logo

scotttesler / migurt Goto Github PK

View Code? Open in Web Editor NEW
4.0 0.0 1.0 170 KB

๐ŸฆA database migration and seeding tool.

License: MIT License

JavaScript 100.00%
database relational-databases databases database-management database-migrations migration migrations migration-tool migrationtool postgresql

migurt's Introduction

migurt ๐Ÿฆ

A database migration tool

Build Status JavaScript Style Guide: Prettier

Migurt lets you write database migrations and seeds in your database's language.

(Currently, only works with PostgreSQL)

Installation

npm i -g migurt

Usage

migurt help [COMMAND]

Displays help.

[COMMAND] - Optional. The name of a command.


migurt create-migration --name <NAME>

Create new migration and matching reversion files.

<NAME> - Required. The name of the migration file. Prefixed to the name will be a timestamp. Suffixed to the name will be ".sql".

Example

migurt create-migration --name create_table_companies

will create files ./db/migrations/up/1525396716884_create_table_companies.sql and ./db/migrations/down/1525396716884_create_table_companies.sql (creating the directories if they don't exist).

Now, write your migrations in PostgreSQL. For example

-- ./db/migrations/up/1525396716884_create_table_companies.sql

CREATE TABLE public.companies (
  id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
  name TEXT NOT NULL UNIQUE,
  active BOOLEAN NOT NULL DEFAULT TRUE
);

CREATE UNIQUE INDEX companies_id_idx ON public.companies (id);
CREATE UNIQUE INDEX companies_name_idx ON public.companies (name);
CREATE INDEX companies_active_idx ON public.companies (active);
-- ./db/migrations/down/1525396716884_create_table_companies.sql

DROP TABLE public.companies;

migurt create-seed --name <NAME>

Create new seed and matching reversion files.

<NAME> - Required. The name of the seed file. Prefixed to the name will be a timestamp. Suffixed to the name will be ".sql".

Example

migurt create-seed --name create_companies

will create files ./db/seeds/up/1526829902471_create_companies.sql and ./db/seeds/down/1526829902471_create_companies.sql (creating the directories if they don't exist).

Now, write your seeds in PostgreSQL. For example

-- ./db/seeds/up/1526829902471_create_companies.sql

INSERT INTO public.companies (name) VALUES ('E Corp');
-- ./db/seeds/down/1526829902471_create_companies.sql

DELETE FROM public.companies WHERE name = 'E Corp';

migurt migrate --number <NUMBER>

Run migrations.

<NUMBER> - Required. The number of migrations to run. Enter a number to run that many migrations from the last ran migration.


migurt seed --number <NUMBER>

Run seeds.

<NUMBER> - Required. The number of seeds to run. Enter a number to run that many seeds from the last ran seed.


migurt revert-migrations --number <NUMBER>

Revert migrations.

<NUMBER> - Required. The number of migrations to revert. Enter a number to revert that many migrations from the latest.


migurt revert-seeds --number <NUMBER>

Revert seeds.

<NUMBER> - Required. The number of seeds to revert. Enter a number to revert that many seeds from the latest.


Configuration

migurt parses environment variables from a .env file when process.env.NODE_ENV != 'production'.

Below are the environment variables and their defaults.

NOTE: DATABASE_URL is required.

DATABASE_URL=
DIRECTORY_DOWN_MIGRATIONS="./db/migrations/down"
DIRECTORY_DOWN_SEEDS="./db/seeds/down"
DIRECTORY_UP_MIGRATIONS="./db/migrations/up"
DIRECTORY_UP_SEEDS="./db/seeds/up"
TABLE_NAME_MIGRATIONS="public.migrations"
TABLE_NAME_SEEDS="public.seeds"

TODO

  • Add MySQL support.

migurt's People

Contributors

scotttesler avatar

Stargazers

 avatar  avatar  avatar  avatar

Forkers

abdallahz3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.