diff --git a/Makefile b/Makefile index e859c9f..d686ca7 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +include .env all: clean buildserver run: @@ -12,5 +13,11 @@ test: dockerbuild: docker build -t authserver-app:latest . +migrateup: + migrate -source file://db/migrations -database 'postgres://$(PG_USER):$(PG_PASSWORD)@$(PG_HOST):$(PG_PORT)/$(PG_DB)?sslmode=disable' up + +migratedown: + migrate -source file://db/migrations -database 'postgres://$(PG_USER):$(PG_PASSWORD)@$(PG_HOST):$(PG_PORT)/$(PG_DB)?sslmode=disable' down + clean: rm -rf auth_server diff --git a/database/1_0_schema_version_table.sql b/database/1_0_schema_version_table.sql deleted file mode 100644 index f2e9784..0000000 --- a/database/1_0_schema_version_table.sql +++ /dev/null @@ -1,9 +0,0 @@ --- Add schema changes table -CREATE TABLE schema_updates( - id SERIAL NOT NULL PRIMARY KEY, - major_version INT NOT NULL, - minor_version INT NOT NULL, - created_at TIMESTAMP NOT NULL -); - -INSERT INTO schema_changes(major_version, minor_version) VALUES (1, 0, NOW()); \ No newline at end of file diff --git a/db/migrations/000001_initial_schema.down.sql b/db/migrations/000001_initial_schema.down.sql new file mode 100644 index 0000000..f7948a0 --- /dev/null +++ b/db/migrations/000001_initial_schema.down.sql @@ -0,0 +1,8 @@ +BEGIN; +DROP TABLE IF EXISTS user_refresh_tokens; +DROP TABLE IF EXISTS reset_password_requests; +DROP TABLE IF EXISTS two_factor_requests; +DROP TABLE IF EXISTS user_roles; +DROP TABLE IF EXISTS roles; +DROP TABLE IF EXISTS users; +COMMIT; \ No newline at end of file diff --git a/database/initial.sql b/db/migrations/000001_initial_schema.up.sql similarity index 100% rename from database/initial.sql rename to db/migrations/000001_initial_schema.up.sql