mirror of
https://github.com/status-im/migrate.git
synced 2025-02-23 16:28:08 +00:00
Merge pull request #135 from ansel1/master
Avoid DDL when checking for versions table #134
This commit is contained in:
commit
eb0eec4471
@ -43,6 +43,14 @@ func (driver *Driver) Close() error {
|
||||
}
|
||||
|
||||
func (driver *Driver) ensureVersionTableExists() error {
|
||||
r := driver.db.QueryRow("SELECT count(*) FROM information_schema.tables WHERE table_name = $1;", tableName)
|
||||
c := 0
|
||||
if err := r.Scan(&c); err != nil {
|
||||
return err
|
||||
}
|
||||
if c > 0 {
|
||||
return nil
|
||||
}
|
||||
if _, err := driver.db.Exec("CREATE TABLE IF NOT EXISTS " + tableName + " (version int not null primary key);"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -37,6 +37,11 @@ func TestMigrate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// testing idempotency: second call should be a no-op, since table already exists
|
||||
if err := d.Initialize(driverUrl); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
files := []file.File{
|
||||
{
|
||||
Path: "/foobar",
|
||||
|
Loading…
x
Reference in New Issue
Block a user