fix: column nullability blunder

This commit is contained in:
KernelDeimos 2024-06-30 15:06:10 -04:00
parent b10302ad74
commit 1429d6f57c
2 changed files with 46 additions and 1 deletions

View File

@ -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}`);

View File

@ -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`;