From ac40b2f73341be433993d5072062277856ccdfd9 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 25 Sep 2023 14:51:28 -0400 Subject: [PATCH] Fix publishjobs `id` column in SQLite Previously, didn't auto-increment or populate --- migrations/drivers.go | 9 +++++++++ migrations/v13.go | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/migrations/drivers.go b/migrations/drivers.go index f19b6c9..800d2a6 100644 --- a/migrations/drivers.go +++ b/migrations/drivers.go @@ -72,6 +72,15 @@ func (db *datastore) typeDateTime() string { return "DATETIME" } +func (db *datastore) typeIntPrimaryKey() string { + if db.driverName == driverSQLite { + // From docs: "In SQLite, a column with type INTEGER PRIMARY KEY is an alias for the ROWID (except in WITHOUT + // ROWID tables) which is always a 64-bit signed integer." + return "INTEGER PRIMARY KEY" + } + return "INT AUTO_INCREMENT PRIMARY KEY" +} + func (db *datastore) collateMultiByte() string { if db.driverName == driverSQLite { return "" diff --git a/migrations/v13.go b/migrations/v13.go index b6c6c3a..5bb954b 100644 --- a/migrations/v13.go +++ b/migrations/v13.go @@ -18,11 +18,10 @@ func supportLetters(db *datastore) error { } _, err = t.Exec(`CREATE TABLE publishjobs ( - id ` + db.typeInt() + ` auto_increment, + id ` + db.typeIntPrimaryKey() + `, post_id ` + db.typeVarChar(16) + ` not null, action ` + db.typeVarChar(16) + ` not null, - delay ` + db.typeTinyInt() + ` not null, - PRIMARY KEY (id) + delay ` + db.typeTinyInt() + ` not null )`) if err != nil { t.Rollback()