Skip to content

Commit

Permalink
Build map of starting bytes pointing to statement
Browse files Browse the repository at this point in the history
  • Loading branch information
qbart committed Nov 30, 2021
1 parent ccf5b40 commit 589cd29
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions krab/type_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,27 @@ func (m *MigrationUpOrDown) ToSQL(w io.StringWriter) {
func (m *MigrationUpOrDown) ToSQLStatements() SQLStatements {
sqls := SQLStatements{}

toSort := map[int]ToSQL{}

if m.SQL != "" {
sqls.Append(m)
toSort[m.AttrDefRanges["sql"].Start.Byte] = m
}

for _, t := range m.CreateTables {
sqls.Append(t)
toSort[t.DefRange.Start.Byte] = t
}
for _, t := range m.CreateIndices {
sqls.Append(t)
toSort[t.DefRange.Start.Byte] = t
}
for _, t := range m.DropIndices {
sqls.Append(t)
toSort[t.DefRange.Start.Byte] = t
}
for _, t := range m.DropTables {
sqls.Append(t)
toSort[t.DefRange.Start.Byte] = t
}

for _, sql := range toSort {
sqls.Append(sql)
}

return sqls
Expand Down

0 comments on commit 589cd29

Please sign in to comment.