diff --git a/database/postgres/postgres.go b/database/postgres/postgres.go index c0989da..b840df8 100644 --- a/database/postgres/postgres.go +++ b/database/postgres/postgres.go @@ -255,14 +255,14 @@ func (p *Postgres) SetVersion(version int, dirty bool) error { return &database.Error{OrigErr: err, Err: "transaction start failed"} } - query := `TRUNCATE "` + p.config.MigrationsTable + `"` + query := `TRUNCATE ` + pq.QuoteIdentifier(p.config.MigrationsTable) if _, err := tx.Exec(query); err != nil { tx.Rollback() return &database.Error{OrigErr: err, Query: []byte(query)} } if version >= 0 { - query = `INSERT INTO "` + p.config.MigrationsTable + `" (version, dirty) VALUES ($1, $2)` + query = `INSERT INTO ` + pq.QuoteIdentifier(p.config.MigrationsTable) + ` (version, dirty) VALUES ($1, $2)` if _, err := tx.Exec(query, version, dirty); err != nil { tx.Rollback() return &database.Error{OrigErr: err, Query: []byte(query)} @@ -277,7 +277,7 @@ func (p *Postgres) SetVersion(version int, dirty bool) error { } func (p *Postgres) Version() (version int, dirty bool, err error) { - query := `SELECT version, dirty FROM "` + p.config.MigrationsTable + `" LIMIT 1` + query := `SELECT version, dirty FROM ` + pq.QuoteIdentifier(p.config.MigrationsTable) + ` LIMIT 1` err = p.conn.QueryRowContext(context.Background(), query).Scan(&version, &dirty) switch { case err == sql.ErrNoRows: @@ -320,7 +320,7 @@ func (p *Postgres) Drop() error { if len(tableNames) > 0 { // delete one by one ... for _, t := range tableNames { - query = `DROP TABLE IF EXISTS "` + t + `" CASCADE` + query = `DROP TABLE IF EXISTS ` + pq.QuoteIdentifier(t) + ` CASCADE` if _, err := p.conn.ExecContext(context.Background(), query); err != nil { return &database.Error{OrigErr: err, Query: []byte(query)} } @@ -348,7 +348,7 @@ func (p *Postgres) ensureVersionTable() (err error) { } }() - query := `CREATE TABLE IF NOT EXISTS "` + p.config.MigrationsTable + `" (version bigint not null primary key, dirty boolean not null)` + query := `CREATE TABLE IF NOT EXISTS ` + pq.QuoteIdentifier(p.config.MigrationsTable) + ` (version bigint not null primary key, dirty boolean not null)` if _, err = p.conn.ExecContext(context.Background(), query); err != nil { return &database.Error{OrigErr: err, Query: []byte(query)} }