Giter Site home page Giter Site logo

migrate's Introduction

migrate

Migrate is a database migration tool for PostgreSQL and SQLite.

Installation

To get the most up to date instal, you can install via the Homewbrew tap tombell/formulae.

brew tap tombell/formulae
brew install tombell/formulae/migrate

To install the latest from source, you can use go install.

go install github.com/tombell/migrate/cmd/migrate@latest

Usage

To begin you'll need to create your migrations in a directory. The files will need a prefix that is a time stamp, so that the migrations can be ordered.

Migrations

The format is YYYYMMDDHHmmss_{migration name}.sql. The rest of the name can be anything you like.

The contents of the migration should have an up and down section, denoted by specific comments.

Example:

-- migrate:up

CREATE TABLE "tracks" (
  "id"      UUID          PRIMARY KEY,
  "artist"  VARCHAR (256) NOT NULL,
  "name"    VARCHAR (256) NOT NULL,
  "genre"   VARCHAR (128) NOT NULL,
  "bpm"     DECIMAL       NOT NULL,
  "key"     VARCHAR (8)   NOT NULL,
  "created" TIMESTAMP     NOT NULL,
  "updated" TIMESTAMP     NOT NULL
);

-- migrate:down

DROP TABLE IF EXISTS "tracks";

Once you've created your migrations, you're ready to run the migrate command.

Applying migrations

The apply sub command runs through the migrations in the specified directory, and applies any migrations not already applied.

You will need to specify the --db, --dsn, and --migrations options. The --db option can be omitted if you're using PostgreSQL, as this is the default value.

migrate apply --dsn "my_local_db" --migrations ./migrations

Rolling back migrations

The rollback sub command, will roll back the last applied migration(s). The --steps option is used to specify the number of migrations to roll back, the default is 1. You will also need the --db, --dsn, and --migrations options.

migrate rollback --dsn "my_local_db" --migrations ./migrations

migrate's People

Contributors

tombell avatar

Watchers

 avatar  avatar

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.