diff --git a/lib/format/pgsql8/diff.go b/lib/format/pgsql8/diff.go index 381ea20..87e561b 100644 --- a/lib/format/pgsql8/diff.go +++ b/lib/format/pgsql8/diff.go @@ -196,7 +196,9 @@ func (d *diff) updateStructure(stage1 output.OutputFileSegmenter, stage3 output. return err } err = diffSequences(d.Logger(), stage1, oldSchema, newSchema) - dbsteward.FatalIfError(err, "while diffing sequences") + if err != nil { + return fmt.Errorf("while diffing sequences: %w", err) + } // remove old constraints before table constraints, so the sql statements succeed err = dropConstraints(d.Logger(), stage1, oldSchema, newSchema, sql99.ConstraintTypeConstraint) if err != nil { @@ -208,9 +210,13 @@ func (d *diff) updateStructure(stage1 output.OutputFileSegmenter, stage3 output. } dropTables(stage1, oldSchema, newSchema) err = createTables(d.Logger(), stage1, oldSchema, newSchema) - dbsteward.FatalIfError(err, "while creating tables") + if err != nil { + return fmt.Errorf("while creating tables: %w", err) + } err = diffTables(d.Logger(), stage1, stage3, oldSchema, newSchema) - dbsteward.FatalIfError(err, "while diffing tables") + if err != nil { + return fmt.Errorf("while diffing tables: %w", err) + } err = diffIndexes(stage1, oldSchema, newSchema) if err != nil { return err @@ -284,7 +290,9 @@ func (d *diff) updateStructure(stage1 output.OutputFileSegmenter, stage3 output. // see below for post table creation stuff if !processedSchemas[newSchema.Name] { err := diffSequences(d.Logger(), stage1, oldSchema, newSchema) - lib.GlobalDBSteward.FatalIfError(err, "while diffing sequences") + if err != nil { + return fmt.Errorf("while diffing sequences: %w", err) + } processedSchemas[newSchema.Name] = true } @@ -300,11 +308,17 @@ func (d *diff) updateStructure(stage1 output.OutputFileSegmenter, stage3 output. // GlobalDBX.RenamedTableCheckPointer() will modify these pointers to be the old table var err error oldSchema, oldTable, err = lib.GlobalDBSteward.OldDatabase.NewTableName(oldSchema, oldTable, newSchema, newTable) - lib.GlobalDBSteward.FatalIfError(err, "getting new table name") + if err != nil { + return fmt.Errorf("getting new table name: %w", err) + } err = createTable(d.Logger(), stage1, oldSchema, newSchema, newTable) - lib.GlobalDBSteward.FatalIfError(err, "while creating table %s.%s", newSchema.Name, newTable.Name) + if err != nil { + return fmt.Errorf("while creating table %s.%s: %w", newSchema.Name, newTable.Name, err) + } err = diffTable(d.Logger(), stage1, stage3, oldSchema, oldTable, newSchema, newTable) - lib.GlobalDBSteward.FatalIfError(err, "while diffing table %s.%s", newSchema.Name, newTable.Name) + if err != nil { + return fmt.Errorf("while diffing table %s.%s: %w", newSchema.Name, newTable.Name, err) + } err = diffIndexesTable(stage1, oldSchema, oldTable, newSchema, newTable) if err != nil { return err @@ -363,7 +377,9 @@ func (d *diff) updatePermissions(stage1 output.OutputFileSegmenter, stage3 outpu for _, newTable := range newSchema.Tables { oldTable := oldSchema.TryGetTableNamed(newTable.Name) isRenamed, err := lib.GlobalDBSteward.OldDatabase.IsRenamedTable(slog.Default(), newSchema, newTable) - lib.GlobalDBSteward.FatalIfError(err, "while updating permissions") + if err != nil { + return fmt.Errorf("while updating permissions: %w", err) + } if isRenamed { // skip permission diffing on it, it is the same // TODO(feat) that seems unlikely? we should probably check permissions on renamed table @@ -437,7 +453,9 @@ func (d *diff) updateData(l *slog.Logger, ofs output.OutputFileSegmenter, delete oldTable := oldSchema.TryGetTableNamed(newTable.Name) isRenamed, err := lib.GlobalDBSteward.OldDatabase.IsRenamedTable(slog.Default(), newSchema, newTable) - lib.GlobalDBSteward.FatalIfError(err, "while updating data") + if err != nil { + return fmt.Errorf("while updatign data: %w", err) + } if isRenamed { d.Logger().Info(fmt.Sprintf("%s.%s used to be called %s - will diff data against that definition", newSchema.Name, newTable.Name, newTable.OldTableName)) oldSchema = lib.GlobalDBSteward.OldDatabase.GetOldTableSchema(newSchema, newTable)