diff --git a/cmd/icingadb-migrate/misc.go b/cmd/icingadb-migrate/misc.go index f1db20cbe..b8d358fff 100644 --- a/cmd/icingadb-migrate/misc.go +++ b/cmd/icingadb-migrate/misc.go @@ -4,7 +4,6 @@ import ( "context" "crypto/sha1" "github.com/icinga/icingadb/pkg/contracts" - "github.com/icinga/icingadb/pkg/driver" "github.com/icinga/icingadb/pkg/icingadb" "github.com/icinga/icingadb/pkg/icingadb/objectpacker" icingadbTypes "github.com/icinga/icingadb/pkg/types" @@ -110,7 +109,7 @@ func sliceIdoHistory[Row any]( args["checkpoint"] = checkpoint args["bulk"] = 20000 - if ht.snapshot.DriverName() != driver.MySQL { + if ht.snapshot.DriverName() != icingadb.MySQL { query = strings.ReplaceAll(query, " USE INDEX (PRIMARY)", "") } diff --git a/pkg/config/database.go b/pkg/config/database.go index 7fb506175..a71378813 100644 --- a/pkg/config/database.go +++ b/pkg/config/database.go @@ -6,7 +6,6 @@ import ( "database/sql/driver" "fmt" "github.com/go-sql-driver/mysql" - icingadbDriver "github.com/icinga/icingadb/pkg/driver" "github.com/icinga/icingadb/pkg/icingadb" "github.com/icinga/icingadb/pkg/logging" "github.com/icinga/icingadb/pkg/utils" @@ -40,7 +39,7 @@ type Database struct { // calls sqlx.Open, but returns *icingadb.DB. func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) { registerDriverOnce.Do(func() { - icingadbDriver.Register(logger) + icingadb.Register(logger) }) var db *sqlx.DB @@ -89,7 +88,7 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) { return setGaleraOpts(ctx, conn, wsrepSyncWait) } - db = sqlx.NewDb(sql.OpenDB(icingadbDriver.NewConnector(c, logger, setWsrepSyncWait)), icingadbDriver.MySQL) + db = sqlx.NewDb(sql.OpenDB(icingadb.NewConnector(c, logger, setWsrepSyncWait)), icingadb.MySQL) case "pgsql": uri := &url.URL{ Scheme: "postgres", @@ -143,7 +142,7 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) { return nil, errors.Wrap(err, "can't open pgsql database") } - db = sqlx.NewDb(sql.OpenDB(icingadbDriver.NewConnector(connector, logger, nil)), icingadbDriver.PostgreSQL) + db = sqlx.NewDb(sql.OpenDB(icingadb.NewConnector(connector, logger, nil)), icingadb.PostgreSQL) default: return nil, unknownDbType(d.Type) } diff --git a/pkg/icingadb/cleanup.go b/pkg/icingadb/cleanup.go index 38f934258..15d36e86f 100644 --- a/pkg/icingadb/cleanup.go +++ b/pkg/icingadb/cleanup.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/icinga/icingadb/internal" "github.com/icinga/icingadb/pkg/com" - "github.com/icinga/icingadb/pkg/driver" "github.com/icinga/icingadb/pkg/types" "time" ) @@ -20,10 +19,10 @@ type CleanupStmt struct { // Build assembles the cleanup statement for the specified database driver with the given limit. func (stmt *CleanupStmt) Build(driverName string, limit uint64) string { switch driverName { - case driver.MySQL: + case MySQL: return fmt.Sprintf(`DELETE FROM %[1]s WHERE environment_id = :environment_id AND %[2]s < :time ORDER BY %[2]s LIMIT %[3]d`, stmt.Table, stmt.Column, limit) - case driver.PostgreSQL: + case PostgreSQL: return fmt.Sprintf(`WITH rows AS ( SELECT %[1]s FROM %[2]s WHERE environment_id = :environment_id AND %[3]s < :time ORDER BY %[3]s LIMIT %[4]d ) diff --git a/pkg/icingadb/db.go b/pkg/icingadb/db.go index 91901608d..7b10a53f1 100644 --- a/pkg/icingadb/db.go +++ b/pkg/icingadb/db.go @@ -7,7 +7,6 @@ import ( "github.com/icinga/icingadb/pkg/backoff" "github.com/icinga/icingadb/pkg/com" "github.com/icinga/icingadb/pkg/contracts" - "github.com/icinga/icingadb/pkg/driver" "github.com/icinga/icingadb/pkg/logging" "github.com/icinga/icingadb/pkg/periodic" "github.com/icinga/icingadb/pkg/retry" @@ -97,9 +96,9 @@ const ( func (db *DB) CheckSchema(ctx context.Context) error { var expectedDbSchemaVersion uint16 switch db.DriverName() { - case driver.MySQL: + case MySQL: expectedDbSchemaVersion = expectedMysqlSchemaVersion - case driver.PostgreSQL: + case PostgreSQL: expectedDbSchemaVersion = expectedPostgresSchemaVersion } @@ -165,10 +164,10 @@ func (db *DB) BuildInsertIgnoreStmt(into interface{}) (string, int) { var clause string switch db.DriverName() { - case driver.MySQL: + case MySQL: // MySQL treats UPDATE id = id as a no-op. clause = fmt.Sprintf(`ON DUPLICATE KEY UPDATE "%s" = "%s"`, columns[0], columns[0]) - case driver.PostgreSQL: + case PostgreSQL: clause = fmt.Sprintf("ON CONFLICT ON CONSTRAINT pk_%s DO NOTHING", table) } @@ -228,10 +227,10 @@ func (db *DB) BuildUpsertStmt(subject interface{}) (stmt string, placeholders in var clause, setFormat string switch db.DriverName() { - case driver.MySQL: + case MySQL: clause = "ON DUPLICATE KEY UPDATE" setFormat = `"%[1]s" = VALUES("%[1]s")` - case driver.PostgreSQL: + case PostgreSQL: clause = fmt.Sprintf("ON CONFLICT ON CONSTRAINT pk_%s DO UPDATE SET", table) setFormat = `"%[1]s" = EXCLUDED."%[1]s"` } diff --git a/pkg/driver/driver.go b/pkg/icingadb/driver.go similarity index 99% rename from pkg/driver/driver.go rename to pkg/icingadb/driver.go index 4615ab6ef..8f04c000d 100644 --- a/pkg/driver/driver.go +++ b/pkg/icingadb/driver.go @@ -1,4 +1,4 @@ -package driver +package icingadb import ( "context" diff --git a/pkg/icingadb/ha.go b/pkg/icingadb/ha.go index 74d3b3234..82ddf30dd 100644 --- a/pkg/icingadb/ha.go +++ b/pkg/icingadb/ha.go @@ -9,7 +9,6 @@ import ( "github.com/icinga/icingadb/internal" "github.com/icinga/icingadb/pkg/backoff" "github.com/icinga/icingadb/pkg/com" - "github.com/icinga/icingadb/pkg/driver" v1 "github.com/icinga/icingadb/pkg/icingadb/v1" "github.com/icinga/icingadb/pkg/icingaredis" icingaredisv1 "github.com/icinga/icingadb/pkg/icingaredis/v1" @@ -251,7 +250,7 @@ func (h *HA) realize(ctx context.Context, s *icingaredisv1.IcingaStatus, t *type isoLvl := sql.LevelSerializable selectLock := "" - if h.db.DriverName() == driver.MySQL { + if h.db.DriverName() == MySQL { // The RDBMS may actually be a Percona XtraDB Cluster which doesn't // support serializable transactions, but only their following equivalent: isoLvl = sql.LevelRepeatableRead