Fix DisableCreateTable for MigrationSet instances.#242
Conversation
|
This PR adds a test verify that I believe this has uncovered another bug, which is that func (ms MigrationSet) GetMigrationRecords(db *sql.DB, dialect string) ([]*MigrationRecord, error) {
dbMap, err := ms.getMigrationDbMap(db, dialect)
if err != nil {
return nil, err
}
var records []*MigrationRecord
query := fmt.Sprintf("SELECT * FROM %s ORDER BY %s ASC", dbMap.Dialect.QuotedTableForQuery(ms.SchemaName, ms.getTableName()), dbMap.Dialect.QuoteField("id"))
_, err = dbMap.Select(&records, query)
if err != nil {
return nil, err
}
return records, nil
}I can picture three potential ways to fix this problem:
I don't think I can make this choice for you, but please feel free to build on top of this PR if you'd like to use it to help solve the problem! |
- Fix bug in testdb where state.hash wasn't getting set, so the template databases had colliding names. - Remove unnecessary semicolons from statements. - Fix bug where DROP DATABASE was not quoting the identifiers, leading to case-insensitive behavior. - Make the RecursiveHash more useful with AddFiles() and AddDirs(). - Use a Mutex to make GooseMigrator concurrency-safe. - Remove DisableCreateTable from the sqlmigrator.Hash() because it does not actually work (see rubenv/sql-migrate#242)
|
I think the point of disabling the creation of the table is for those cases where you want to manage that table yourself. However, you do need it to track state (it's not just reading it: after executing a migration it also inserts there). I wonder what your use case is to run completely without a migration table?
As a general advice: never do things like this, as it will silently hide configuration errors, then do the thing you probably do not want in such a scenario. |
OK, I'll update the tests to just confirm that sql-migrate will not attempt to create the table. Thank you for clarifying. I wasn't sure what was the intended behavior with
I am working on a library for quickly creating postgres databases for testing. As part of creating a test database, I assume users would like to run their migrations. I have therefore implemented adapters for all of the most popoular golang migration libraries, including an adaptor for sql-migrate. The sqlmigrator adapter uses a I personally do not use sql-migrate, and I don't know why someone would want to use |
Previously the DisableCreateTable setting was always being read from the global `migSet` instance. This meant that setting `ms.DisableCreateTable` on a given `var ms MigrationSet` instance had no effect. This commit fixes that bug, and adds a test to confirm the fix. Regardless of the global `migSet.DisableCreateTable` value, `ms.getMigrationDbMap()` will always read from `ms.DisableCreateTable`.
|
@rubenv this PR is now ready for review, it contains the bugfix and tests to confirm it 🥳 |
|
Merged, thanks a lot! |
Previously the DisableCreateTable setting was always being read from the global
migSetinstance. This meant that settingms.DisableCreateTableon a givenvar ms MigrationSetinstance had no effect.This commit fixes that bug, and adds a test to confirm the fix. Regardless of the global
migSet.DisableCreateTablevalue,ms.getMigrationDbMap()will always read fromms.DisableCreateTable.