Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CockroachDB support. #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
9 changes: 7 additions & 2 deletions migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Register(name string, up, down func(*pg.Tx) error) {
/*
Run Runs the specified command with the options they require
Note:

init - no options
migrate - one option
- "" for all migrations in a single batch
Expand All @@ -80,7 +81,11 @@ func Run(db *pg.DB, cmd string, options ...string) error {
if len(options) > 0 {
extra = options[0]
}
return migrate(db, extra == "one-by-one")
err := migrate(db, extra == "one-by-one")
if err != nil {
return errors.Wrap(err, "migration failed")
}
return nil

case "rollback":
return rollback(db)
Expand Down Expand Up @@ -394,7 +399,7 @@ func lockTable(tx *pg.Tx) error {
// https://www.postgresql.org/docs/current/explicit-locking.html
// This mode protects a table against concurrent data changes, and is self-exclusive so that only one session can hold it at a time.
// This means only one migration can run at a time, but pg_dump can still COPY from the table (since it acquires a ACCESS SHARE lock, or so I am told)
_, err = tx.Exec("LOCK ? in SHARE ROW EXCLUSIVE MODE", pg.Ident(migrationTableName))
//_, err = tx.Exec("LOCK ? in SHARE ROW EXCLUSIVE MODE", pg.Ident(migrationTableName))

return err
}
Expand Down