gomigrate

Golang 中的 SQL 数据库迁移工具包。「A SQL database migration toolkit in Golang」

  • 所有者: DavidHuie/gomigrate
  • 平台: Linux, Mac, Windows
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

gomigrate

Build Status

A SQL database migration toolkit in Golang.

Supported databases

  • PostgreSQL
  • MariaDB
  • MySQL
  • Sqlite3

Usage

First import the package:

import "github.com/DavidHuie/gomigrate"

Given a database/sql database connection to a PostgreSQL database, db,
and a directory to migration files, create a migrator:

migrator, _ := gomigrate.NewMigrator(db, gomigrate.Postgres{}, "./migrations")

You may also specify a specific logger to use, such as logrus:

migrator, _ := gomigrate.NewMigratorWithLogger(db, gomigrate.Postgres{}, "./migrations", logrus.New())

To migrate the database, run:

err := migrator.Migrate()

To rollback the last migration, run:

err := migrator.Rollback()

Migration files

Migration files need to follow a standard format and must be present
in the same directory. Given "up" and "down" steps for a migration,
create a file for each by following this template:

{{ id }}_{{ name }}_{{ "up" or "down" }}.sql

For a given migration, the id and name fields must be the same.
The id field is an integer that corresponds to the order in which
the migration should run relative to the other migrations.

id should not be 0 as that value is used for internal validations.

Example

If I'm trying to add a "users" table to the database, I would create
the following two files:

1_add_users_table_up.sql

CREATE TABLE users();

1_add_users_table_down.sql

DROP TABLE users;

Copyright (c) 2014 David Huie. See LICENSE.txt for further details.

主要指標

概覽
名稱與所有者DavidHuie/gomigrate
主編程語言Go
編程語言Go (語言數: 3)
平台Linux, Mac, Windows
許可證MIT License
所有者活动
創建於2014-07-12 23:25:00
推送於2019-08-26 18:27:20
最后一次提交2019-08-26 11:27:18
發布數0
用户参与
星數161
關注者數6
派生數27
提交數78
已啟用問題?
問題數14
打開的問題數8
拉請求數10
打開的拉請求數1
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?