fix: verify SQL migrations before recording and preserve sessions (#3)
This commit is contained in:
1 parent
370407d3ba
commit
a59cc7ccb7
4 files changed
+145
-12
No files matched your search
@@ -157,13 +157,8 @@ func RunSQLMigrations(db *gorm.DB, migrations fs.FS, onApply func(filename strin
|
||||
return applied, fmt.Errorf("read migration %s: %w", filename, err)
|
||||
}
|
||||
|
||||
if statements := splitSQLStatements(string(content)); len(statements) > 0 {
|
||||
if err := executeMigrationStatements(db, filename, statements); err != nil {
|
||||
return applied, err
|
||||
}
|
||||
}
|
||||
if err := db.Create(&SQLSchemaMigration{Filename: filename}).Error; err != nil {
|
||||
return applied, fmt.Errorf("record migration %s: %w", filename, err)
|
||||
if err := applySQLMigrationFile(db, filename, string(content)); err != nil {
|
||||
return applied, err
|
||||
}
|
||||
applied = append(applied, filename)
|
||||
}
|
||||
@@ -235,9 +230,6 @@ func isIgnorableMigrationError(message string) bool {
|
||||
"duplicate column name",
|
||||
"duplicate key name",
|
||||
"already exists",
|
||||
"can't create table",
|
||||
"duplicate foreign key constraint name",
|
||||
"errno 121",
|
||||
}
|
||||
for _, pattern := range ignorable {
|
||||
if strings.Contains(lower, pattern) {
|
||||
|
||||
Reference in new issue
Block a user