fix: skip already applied migrations
This commit is contained in:
@@ -25,7 +25,20 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer pool.Close()
|
defer pool.Close()
|
||||||
for _, path := range []string{"migrations/000001_mvp.sql", "migrations/000002_growth_analyst.sql", "migrations/000003_ai_summary_refresh.sql", "migrations/000004_ai_page_insights.sql"} {
|
migrations := []struct {
|
||||||
|
version int64
|
||||||
|
path string
|
||||||
|
}{{1, "migrations/000001_mvp.sql"}, {2, "migrations/000002_growth_analyst.sql"}, {3, "migrations/000003_ai_summary_refresh.sql"}, {4, "migrations/000004_ai_page_insights.sql"}}
|
||||||
|
for _, item := range migrations {
|
||||||
|
var applied bool
|
||||||
|
if err := pool.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM schema_migrations WHERE version=$1)`, item.version).Scan(&applied); err != nil {
|
||||||
|
logger.Error("checking migration version failed", "version", item.version, "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if applied {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
path := item.path
|
||||||
migration, err := os.ReadFile(path)
|
migration, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("reading migration failed", "path", path, "error", err)
|
logger.Error("reading migration failed", "path", path, "error", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user