All Projects → jimenezmaximiliano → migrations

jimenezmaximiliano / migrations

Licence: ISC license
Migrations is a database migration tool that uses go's database/sql from the standard library

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to migrations

upscheme
Database migrations and schema updates made easy
Stars: ✭ 737 (+4235.29%)
Mutual labels:  sql-server, migrations, migration, database-migrations
r2dbc-migrate
R2DBC database migration tool & library
Stars: ✭ 83 (+388.24%)
Mutual labels:  sql-server, migration, database-migrations
Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+12323.53%)
Mutual labels:  migrations, migration, database-migrations
Dbmate
🚀 A lightweight, framework-agnostic database migration tool.
Stars: ✭ 2,228 (+13005.88%)
Mutual labels:  migrations, migration, database-migrations
Node Sqlite
SQLite client for Node.js applications with SQL-based migrations API written in Typescript
Stars: ✭ 642 (+3676.47%)
Mutual labels:  migrations, migration
Rxjava2 Android Samples
RxJava 2 Android Examples - Migration From RxJava 1 to RxJava 2 - How to use RxJava 2 in Android
Stars: ✭ 4,950 (+29017.65%)
Mutual labels:  migrations, migration
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+45264.71%)
Mutual labels:  migrations, migration
Mongo.migration
On-the-fly migrations with MongoDB C# Driver
Stars: ✭ 99 (+482.35%)
Mutual labels:  migrations, migration
sync-db
Utility to synchronize relational database objects across databases.
Stars: ✭ 15 (-11.76%)
Mutual labels:  migrations, database-migrations
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+4829.41%)
Mutual labels:  migrations, migration
Lol dba
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
Stars: ✭ 1,363 (+7917.65%)
Mutual labels:  migrations, database-migrations
Migrate Mongo
A database migration tool for MongoDB in Node
Stars: ✭ 481 (+2729.41%)
Mutual labels:  migrations, database-migrations
Phinx
PHP Database Migrations for Everyone
Stars: ✭ 4,245 (+24870.59%)
Mutual labels:  migrations, database-migrations
Postgres Migrations
🐦 A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations
Stars: ✭ 161 (+847.06%)
Mutual labels:  migrations, database-migrations
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+13517.65%)
Mutual labels:  migrations, migration
Phoenix
Framework agnostic database migrations for PHP.
Stars: ✭ 81 (+376.47%)
Mutual labels:  migrations, database-migrations
mongo-migrate
Versioned migrations for MongoDB.
Stars: ✭ 79 (+364.71%)
Mutual labels:  migrations, database-migrations
plow
👨‍🌾 Postgres migrations and seeding made easy
Stars: ✭ 13 (-23.53%)
Mutual labels:  migrations, migration
Obevo
Obevo is a database deployment tool that handles enterprise scale schemas and complexity
Stars: ✭ 192 (+1029.41%)
Mutual labels:  sql-server, database-migrations
Dbatools
🚀 SQL Server automation and instance migrations have never been safer, faster or freer
Stars: ✭ 1,742 (+10147.06%)
Mutual labels:  sql-server, migrations

Migrations

migrate

Migrations is a minimalistic database migration tool that uses go's database/sql from the standard library.

Features

  • supports any database driver that is compatible with database/sql, including: MySQL, Microsoft SQL Server, PostgreSQL, Oracle and SQLite.
  • migrations are simple SQL files
  • migrations can contain multiple queries
  • easy generation of migration files
  • we keep track of run migrations
  • minimal dependencies
  • customizable
  • support for environment variables

Usage

Examples

Create a migration file

./migrations create -name=createGophersTable -path=/app/migrations/

or use environment variables:

MIGRATIONS_COMMAND="create" MIGRATIONS_PATH="/app/migrations/" MIGRATIONS_NEW_MIGRATION_NAME="createGophersTable" ./migrations

Run migrations

./migrations migrate -path=/app/migrations/

or use environment variables:

MIGRATIONS_COMMAND="migrate" MIGRATIONS_PATH="/app/migrations/" ./migrations

create command

The create command creates a file with a prefix using the current timestamp. That's going to be used to determine the order on which migrations should be run.

For example, running:

./migrations create -name=createGophersTable -path=/app/migrations/
./migrations create -name=createGolfersTable -path=/app/migrations/

Will result in:

/app/migrations/1627676712447528000_createGophersTable.sql
/app/migrations/1627676757857350000_createGolfersTable.sql

migrate command

The migrate command runs migrations and then displays a report with the result of each migration run, if any.

./migrations migrate -path=/app/migrations/

Example output:

[ INFO ] Run migrations
[  OK  ] 1627676712447528000_createGophersTable.sql
[  OK  ] 1627676757857350000_createGolfersTable.sql
[ INFO ] Done

Setup

  1. Get the module
go get github.com/jimenezmaximiliano/migrations
  1. Create a go file using the next template:
package main

import (
	"database/sql"

	// This example uses mysql but you can pick any other driver compatible with database/sql
	_ "github.com/go-sql-driver/mysql"

	"github.com/jimenezmaximiliano/migrations"
)

func main() {
	migrations.RunMigrationsCommand(func() (*sql.DB, error) {
		// Here you can set up your db connection
		return sql.Open("mysql", "user:password@/db?multiStatements=true")
	})
}
  1. Then use the binary like this:
./migrations migrate -path=/app/migrations

or

go run migrations.go migrate -path=/app/migrations

See the example directory in this repository for a working example

Migration files

All migration files must:

  • be in the provided path (not inside subdirectories)
  • end in .sql (files without the .sql extension will be ignored)
  • be in this format: {number}_{string}.sql where number determines the order on which migrations will be run
  • be ordered by filename in the order they should run (you can use the create command for that)

Example:

/app/migrations
/app/migrations/1627676712447528000_createGophersTable.sql
/app/migrations/1627676757857350000_createGolfersTable.sql

See example migrations in the example directory

Customization

You can use the migrations facade as a tutorial on how to replace any component of the package by implementing one of its interfaces.

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].