Skip to content

Commit

Permalink
btcsupply: don't run migrations and seeds in read only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 18, 2024
1 parent 0f9c373 commit 5635691
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/btcsupply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
}

func main() {
db, err := sqlite.NewSqliteBackend()
db, err := sqlite.NewSqliteBackend(noindex)
defer db.Close()
if err != nil {
log.Fatal().Err(err).Msg("Failed to open database")
Expand Down
16 changes: 9 additions & 7 deletions storage/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SqliteBackend struct {
db *sql.DB
}

func NewSqliteBackend() (*SqliteBackend, error) {
func NewSqliteBackend(readonly bool) (*SqliteBackend, error) {
path := os.Getenv("DB_PATH")
if path == "" {
return nil, fmt.Errorf("DB_PATH environment variable must be set")
Expand Down Expand Up @@ -50,13 +50,15 @@ func NewSqliteBackend() (*SqliteBackend, error) {
Msg("Database opened")

backend := &SqliteBackend{db: db}
if err := backend.Migrate(); err != nil {
return nil, fmt.Errorf("failed to migrate database: %w", err)
}
if !readonly {
if err := backend.Migrate(); err != nil {
return nil, fmt.Errorf("failed to migrate database: %w", err)
}

err = backend.seedBurnScriptsFromCSV()
if err != nil {
return nil, fmt.Errorf("failed to seed burn scripts: %w", err)
err = backend.seedBurnScriptsFromCSV()
if err != nil {
return nil, fmt.Errorf("failed to seed burn scripts: %w", err)
}
}

return backend, nil
Expand Down

0 comments on commit 5635691

Please sign in to comment.