Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Sep 6, 2024
1 parent ef4c6c4 commit 74fbd80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion state/storage/sqlstorage/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func TestUpdateForkID(t *testing.T) {
err = storage.AddForkID(ctx, forkInterval, dbTx)
require.NoError(t, err)
forkInterval.ToBatchNumber = 3
storage.UpdateForkID(ctx, forkInterval, dbTx)
err = storage.UpdateForkID(ctx, forkInterval, dbTx)
require.NoError(t, err)
readForkIntervals, err := storage.GetForkIDs(ctx, dbTx)
require.NoError(t, err)
require.Len(t, readForkIntervals, 1)
Expand Down
3 changes: 2 additions & 1 deletion state/storage/sqlstorage/l1infotree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func TestL1InfoRootRemovedOnCascade(t *testing.T) {
err = storage.AddL1InfoTreeLeaf(ctx, &leaf, dbTx)
require.NoError(t, err)
}
storage.ResetToL1BlockNumber(ctx, 1, dbTx)
err = storage.ResetToL1BlockNumber(ctx, 1, dbTx)
require.NoError(t, err)
leafsRead, err := storage.GetAllL1InfoTreeLeaves(ctx, dbTx)
require.NoError(t, err)
require.NotNil(t, leafsRead)
Expand Down
14 changes: 13 additions & 1 deletion state/storage/sqlstorage/sqlstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type SqlStorage struct {
db *sql.DB
}

const (
SqliteDriverName = "sqlite3"
)

func NewSqlStorage(cfg Config, runMigrations bool) (*SqlStorage, error) {
log.Infof("Running DB migrations")

Expand All @@ -33,7 +37,15 @@ func NewSqlStorage(cfg Config, runMigrations bool) (*SqlStorage, error) {
return nil, err
}
}
db.Exec("PRAGMA foreign_keys = ON;")
if cfg.DriverName == SqliteDriverName {
log.Debugf("Enabling foreign keys for sqlite database")
_, err = db.Exec("PRAGMA foreign_keys = ON;")
if err != nil {
err := fmt.Errorf("error enabling foreign keys: %w", err)
log.Errorf(err.Error())
return nil, err
}
}
return &SqlStorage{db}, nil
}

Expand Down

0 comments on commit 74fbd80

Please sign in to comment.