Skip to content

Commit 7d2f6d2

Browse files
committed
fix: group permission audit table
1 parent 4af279a commit 7d2f6d2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/backend/src/services/database/SqliteDatabaseAccessService.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
4242
this.db = new Database(this.config.path);
4343

4444
// Database upgrade logic
45-
const TARGET_VERSION = 16;
45+
const TARGET_VERSION = 17;
4646

4747
if ( do_setup ) {
4848
this.log.noticeme(`SETUP: creating database at ${this.config.path}`);
@@ -65,6 +65,7 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
6565
'0016_group-permissions.sql',
6666
'0017_publicdirs.sql',
6767
'0018_fix-0003.sql',
68+
'0019_fix-0016.sql',
6869
].map(p => path_.join(__dirname, 'sqlite_setup', p));
6970
const fs = require('fs');
7071
for ( const filename of sql_files ) {
@@ -145,6 +146,10 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
145146
upgrade_files.push('0018_fix-0003.sql');
146147
}
147148

149+
if ( user_version <= 16 ) {
150+
upgrade_files.push('0019_fix-0016.sql');
151+
}
152+
148153
if ( upgrade_files.length > 0 ) {
149154
this.log.noticeme(`Database out of date: ${this.config.path}`);
150155
this.log.noticeme(`UPGRADING DATABASE: ${user_version} -> ${TARGET_VERSION}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
CREATE TABLE `audit_user_to_group_permissions_new` (
2+
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
3+
4+
"user_id" INTEGER DEFAULT NULL,
5+
"user_id_keep" INTEGER NOT NULL,
6+
7+
"group_id" INTEGER DEFAULT NULL,
8+
"group_id_keep" INTEGER NOT NULL,
9+
10+
"permission" TEXT NOT NULL,
11+
"extra" JSON DEFAULT NULL,
12+
13+
"action" TEXT DEFAULT NULL,
14+
"reason" TEXT DEFAULT NULL,
15+
16+
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
17+
18+
FOREIGN KEY("user_id") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
19+
FOREIGN KEY("group_id") REFERENCES "group" ("id") ON DELETE SET NULL ON UPDATE CASCADE
20+
);
21+
22+
INSERT INTO `audit_user_to_group_permissions_new`
23+
(
24+
`id`,
25+
`user_id`, `user_id_keep`,
26+
`group_id`, `group_id_keep`,
27+
`permission`, `extra`, `action`, `reason`,
28+
`created_at`
29+
)
30+
SELECT
31+
`id`,
32+
`user_id`, `user_id_keep`,
33+
`group_id`, `group_id_keep`,
34+
`permission`, `extra`, `action`, `reason`,
35+
`created_at`
36+
FROM `audit_user_to_group_permissions`;
37+
DROP TABLE `audit_user_to_group_permissions`;
38+
39+
ALTER TABLE `audit_user_to_group_permissions_new`
40+
RENAME TO `audit_user_to_group_permissions`;
41+

0 commit comments

Comments
 (0)