mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 22:40:20 +08:00
sql: group permissions table
This commit is contained in:
parent
0ddb13e8ee
commit
b817a78efa
@ -42,7 +42,7 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
|
|||||||
this.db = new Database(this.config.path);
|
this.db = new Database(this.config.path);
|
||||||
|
|
||||||
// Database upgrade logic
|
// Database upgrade logic
|
||||||
const TARGET_VERSION = 13;
|
const TARGET_VERSION = 14;
|
||||||
|
|
||||||
if ( do_setup ) {
|
if ( do_setup ) {
|
||||||
this.log.noticeme(`SETUP: creating database at ${this.config.path}`);
|
this.log.noticeme(`SETUP: creating database at ${this.config.path}`);
|
||||||
@ -62,6 +62,7 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
|
|||||||
'0013_protected-apps.sql',
|
'0013_protected-apps.sql',
|
||||||
'0014_share.sql',
|
'0014_share.sql',
|
||||||
'0015_group.sql',
|
'0015_group.sql',
|
||||||
|
'0016_group-permissions.sql',
|
||||||
].map(p => path_.join(__dirname, 'sqlite_setup', p));
|
].map(p => path_.join(__dirname, 'sqlite_setup', p));
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
for ( const filename of sql_files ) {
|
for ( const filename of sql_files ) {
|
||||||
@ -130,6 +131,10 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
|
|||||||
upgrade_files.push('0015_group.sql');
|
upgrade_files.push('0015_group.sql');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( user_version <= 13 ) {
|
||||||
|
upgrade_files.push('0016_group-permissions.sql');
|
||||||
|
}
|
||||||
|
|
||||||
if ( upgrade_files.length > 0 ) {
|
if ( upgrade_files.length > 0 ) {
|
||||||
this.log.noticeme(`Database out of date: ${this.config.path}`);
|
this.log.noticeme(`Database out of date: ${this.config.path}`);
|
||||||
this.log.noticeme(`UPGRADING DATABASE: ${user_version} -> ${TARGET_VERSION}`);
|
this.log.noticeme(`UPGRADING DATABASE: ${user_version} -> ${TARGET_VERSION}`);
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
CREATE TABLE `user_to_group_permissions` (
|
||||||
|
"user_id" INTEGER NOT NULL,
|
||||||
|
"group_id" INTEGER NOT NULL,
|
||||||
|
"permission" TEXT NOT NULL,
|
||||||
|
"extra" JSON DEFAULT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY("user_id") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
FOREIGN KEY("group_id") REFERENCES "group" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
PRIMARY KEY ("user_id", "group_id", "permission")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "audit_user_to_group_permissions" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
|
"user_id" INTEGER NOT NULL,
|
||||||
|
"user_id_keep" INTEGER DEFAULT NULL,
|
||||||
|
|
||||||
|
"group_id" INTEGER NOT NULL,
|
||||||
|
"group_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("user_id") REFERENCES "user" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
FOREIGN KEY("group_id") REFERENCES "group" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user