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) {
|
func getMigrationsPath() (string, error) {
|
||||||
// Get the directory of the current source file
|
if envPath := os.Getenv("MIGRATIONS_PATH"); envPath != "" {
|
||||||
_, filename, _, ok := runtime.Caller(0)
|
if _, err := os.Stat(envPath); err == nil {
|
||||||
if !ok {
|
return envPath, nil
|
||||||
return "", fmt.Errorf("failed to get current file path")
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the internal directory (go up from internal/pkg/infrastructure/ to internal/)
|
paths := []string{
|
||||||
// Current path: .../internal/pkg/infrastructure/db.go
|
"./internal/migrations",
|
||||||
// Need to go up: infrastructure -> pkg -> internal
|
"../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)))
|
internalDir := filepath.Dir(filepath.Dir(filepath.Dir(filename)))
|
||||||
migrationsPath := filepath.Join(internalDir, "migrations")
|
migrationsPath := filepath.Join(internalDir, "migrations")
|
||||||
|
if _, err := os.Stat(migrationsPath); err == nil {
|
||||||
// Verify the migrations directory exists
|
return migrationsPath, nil
|
||||||
if _, err := os.Stat(migrationsPath); err != nil {
|
}
|
||||||
return "", fmt.Errorf("migrations directory not found at %s: %w", migrationsPath, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return migrationsPath, nil
|
return "", fmt.Errorf("migrations directory not found")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ WORKDIR /app
|
||||||
# Copy the binary from builder
|
# Copy the binary from builder
|
||||||
COPY --from=builder /build/services/api/api .
|
COPY --from=builder /build/services/api/api .
|
||||||
|
|
||||||
|
# Copy migrations
|
||||||
|
COPY --from=builder /build/internal/migrations ./internal/migrations
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Run the API
|
# Run the API
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue