Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple database migration tool for Go

NotificationsYou must be signed in to change notification settings

ClusterVR/migorate

Repository files navigation

Simple database migration tool for Go.

Features

  • Migration management
  • Execute SQL command from *.sql files
  • Generate SQL file with Rails-like commands

Usage

Create .migoraterc

mysql:  host: localhost  port: 3306  user: migorate  password: migorate  database: migorate

Generate migration file

$ migorate generate [migration id] [col:type]...
$ migorate generate create_users id:id name:string login_count:integer last_login_at:datetime created_at:timestamp2016/07/17 22:55:30 Generated: db/migrations/20160717225530_create_users.sql$ cat db/migrations/20160717225530_create_users.sql-- +migrate UpCREATE TABLE users(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), login_count INT, last_login_at DATETIME, created_at TIMESTAMP);-- +migrate DownDROP TABLE users;

Currently, onlyCREATE TABLE migration can be generated with migration idcreate_(tablename).

All other migration id generates empty migration file.

Type conversion

in commandSQL
idINT PRIMARY KEY AUTO_INCREMENT
integerINT
datetimeDATETIME
stringVARCHAR(255)
timestampTIMESTAMP
referencesINTAdds foreign key toid in(column_name)s table

Plan migration

$ migorate plan all2016/07/17 21:16:53 Planned migrations:2016/07/17 21:16:53   1: 20160717225530_create_users

Execute migration

$ migorateexec all2016/07/17 21:17:49 Executing 20160717225530_create_users2016/07/17 21:17:49   CREATE TABLE users(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), login_count INT, last_login_at DATETIME, created_at TIMESTAMP);

Rollback

$ migorate rollback [migration id]
$ migorate rollback 20160717225530_create_users2016/07/17 21:21:09 Executing 20160717225530_create_users2016/07/17 21:21:09   DROP TABLE users;

Rollback all

$ migorate rollback all2017/02/26 15:42:30 Executing 20160716102604_create_authors2017/02/26 15:42:30 Executed:ALTER TABLE books  DROP FOREIGN KEY fk_books_author_id;2017/02/26 15:42:30 Executed:DROP TABLE authors;2017/02/26 15:42:30 Executed:ALTER TABLE books  ADD (author VARCHAR(255));2017/02/26 15:42:30 Executing 20160714092604_create_books2017/02/26 15:42:30 Executed:DROP TABLE books;2017/02/26 15:42:30 Executing 20160714092556_create_users2017/02/26 15:42:30 Executed:DROP TABLE users;

About

Simple database migration tool for Go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp