-
Notifications
You must be signed in to change notification settings - Fork 3
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
v2 #2
v2 #2
Conversation
- Implemented FileTemplate method - Locking during migrations - Custom transactions / disable transactions
9e1a0be
to
8738ef5
Compare
mysql.go
Outdated
func (drv *Driver) Lock() error { | ||
// NOTE: versionTx will be implicitly committed by LOCK TABLES | ||
// the only reason we need it is to get exclusive db connection. | ||
// TODO: go1.9 has DB.Conn() which returns exclusive connection, use it when time comes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the time already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use 1.9 in production yet, waiting some time before upgrading minor version of Go is quite popular practice. I built custom migrations appliance on top of migrate package. Moving it to DB.Conn() is not a big deal, let's wait a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok fine
mysql.go
Outdated
versionUpdSQL = "DELETE FROM " + versionsTableName + " WHERE version = ?" | ||
} | ||
if _, err = drv.versionTx.Exec(versionUpdSQL, f.Version); err != nil { | ||
drv.rollbackVersionTx() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the record, if the rollback fails, the error is lost here.
mysql.go
Outdated
type migration struct { | ||
// notx determines if default transaction | ||
// should be disabled | ||
notx bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be noTx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid reading notX
mysql.go
Outdated
return fmt.Errorf("Failed to commit lines %d-%d: %s", s.txbegin, s.txend, err) | ||
} | ||
|
||
// newStmt is a DRYer for migration.parse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong func name
mysql.go
Outdated
// It locks schema_migrations table, so concurrent execution is safe. | ||
func (drv *Driver) Migrate(f file.File) error { | ||
if drv.versionTx == nil { | ||
return errors.New("migrate must call Lock before Migrate") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you lock here instead of returning an error?
There could be an unlock
added as a defer too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we could lock/unlock here, there would be no reason for exposing Lock/Unlock methods in driver interface. migrate
package is responsible for locking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall very good work!
I just have minor issues to be addressed before merging this.
Thanks!
Place SQL between "-- TXBEGIN" and "-- TXEND" comments for custom transaction: | ||
- you CAN have multiple separate transactions in single migration | ||
- any SQL not wrapped into TXBEGIN - TXEND will be executed without transaction. | ||
Add "-- NOTX" comment above all SQL to disable default transaction. NOTE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably unify this with the existing -- disable_ddl_transaction
in pg driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to keep this "directive" comments short to avoid potential misspelling, or we should add some prefix (like ++
in goose) to apply validations and throw error if user misspelled something
Upd for db-journey/migrate#3 and some extra features: