fix(lagoon): keep Status plugin-only; migrate:status adds the framework sets itself (WR-12)

57a849d made lagoon.Status read migrationSets, which changed its result
for consumers: the framework sets came first and a plugin with no
migrations lost its row. Status is back to its pre-57a849d behaviour.
migrate:status (table and --json) now reads the unexported setStatus,
which lists the framework sets and the plugins from migrationSets, so it
still agrees with migrate --pretend. Both share historyRows.

- TestStatusPluginRows pins Status: plugin rows only, an empty row for a
  plugin with no migrations or no history table, none without HasMigrations
- TestMigrateStatusJSON also checks the table lists the framework sets
- TestTwoPluginMigrationSetsIsolated and TestDocsMigrate are back to the
  plugin-only rows
This commit is contained in:
Jakub Zych
2026-10-22 04:30:36 +02:00
parent f5e9ee508b
commit 139f5e3942
8 changed files with 116 additions and 67 deletions

View File

@@ -130,20 +130,34 @@ func lastMigrationPlugin(plugins []party.Plugin) string {
return ""
}
// StatusRow is one migration set's recorded IDs: Plugin is the plugin ID or
// the framework set's history ID (for example summercms.attach), Table its
// history table.
// StatusRow is one plugin's recorded migration ids.
type StatusRow struct {
Plugin string
Table string
IDs []string
}
// Status reads the history table of every set Migrate applies, in the
// same order: the framework's own sets first (uploads, backend admin,
// deferred bindings, job queue), then each plugin with at least one
// migration. A missing history table gives a row without IDs.
// Status reads each plugin history table: one row per plugin that
// implements pact.HasMigrations, in plugin order, a plugin with no
// migrations included. The framework's own sets are not listed.
func Status(gdb *gorm.DB, plugins []party.Plugin) ([]StatusRow, error) {
if gdb == nil {
return nil, fmt.Errorf("lagoon: gorm db is nil")
}
var ids []string
for _, p := range plugins {
if _, ok := p.(pact.HasMigrations); ok {
ids = append(ids, p.ID())
}
}
return historyRows(gdb, ids)
}
// setStatus reads the history table of every set Migrate applies, in its
// order (migrationSets): the framework's own sets first, then each plugin
// with at least one migration. migrate:status prints it, so that it agrees
// with migrate --pretend.
func setStatus(gdb *gorm.DB, plugins []party.Plugin) ([]StatusRow, error) {
if gdb == nil {
return nil, fmt.Errorf("lagoon: gorm db is nil")
}
@@ -151,19 +165,30 @@ func Status(gdb *gorm.DB, plugins []party.Plugin) ([]StatusRow, error) {
if err != nil {
return nil, err
}
var rows []StatusRow
ids := make([]string, 0, len(sets))
for _, s := range sets {
table, err := HistoryTableName(s.id)
ids = append(ids, s.id)
}
return historyRows(gdb, ids)
}
// historyRows reads the applied IDs of each history ID's table, sorted. A
// missing history table gives a row without IDs (nil), an empty one a row
// with an empty slice.
func historyRows(gdb *gorm.DB, ids []string) ([]StatusRow, error) {
var rows []StatusRow
for _, id := range ids {
table, err := HistoryTableName(id)
if err != nil {
return nil, err
}
row := StatusRow{Plugin: s.id, Table: table}
row := StatusRow{Plugin: id, Table: table}
if !gdb.Migrator().HasTable(table) {
rows = append(rows, row)
continue
}
if err := gdb.Table(table).Order("id").Pluck("id", &row.IDs).Error; err != nil {
return nil, fmt.Errorf("lagoon: status %s: %w", s.id, err)
return nil, fmt.Errorf("lagoon: status %s: %w", id, err)
}
if row.IDs == nil {
row.IDs = []string{}