a simple go library to do database migration
Go to file
Colin Henry 46e6c1272d
Update README.md
2022-04-13 08:16:46 -07:00
LICENSE added license 2021-07-10 16:21:56 -07:00
README.md Update README.md 2022-04-13 08:16:46 -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 retract previous versions 2021-07-10 16:18:59 -07:00
go.sum temporary holding ground for migrate 2021-06-04 17:57:45 -07:00
migrate.go introduced the concept of a dialect, to provide the exact SQL needed. 2021-07-10 13:09:26 -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

README.md

migrate

migrate is a package for SQL datbase migrations in the spirit of 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, migrate.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