fix: fix migration via args failed

This commit is contained in:
Sosokker 2025-02-12 18:02:45 +07:00
parent 856823d87d
commit b9419287e7
4 changed files with 15 additions and 4 deletions

View File

@ -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)
}

10
backend/makefile Normal file
View File

@ -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

View File

@ -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);
CREATE UNIQUE INDEX idx_users_username ON users(username);

View File

@ -4,5 +4,5 @@ import (
"embed"
)
//go:embed migrations/*.sql
//go:embed *.sql
var EmbedMigrations embed.FS