cmd/stdiscosrv: Fix index creation checks on startup

This commit is contained in:
Jakob Borg 2016-08-12 11:39:10 +02:00
parent 480b78f2c8
commit e6364407a9

View File

@ -27,8 +27,9 @@ func postgresSetup(db *sql.DB) error {
return err return err
} }
var tmp string
row := db.QueryRow(`SELECT 'DevicesDeviceIDIndex'::regclass`) row := db.QueryRow(`SELECT 'DevicesDeviceIDIndex'::regclass`)
if err = row.Scan(nil); err != nil { if err = row.Scan(&tmp); err != nil {
_, err = db.Exec(`CREATE INDEX DevicesDeviceIDIndex ON Devices (DeviceID)`) _, err = db.Exec(`CREATE INDEX DevicesDeviceIDIndex ON Devices (DeviceID)`)
} }
if err != nil { if err != nil {
@ -36,7 +37,7 @@ func postgresSetup(db *sql.DB) error {
} }
row = db.QueryRow(`SELECT 'DevicesSeenIndex'::regclass`) row = db.QueryRow(`SELECT 'DevicesSeenIndex'::regclass`)
if err = row.Scan(nil); err != nil { if err = row.Scan(&tmp); err != nil {
_, err = db.Exec(`CREATE INDEX DevicesSeenIndex ON Devices (Seen)`) _, err = db.Exec(`CREATE INDEX DevicesSeenIndex ON Devices (Seen)`)
} }
if err != nil { if err != nil {
@ -53,7 +54,7 @@ func postgresSetup(db *sql.DB) error {
} }
row = db.QueryRow(`SELECT 'AddressesDeviceIDSeenIndex'::regclass`) row = db.QueryRow(`SELECT 'AddressesDeviceIDSeenIndex'::regclass`)
if err = row.Scan(nil); err != nil { if err = row.Scan(&tmp); err != nil {
_, err = db.Exec(`CREATE INDEX AddressesDeviceIDSeenIndex ON Addresses (DeviceID, Seen)`) _, err = db.Exec(`CREATE INDEX AddressesDeviceIDSeenIndex ON Addresses (DeviceID, Seen)`)
} }
if err != nil { if err != nil {
@ -61,7 +62,7 @@ func postgresSetup(db *sql.DB) error {
} }
row = db.QueryRow(`SELECT 'AddressesDeviceIDAddressIndex'::regclass`) row = db.QueryRow(`SELECT 'AddressesDeviceIDAddressIndex'::regclass`)
if err = row.Scan(nil); err != nil { if err = row.Scan(&tmp); err != nil {
_, err = db.Exec(`CREATE INDEX AddressesDeviceIDAddressIndex ON Addresses (DeviceID, Address)`) _, err = db.Exec(`CREATE INDEX AddressesDeviceIDAddressIndex ON Addresses (DeviceID, Address)`)
} }
if err != nil { if err != nil {