a simple go library to do database migration
Go to file
2021-07-10 14:36:26 -07:00
dialect.go introduced the concept of a dialect, to provide the exact SQL needed. 2021-07-10 13:09:26 -07:00
doc.go introduced the concept of a dialect, to provide the exact SQL needed. 2021-07-10 13:09:26 -07:00
go.mod temporary holding ground for migrate 2021-06-04 17:57:45 -07:00
go.sum temporary holding ground for migrate 2021-06-04 17:57:45 -07:00
migrate_test.go introduced the concept of a dialect, to provide the exact SQL needed. 2021-07-10 13:09:26 -07:00
migrate.go introduced the concept of a dialect, to provide the exact SQL needed. 2021-07-10 13:09:26 -07:00
README.md added readme 2021-07-10 14:36:26 -07:00

migrate

migrate is a package for SQL datbase migrations in the spirit of dbstore(rsc.io/dbstore) it is intended to keep its footprint small, requiring only an additional table in the database there is no rollback support as you should only ever roll forward. Sqlite3 support is provided, support for other datbases can be added by implementing the Dialect interface

Installation

go get github.com/jchenry/migrate

Usage

...
records :=
		[]Record{
			{
				Description: "create people table",
				F: func(ctx Context) (err error) {
					_, err = ctx.Exec(`
				CREATE TABLE people (
					given_name VARCHAR(20),
					surname VARCHAR(30),
					gender CHAR(1),
					age SMALLINT);
				`)
					return
				},
			},
			{
				Description: "Insert a person into people",
				F: func(ctx Context) (err error) {
					_, err = ctx.Exec(`INSERT INTO people VALUES('Henry','Colin','M', 42)`)
					return
				},
			},
		}

	err = migrate.Apply(db, migtate.Sqlite3(), records)
    ...

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

courtesey of https://www.makeareadme.com