From 665845a7e5050a57e6dee05a3055e2a973e1e108 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Tue, 13 Jun 2017 21:45:15 -0400 Subject: Migrations --- Makefile | 11 +++++++++++ README.md | 7 +++++++ migrations/20170613212553_op-constraint.sql | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 README.md create mode 100644 migrations/20170613212553_op-constraint.sql diff --git a/Makefile b/Makefile index 0fa6116..759e09f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +DB=sslmode=disable dbname=lastfm + all: kill build start build: @@ -12,3 +14,12 @@ start: watch: watchman-make -p '*.go' 'templates/*.tmpl' -t all + +up: + goose -dir migrations postgres "$(DB)" up + +down: + goose -dir migrations postgres "$(DB)" down + +status: + goose -dir migrations postgres "$(DB)" status diff --git a/README.md b/README.md new file mode 100644 index 0000000..1020fda --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +## Database migrations + +We use `goose` for migrations. First install with: + + go get -u github.com/pressly/goose/cmd/goose + +Whenever a commit changed the database, apply the migrations with `make up`. diff --git a/migrations/20170613212553_op-constraint.sql b/migrations/20170613212553_op-constraint.sql new file mode 100644 index 0000000..1ef1ec1 --- /dev/null +++ b/migrations/20170613212553_op-constraint.sql @@ -0,0 +1,8 @@ + +-- +goose Up +-- SQL in section 'Up' is executed when this migration is applied +ALTER TABLE users ADD CONSTRAINT op UNIQUE (type, op_id); + +-- +goose Down +-- SQL section 'Down' is executed when this migration is rolled back +ALTER TABLE users DROP CONSTRAINT op; -- cgit v1.2.3-70-g09d2