diff --git a/Makefile b/Makefile index d21a460..f4403cc 100644 --- a/Makefile +++ b/Makefile @@ -195,7 +195,7 @@ clean-all: clean clean-test ## Example: `postgres-state`. %-state: $(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]')) - @goose -dir $(MIGRATIONS_PATH) $* $($(DB)_CONNECTION) status + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) status .PHONY: %-migration ## Create migrations with specifed name and type (`sql` - default, `go`). @@ -206,7 +206,7 @@ clean-all: clean clean-test ## `postgres-migration name=create_table type=go`. %-migration: $(eval type := $(or $(type), sql)) - @goose -dir $(MIGRATIONS_PATH) $* -s create $(name) $(type) + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) create $(name) $(type) .PHONY: %-migrate ## Apply all available migrations to the database. @@ -216,7 +216,7 @@ clean-all: clean clean-test ## Example: `postgres-migrate`. %-migrate: $(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]')) - @goose -dir $(MIGRATIONS_PATH) $* $($(DB)_CONNECTION) up + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) up .PHONY: %-migrate-to ## Migrate up to a specific version. @@ -226,7 +226,7 @@ clean-all: clean clean-test ## Example: `postgres-migrate-to version=20170506082420`. %-migrate-to: $(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]')) - @goose -dir $(MIGRATIONS_PATH) $* $($(DB)_CONNECTION) up-to $(version) + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) up-to $(version) .PHONY: %-rollback ## Roll back a single migration from the current version. @@ -236,7 +236,7 @@ clean-all: clean clean-test ## Example: `postgres-rollback`. %-rollback: $(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]')) - @goose -dir $(MIGRATIONS_PATH) $* $($(DB)_CONNECTION) down + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) down .PHONY: %-rollback-to ## Roll back migrations to a specific version. @@ -246,7 +246,7 @@ clean-all: clean clean-test ## Example: `postgres-rollback-to version=20170506082527`. %-rollback-to: $(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]')) - @goose -dir $(MIGRATIONS_PATH) $* $($(DB)_CONNECTION) down-to $(version) + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) down-to $(version) .PHONY: %-reset ## Roll back all migrations. @@ -256,4 +256,4 @@ clean-all: clean clean-test ## Example: `postgres-reset`. %-reset: $(eval DB := $(shell echo $* | tr '[:lower:]' '[:upper:]')) - @goose -dir $(MIGRATIONS_PATH) $* $($(DB)_CONNECTION) reset + @GOOSE_DRIVER=$* goose -dir $(MIGRATIONS_PATH) $($(DB)_CONNECTION) reset diff --git a/docker/.env b/docker/.env index 7942038..9913378 100644 --- a/docker/.env +++ b/docker/.env @@ -1,10 +1,10 @@ SERVICE_NAME=novamusic VERSION=v0.4 -ENV=prod +ENV=dev CONFIG_PATH=config/ -CONFIG_NAME=prod +CONFIG_NAME=dev CONFIG_TYPE=yaml POSTGRES_HOST=postgres diff --git a/internal/db/postgres/migrations/20240922194939_create_user_table.sql b/internal/db/postgres/migrations/20240922194939_create_user_table.sql index 0cfafae..ced03cb 100644 --- a/internal/db/postgres/migrations/20240922194939_create_user_table.sql +++ b/internal/db/postgres/migrations/20240922194939_create_user_table.sql @@ -20,4 +20,5 @@ CREATE TABLE IF NOT EXISTS "user" ( -- +goose Down -- +goose StatementBegin DROP TABLE IF EXISTS "user"; +DROP TYPE IF EXISTS role_type; -- +goose StatementEnd diff --git a/internal/db/postgres/migrations/20240929195959_create_album_table.sql b/internal/db/postgres/migrations/20240929195959_create_album_table.sql index 4d68616..af73a34 100644 --- a/internal/db/postgres/migrations/20240929195959_create_album_table.sql +++ b/internal/db/postgres/migrations/20240929195959_create_album_table.sql @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS "album" ( artist_id INT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT current_timestamp, - FOREIGN KEY (artist_id) REFERENCES artist (id) + FOREIGN KEY (artist_id) REFERENCES artist (id) ON DELETE CASCADE ); -- +goose StatementEnd diff --git a/internal/db/postgres/migrations/20240929200011_create_track_table.sql b/internal/db/postgres/migrations/20240929200011_create_track_table.sql index 79858fb..5302a2c 100644 --- a/internal/db/postgres/migrations/20240929200011_create_track_table.sql +++ b/internal/db/postgres/migrations/20240929200011_create_track_table.sql @@ -15,8 +15,8 @@ CREATE TABLE IF NOT EXISTS "track" ( release_date TIMESTAMPTZ DEFAULT NOW(), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT current_timestamp, - FOREIGN KEY (artist_id) REFERENCES artist (id), - FOREIGN KEY (album_id) REFERENCES album (id) + FOREIGN KEY (artist_id) REFERENCES artist (id) ON DELETE CASCADE, + FOREIGN KEY (album_id) REFERENCES album (id) ON DELETE CASCADE ); -- +goose StatementEnd diff --git a/internal/db/postgres/migrations/20240929202312_seed.sql b/internal/db/postgres/migrations/20240929202312_seed.sql index 05be2fc..543e1cd 100644 --- a/internal/db/postgres/migrations/20240929202312_seed.sql +++ b/internal/db/postgres/migrations/20240929202312_seed.sql @@ -29,9 +29,9 @@ VALUES ('Houdini', 'Hip-Hop', 123, 'test filepath', 'tracks/Houdini.jpeg', 5, 5); -- +goose StatementEnd --- +goose Down --- +goose StatementBegin -TRUNCATE TABLE artist; -TRUNCATE TABLE album; -TRUNCATE TABLE track; --- +goose StatementEnd +-- -- +goose Down +-- -- +goose StatementBegin +-- TRUNCATE TABLE artist; +-- TRUNCATE TABLE album; +-- TRUNCATE TABLE track; +-- -- +goose StatementEnd