diff --git a/backend/internal/cmd/migrate.go b/backend/internal/cmd/migrate.go index b902432..b352f52 100644 --- a/backend/internal/cmd/migrate.go +++ b/backend/internal/cmd/migrate.go @@ -11,7 +11,7 @@ import ( "github.com/pressly/goose/v3" "github.com/spf13/cobra" - migrations "github.com/forfarm/backend/internal" + "github.com/forfarm/backend/migrations" ) func MigrateCmd(ctx context.Context, dbDriver, dbSource string) *cobra.Command { @@ -29,7 +29,7 @@ func MigrateCmd(ctx context.Context, dbDriver, dbSource string) *cobra.Command { goose.SetBaseFS(migrations.EmbedMigrations) - if err := goose.UpContext(ctx, db, "migrations"); err != nil { + if err := goose.UpContext(ctx, db, "."); err != nil { return fmt.Errorf("failed to run migrations: %w", err) } diff --git a/backend/makefile b/backend/makefile new file mode 100644 index 0000000..49fbb06 --- /dev/null +++ b/backend/makefile @@ -0,0 +1,10 @@ +.PHONY: live run migrate + +live: + air -c .air.toml + +run: + go run cmd/forfarm/main.go API + +migrate: + go run cmd/forfarm/main.go migrate \ No newline at end of file diff --git a/backend/internal/migrations/00001_create_users.sql b/backend/migrations/00001_create_user_table.sql similarity index 83% rename from backend/internal/migrations/00001_create_users.sql rename to backend/migrations/00001_create_user_table.sql index 7bc50be..8b0b6d7 100644 --- a/backend/internal/migrations/00001_create_users.sql +++ b/backend/migrations/00001_create_user_table.sql @@ -1,3 +1,4 @@ +-- +goose Up CREATE TABLE users ( id SERIAL PRIMARY KEY, uuid UUID NOT NULL, @@ -10,4 +11,4 @@ CREATE TABLE users ( ); CREATE UNIQUE INDEX idx_users_uuid ON users(uuid); -CREATE UNIQUE INDEX idx_users_username ON users(username); \ No newline at end of file +CREATE UNIQUE INDEX idx_users_username ON users(username); diff --git a/backend/internal/embed.go b/backend/migrations/embed.go similarity index 71% rename from backend/internal/embed.go rename to backend/migrations/embed.go index 0df75f5..3e96d80 100644 --- a/backend/internal/embed.go +++ b/backend/migrations/embed.go @@ -4,5 +4,5 @@ import ( "embed" ) -//go:embed migrations/*.sql +//go:embed *.sql var EmbedMigrations embed.FS