Files
homebox/backend/internal/data/migrations/postgres/20250112202302_sync_children.go
Matt Kilgore 1ac86d9c04 Real Migrations System (#645)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-05-01 15:03:08 -04:00

39 lines
938 B
Go

package postgres
import (
"context"
"database/sql"
"fmt"
"github.com/pressly/goose/v3"
)
//nolint:gochecknoinits
func init() {
goose.AddMigrationContext(Up20250112202302, Down20250112202302)
}
func Up20250112202302(ctx context.Context, tx *sql.Tx) error {
columnName := "sync_child_items_locations"
query := `
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'items' AND column_name = 'sync_child_items_locations';
`
err := tx.QueryRowContext(ctx, query).Scan(&columnName)
if err != nil {
// Column does not exist, proceed with migration
_, err = tx.ExecContext(ctx, `
ALTER TABLE "items" ADD COLUMN "sync_child_items_locations" boolean NOT NULL DEFAULT false;
`)
if err != nil {
return fmt.Errorf("failed to execute migration: %w", err)
}
}
return nil
}
func Down20250112202302(ctx context.Context, tx *sql.Tx) error {
// This migration is a no-op for Postgres.
return nil
}