Skip to content

Commit

Permalink
fix: disable fk checks for sqlite on migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Feb 17, 2021
1 parent ccac199 commit 50745d4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion popx/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,24 @@ func (m Migrator) exec(ctx context.Context, fn func() error) error {
if err != nil {
return errors.Wrap(err, "migrator: problem creating schema migrations")
}
return fn()

if m.Connection.Dialect.Name() == "sqlite3" {
if err := m.Connection.RawQuery("PRAGMA foreign_keys=OFF").Exec(); err!= nil {
return err
}
}

if err := fn(); err != nil {
return err
}

if m.Connection.Dialect.Name() == "sqlite3" {
if err := m.Connection.RawQuery("PRAGMA foreign_keys=ON").Exec(); err!= nil {
return err
}
}

return nil
}

func (m Migrator) printTimer(timerStart time.Time) {
Expand Down

0 comments on commit 50745d4

Please sign in to comment.