Skip to content

Commit

Permalink
Remove GlobalTrigger, refactor it into standalone functions, and some…
Browse files Browse the repository at this point in the history
… general cleanup of that code
  • Loading branch information
williammoran committed Apr 25, 2024
1 parent 68b59c5 commit fa9d0ea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/format/pgsql8/diff_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (self *DiffTriggers) DiffTriggersTable(ofs output.OutputFileSegmenter, oldS
}
newTrigger := newSchema.TryGetTriggerMatching(oldTrigger)
if newTrigger == nil || !oldTrigger.Equals(newTrigger) {
ofs.WriteSql(GlobalTrigger.GetDropSql(oldSchema, oldTrigger)...)
ofs.WriteSql(getDropTriggerSql(oldSchema, oldTrigger)...)
}
}
}
Expand All @@ -47,7 +47,7 @@ func (self *DiffTriggers) DiffTriggersTable(ofs output.OutputFileSegmenter, oldS

oldTrigger := oldSchema.TryGetTriggerMatching(newTrigger)
if oldTrigger == nil || !oldTrigger.Equals(newTrigger) {
ofs.WriteSql(GlobalTrigger.GetCreationSql(newSchema, newTrigger)...)
ofs.WriteSql(getCreateTriggerSql(newSchema, newTrigger)...)
}
}
}
2 changes: 1 addition & 1 deletion lib/format/pgsql8/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func buildSchema(doc *ir.Definition, ofs output.OutputFileSegmenter, tableDep []
for _, schema := range doc.Schemas {
for _, trigger := range schema.Triggers {
if trigger.SqlFormat.Equals(ir.SqlFormatPgsql8) {
ofs.WriteSql(GlobalTrigger.GetCreationSql(schema, trigger)...)
ofs.WriteSql(getCreateTriggerSql(schema, trigger)...)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/format/pgsql8/pgsql8.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "github.com/dbsteward/dbsteward/lib/format"

var GlobalOperations = NewOperations()
var GlobalSchema = NewSchema()
var GlobalTrigger = NewTrigger()
var GlobalDataType = NewDataType()
var GlobalView = NewView()
var GlobalDiffConstraints = NewDiffConstraints()
Expand Down
20 changes: 6 additions & 14 deletions lib/format/pgsql8/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ import (
"github.com/dbsteward/dbsteward/lib/output"
)

type Trigger struct {
IncludeColumnDefaultNextvalInCreateSql bool
}

func NewTrigger() *Trigger {
return &Trigger{}
}

func (self *Trigger) GetCreationSql(schema *ir.Schema, trigger *ir.Trigger) []output.ToSql {
func getCreateTriggerSql(schema *ir.Schema, trigger *ir.Trigger) []output.ToSql {
// TODO(go,3) move validation elsewhere
if table := schema.TryGetTableNamed(trigger.Table); table == nil {
lib.GlobalDBSteward.Fatal("Failed to find trigger table %s.%s", schema.Name, trigger.Table)
Expand All @@ -29,8 +21,8 @@ func (self *Trigger) GetCreationSql(schema *ir.Schema, trigger *ir.Trigger) []ou

return []output.ToSql{
&sql.TriggerCreate{
Trigger: sql.TriggerRef{schema.Name, trigger.Name},
Table: sql.TableRef{schema.Name, trigger.Table},
Trigger: sql.TriggerRef{Schema: schema.Name, Trigger: trigger.Name},
Table: sql.TableRef{Schema: schema.Name, Table: trigger.Table},
Timing: string(trigger.Timing),
Events: trigger.Events,
ForEach: string(trigger.ForEach),
Expand All @@ -39,11 +31,11 @@ func (self *Trigger) GetCreationSql(schema *ir.Schema, trigger *ir.Trigger) []ou
}
}

func (self *Trigger) GetDropSql(schema *ir.Schema, trigger *ir.Trigger) []output.ToSql {
func getDropTriggerSql(schema *ir.Schema, trigger *ir.Trigger) []output.ToSql {
return []output.ToSql{
&sql.TriggerDrop{
Trigger: sql.TriggerRef{schema.Name, trigger.Name},
Table: sql.TableRef{schema.Name, trigger.Table},
Trigger: sql.TriggerRef{Schema: schema.Name, Trigger: trigger.Name},
Table: sql.TableRef{Schema: schema.Name, Table: trigger.Table},
},
}
}

0 comments on commit fa9d0ea

Please sign in to comment.