Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func process(migrator *Migrator, filename string, fileReadFn func(string) ([]byt

err = migrator.Run(matches[1], matches[2], string(content))
if err != nil {
return fmt.Errorf("error running migration: %w", err)
return fmt.Errorf("%w", err)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions db/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func (m *Migrator) Setup() error {
// Run a particular database migration and inserting its timestamp
// on the migrations table.
func (m *Migrator) Run(timestamp, name, sql string) error {
migName := timestamp + "-" + name
var exists bool
row := m.db.QueryRow("SELECT EXISTS (SELECT 1 FROM schema_migrations WHERE timestamp = $1)", timestamp)
err := row.Scan(&exists)
if err != nil {
return fmt.Errorf("❌ %s: error checking last migration: %w", migName, err)
return fmt.Errorf("❌ error checking last migration: %w", err)
}

if exists {
return nil
}

migName := timestamp + "-" + name
_, err = m.db.Exec(sql)
if err != nil {
err = fmt.Errorf("❌ %s: error running migration: %w", migName, err)
Expand All @@ -46,7 +46,7 @@ func (m *Migrator) Run(timestamp, name, sql string) error {

_, err = m.db.Exec("INSERT INTO schema_migrations (timestamp) VALUES ($1);", timestamp)
if err != nil {
err = fmt.Errorf("❌ %s: error updating migrations table: %w", migName, err)
err = fmt.Errorf("❌ %w", err)
return err
}

Expand Down
Loading