aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--README.md7
-rw-r--r--migrations/20170613212553_op-constraint.sql8
3 files changed, 26 insertions, 0 deletions
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;