Skip to content

Dorky-Robot/sql-migrate-js

Repository files navigation

Logo Simple Postgres Migrations

A minimalistic PostgreSQL migrations tool inspired by the Rails migration process. Easily generate, apply, or revert database migrations using Node.js.

Table of Contents

Features

  • Generate migration files with unique timestamps
  • Easily apply or revert migrations
  • Clean and simple CLI interface

Installation

```bash git clone https://github.com/your-github-username/simple-postgres-migrations.git cd simple-postgres-migrations npm install ```

Usage

Generating Migrations

To generate migration files:

```bash node migrate.js generate ```

This will generate two files: one for applying the migration and another for reverting it.

Applying Migrations

To apply all pending migrations:

```bash node migrate.js up ```

Reverting Migrations

To revert the last applied migration:

```bash node migrate.js down ```

Setup

For first-time setup:

```bash node migrate.js setup ```

Configuration

You must provide a .db.test, .db.development, or .db.production to specify the database config for a given environment in migrate.utils.js with your PostgreSQL connection details:

```javascript export const DB_CONFIG = { host: 'localhost', port: 5432, user: 'your-username', password: 'your-password', database: 'your-database-name' }; ```

Ensure the MIGRATIONS_DIR in migrate.utils.js points to your desired migrations directory:

```javascript export const MIGRATIONS_DIR = path.join(__dirname, 'migrations'); ```

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

`SQL-migrate-js` is a tiny library for managing migrations with minimal dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors