fix: add migrations to docker
This commit is contained in:
parent
9ef1833073
commit
18842091a4
2 changed files with 28 additions and 15 deletions
|
|
@ -152,22 +152,32 @@ func GetMigrationVersion(db *sql.DB) (uint, bool, error) {
|
|||
}
|
||||
|
||||
func getMigrationsPath() (string, error) {
|
||||
// Get the directory of the current source file
|
||||
_, filename, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("failed to get current file path")
|
||||
if envPath := os.Getenv("MIGRATIONS_PATH"); envPath != "" {
|
||||
if _, err := os.Stat(envPath); err == nil {
|
||||
return envPath, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Get the internal directory (go up from internal/pkg/infrastructure/ to internal/)
|
||||
// Current path: .../internal/pkg/infrastructure/db.go
|
||||
// Need to go up: infrastructure -> pkg -> internal
|
||||
paths := []string{
|
||||
"./internal/migrations",
|
||||
"../internal/migrations",
|
||||
"../../internal/migrations",
|
||||
}
|
||||
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
|
||||
_, filename, _, ok := runtime.Caller(0)
|
||||
if ok {
|
||||
internalDir := filepath.Dir(filepath.Dir(filepath.Dir(filename)))
|
||||
migrationsPath := filepath.Join(internalDir, "migrations")
|
||||
|
||||
// Verify the migrations directory exists
|
||||
if _, err := os.Stat(migrationsPath); err != nil {
|
||||
return "", fmt.Errorf("migrations directory not found at %s: %w", migrationsPath, err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(migrationsPath); err == nil {
|
||||
return migrationsPath, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("migrations directory not found")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ WORKDIR /app
|
|||
# Copy the binary from builder
|
||||
COPY --from=builder /build/services/api/api .
|
||||
|
||||
# Copy migrations
|
||||
COPY --from=builder /build/internal/migrations ./internal/migrations
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the API
|
||||
|
|
|
|||
Loading…
Reference in a new issue