Skip to content

Commit

Permalink
Incremental removal of FatalIfError()
Browse files Browse the repository at this point in the history
  • Loading branch information
williammoran committed May 6, 2024
1 parent fde2173 commit e10a939
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions lib/format/pgsql8/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e10a939

Please sign in to comment.