Skip to content

Commit

Permalink
Merge pull request #307 from SiaFoundation/nate/fix-migration
Browse files Browse the repository at this point in the history
Disable foreign key constraints during migration
  • Loading branch information
n8maninger committed Feb 16, 2024
2 parents 144e896 + 4bf5c5b commit 6f0a7b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 0 additions & 5 deletions persist/sqlite/init.go
Expand Up @@ -68,11 +68,6 @@ func (s *Store) upgradeDatabase(current, target int64) error {
func (s *Store) init() error {
// calculate the expected final database version
target := int64(len(migrations) + 1)
// disable foreign key constraints during migration
if _, err := s.db.Exec("PRAGMA foreign_keys = OFF"); err != nil {
return fmt.Errorf("failed to disable foreign key constraints: %w", err)
}

version := getDBVersion(s.db)
switch {
case version == 0:
Expand Down
5 changes: 5 additions & 0 deletions persist/sqlite/migrations.go
Expand Up @@ -10,6 +10,11 @@ import (
"go.uber.org/zap"
)

func migrateVersion25(tx txn, log *zap.Logger) error {
// no-op migration to trigger foreign key checks
return nil
}

// migrateVersion24 combines the rhp2 and rhp3 data metrics
func migrateVersion24(tx txn, log *zap.Logger) error {
rows, err := tx.Query(`SELECT date_created, stat, stat_value FROM host_stats WHERE stat IN (?, ?, ?, ?) ORDER BY date_created ASC`, metricRHP2Ingress, metricRHP2Egress, metricRHP3Ingress, metricRHP3Egress)
Expand Down

0 comments on commit 6f0a7b6

Please sign in to comment.