mirror of
https://github.com/status-im/migrate.git
synced 2025-02-24 00:38:07 +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 {
|
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 {
|
if _, err := driver.db.Exec("CREATE TABLE IF NOT EXISTS " + tableName + " (version int not null primary key);"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,11 @@ func TestMigrate(t *testing.T) {
|
|||||||
t.Fatal(err)
|
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{
|
files := []file.File{
|
||||||
{
|
{
|
||||||
Path: "/foobar",
|
Path: "/foobar",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user