Merge pull request #135 from ansel1/master

Avoid DDL when checking for versions table #134
This commit is contained in:
Matthias Kadenbach 2017-01-06 14:24:59 -08:00 committed by GitHub
commit eb0eec4471
2 changed files with 13 additions and 0 deletions

View File

@ -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
}

View File

@ -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",