Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scotttesler/migurt
ðĶA database migration and seeding tool.
https://github.com/scotttesler/migurt
database database-management database-migrations databases migration migration-tool migrations migrationtool postgres postgres-database postgresql postgresql-database relational-databases sql
Last synced: about 1 month ago
JSON representation
ðĶA database migration and seeding tool.
- Host: GitHub
- URL: https://github.com/scotttesler/migurt
- Owner: scotttesler
- License: mit
- Created: 2018-05-19T21:03:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T09:54:18.000Z (7 months ago)
- Last Synced: 2024-11-27T10:35:55.717Z (about 1 month ago)
- Topics: database, database-management, database-migrations, databases, migration, migration-tool, migrations, migrationtool, postgres, postgres-database, postgresql, postgresql-database, relational-databases, sql
- Language: JavaScript
- Homepage:
- Size: 166 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# migurt ðĶ
_A database migration tool_
[![Build Status](https://travis-ci.org/scotttesler/migurt.svg?branch=master)](https://travis-ci.org/scotttesler/migurt "Build status")
[![JavaScript Style Guide: Prettier](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier "Prettier")Migurt lets you write database migrations and seeds in your database's language.
(Currently, only works with [PostgreSQL](https://www.postgresql.org/))
## Installation
`npm i -g migurt`
## Usage
### `migurt help [COMMAND]`
Displays help.
`[COMMAND]` - _Optional_. The name of a command.
---
### `migurt create-migration --name `
Create new migration and matching reversion files.
`` - **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
```sql
-- ./db/migrations/up/1525396716884_create_table_companies.sqlCREATE 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);
``````sql
-- ./db/migrations/down/1525396716884_create_table_companies.sqlDROP TABLE public.companies;
```---
### `migurt create-seed --name `
Create new seed and matching reversion files.
`` - **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
```sql
-- ./db/seeds/up/1526829902471_create_companies.sqlINSERT INTO public.companies (name) VALUES ('E Corp');
``````sql
-- ./db/seeds/down/1526829902471_create_companies.sqlDELETE FROM public.companies WHERE name = 'E Corp';
```---
### `migurt migrate --number `
Run migrations.
`` - **Required**. The number of migrations to run. Enter a number to
run that many migrations from the last ran migration.---
### `migurt seed --number `
Run seeds.
`` - **Required**. The number of seeds to run. Enter a number to run
that many seeds from the last ran seed.---
### `migurt revert-migrations --number `
Revert migrations.
`` - **Required**. The number of migrations to revert. Enter a number to
revert that many migrations from the latest.---
### `migurt revert-seeds --number `
Revert seeds.
`` - **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.
```javascript
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.