From 1429d6f57c67dff51fc41ca0c2868f8d000845f1 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Sun, 30 Jun 2024 15:06:10 -0400 Subject: [PATCH] fix: column nullability blunder --- .../database/SqliteDatabaseAccessService.js | 7 +++- .../database/sqlite_setup/0018_fix-0003.sql | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/services/database/sqlite_setup/0018_fix-0003.sql diff --git a/packages/backend/src/services/database/SqliteDatabaseAccessService.js b/packages/backend/src/services/database/SqliteDatabaseAccessService.js index ca189d95..e2d844d5 100644 --- a/packages/backend/src/services/database/SqliteDatabaseAccessService.js +++ b/packages/backend/src/services/database/SqliteDatabaseAccessService.js @@ -42,7 +42,7 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService { this.db = new Database(this.config.path); // Database upgrade logic - const TARGET_VERSION = 15; + const TARGET_VERSION = 16; if ( do_setup ) { this.log.noticeme(`SETUP: creating database at ${this.config.path}`); @@ -64,6 +64,7 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService { '0015_group.sql', '0016_group-permissions.sql', '0017_publicdirs.sql', + '0018_fix-0003.sql', ].map(p => path_.join(__dirname, 'sqlite_setup', p)); const fs = require('fs'); for ( const filename of sql_files ) { @@ -140,6 +141,10 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService { upgrade_files.push('0017_publicdirs.sql'); } + if ( user_version <= 15 ) { + upgrade_files.push('0018_fix-0003.sql'); + } + if ( upgrade_files.length > 0 ) { this.log.noticeme(`Database out of date: ${this.config.path}`); this.log.noticeme(`UPGRADING DATABASE: ${user_version} -> ${TARGET_VERSION}`); diff --git a/packages/backend/src/services/database/sqlite_setup/0018_fix-0003.sql b/packages/backend/src/services/database/sqlite_setup/0018_fix-0003.sql new file mode 100644 index 00000000..be3a07ee --- /dev/null +++ b/packages/backend/src/services/database/sqlite_setup/0018_fix-0003.sql @@ -0,0 +1,40 @@ +CREATE TABLE `audit_user_to_user_permissions_new` ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT, + + "issuer_user_id" INTEGER DEFAULT NULL, + "issuer_user_id_keep" INTEGER DEFAULT NULL, + + "holder_user_id" INTEGER DEFAULT NULL, + "holder_user_id_keep" INTEGER DEFAULT NULL, + + "permission" TEXT NOT NULL, + "extra" JSON DEFAULT NULL, + + "action" TEXT DEFAULT NULL, + "reason" TEXT DEFAULT NULL, + + "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + FOREIGN KEY("issuer_user_id") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + FOREIGN KEY("holder_user_id") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); + +INSERT INTO `audit_user_to_user_permissions_new` +( + `id`, + `issuer_user_id`, `issuer_user_id_keep`, + `holder_user_id`, `holder_user_id_keep`, + `permission`, `extra`, `action`, `reason`, + `created_at` +) +SELECT + `id`, + `issuer_user_id`, `issuer_user_id_keep`, + `holder_user_id`, `holder_user_id_keep`, + `permission`, `extra`, `action`, `reason`, + `created_at` +FROM `audit_user_to_user_permissions`; +DROP TABLE `audit_user_to_user_permissions`; + +ALTER TABLE `audit_user_to_user_permissions_new` +RENAME TO `audit_user_to_user_permissions`;