@@ -677,5 +677,92 @@ CREATE INDEX IF NOT EXISTS idx_cp_bootstrap_workloads_state ON cp_bootstrap_work
677677 return err
678678 },
679679 },
680+ // cp_health_checks was created without a service_name column even
681+ // though healthCheckModel/health.HealthCheck both carry the field
682+ // (it targets a specific service inside a multi-service instance).
683+ // Inserting the full model failed with "column service_name does
684+ // not exist", so the store worked around it with a column whitelist
685+ // that silently dropped ServiceName. Add the column so it round-trips;
686+ // NULL is impossible because legacy rows default to ''.
687+ & migrate.Migration {
688+ Name : "add_service_name_to_cp_health_checks" ,
689+ Version : "20240101000022" ,
690+ Up : func (ctx context.Context , exec migrate.Executor ) error {
691+ _ , err := exec .Exec (ctx , `ALTER TABLE cp_health_checks ADD COLUMN IF NOT EXISTS service_name TEXT NOT NULL DEFAULT ''` )
692+
693+ return err
694+ },
695+ Down : func (ctx context.Context , exec migrate.Executor ) error {
696+ _ , err := exec .Exec (ctx , `ALTER TABLE cp_health_checks DROP COLUMN IF EXISTS service_name` )
697+
698+ return err
699+ },
700+ },
701+ // The multi-service refactor changed the deployment/release/template/
702+ // instance models to JSONB `services` (and friends) but the migrations
703+ // only dropped the legacy single-image columns — the replacement columns
704+ // were never added, so InsertDeployment/InsertRelease/InsertTemplate and
705+ // the instance writes failed with "column ... does not exist" (42703) on
706+ // a freshly-migrated DB. Add every column the current models expect.
707+ // All ADD COLUMN IF NOT EXISTS, so this is a safe no-op where a column
708+ // was already present.
709+ & migrate.Migration {
710+ Name : "reconcile_multi_service_columns" ,
711+ Version : "20240101000023" ,
712+ Up : func (ctx context.Context , exec migrate.Executor ) error {
713+ stmts := []string {
714+ `ALTER TABLE cp_deployments ADD COLUMN IF NOT EXISTS services JSONB` ,
715+ `ALTER TABLE cp_deployments ADD COLUMN IF NOT EXISTS service_progress JSONB` ,
716+ `ALTER TABLE cp_releases ADD COLUMN IF NOT EXISTS services JSONB` ,
717+ `ALTER TABLE cp_releases ADD COLUMN IF NOT EXISTS config JSONB` ,
718+ `ALTER TABLE cp_releases ADD COLUMN IF NOT EXISTS metadata JSONB` ,
719+ `ALTER TABLE cp_templates ADD COLUMN IF NOT EXISTS default_kind TEXT` ,
720+ `ALTER TABLE cp_templates ADD COLUMN IF NOT EXISTS default_strategy TEXT` ,
721+ `ALTER TABLE cp_templates ADD COLUMN IF NOT EXISTS services JSONB` ,
722+ `ALTER TABLE cp_templates ADD COLUMN IF NOT EXISTS labels JSONB` ,
723+ `ALTER TABLE cp_templates ADD COLUMN IF NOT EXISTS variables JSONB` ,
724+ `ALTER TABLE cp_templates ADD COLUMN IF NOT EXISTS source JSONB` ,
725+ `ALTER TABLE cp_instances ADD COLUMN IF NOT EXISTS kind TEXT` ,
726+ `ALTER TABLE cp_instances ADD COLUMN IF NOT EXISTS services JSONB` ,
727+ `ALTER TABLE cp_instances ADD COLUMN IF NOT EXISTS service_refs JSONB` ,
728+ `ALTER TABLE cp_instances ADD COLUMN IF NOT EXISTS labels JSONB` ,
729+ `ALTER TABLE cp_instances ADD COLUMN IF NOT EXISTS source JSONB` ,
730+ }
731+ for _ , stmt := range stmts {
732+ if _ , err := exec .Exec (ctx , stmt ); err != nil {
733+ return err
734+ }
735+ }
736+
737+ return nil
738+ },
739+ Down : func (ctx context.Context , exec migrate.Executor ) error {
740+ stmts := []string {
741+ `ALTER TABLE cp_deployments DROP COLUMN IF EXISTS services` ,
742+ `ALTER TABLE cp_deployments DROP COLUMN IF EXISTS service_progress` ,
743+ `ALTER TABLE cp_releases DROP COLUMN IF EXISTS services` ,
744+ `ALTER TABLE cp_releases DROP COLUMN IF EXISTS config` ,
745+ `ALTER TABLE cp_releases DROP COLUMN IF EXISTS metadata` ,
746+ `ALTER TABLE cp_templates DROP COLUMN IF EXISTS default_kind` ,
747+ `ALTER TABLE cp_templates DROP COLUMN IF EXISTS default_strategy` ,
748+ `ALTER TABLE cp_templates DROP COLUMN IF EXISTS services` ,
749+ `ALTER TABLE cp_templates DROP COLUMN IF EXISTS labels` ,
750+ `ALTER TABLE cp_templates DROP COLUMN IF EXISTS variables` ,
751+ `ALTER TABLE cp_templates DROP COLUMN IF EXISTS source` ,
752+ `ALTER TABLE cp_instances DROP COLUMN IF EXISTS kind` ,
753+ `ALTER TABLE cp_instances DROP COLUMN IF EXISTS services` ,
754+ `ALTER TABLE cp_instances DROP COLUMN IF EXISTS service_refs` ,
755+ `ALTER TABLE cp_instances DROP COLUMN IF EXISTS labels` ,
756+ `ALTER TABLE cp_instances DROP COLUMN IF EXISTS source` ,
757+ }
758+ for _ , stmt := range stmts {
759+ if _ , err := exec .Exec (ctx , stmt ); err != nil {
760+ return err
761+ }
762+ }
763+
764+ return nil
765+ },
766+ },
680767 )
681768}
0 commit comments