New permissions database model

This commit is contained in:
Ben 2019-05-16 16:34:41 +01:00
parent 75c05604d9
commit 99e7a63957
2 changed files with 48 additions and 0 deletions

View File

@ -1,3 +1,5 @@
-- noinspection SqlDialectInspectionForFile
DROP TABLE IF EXISTS item; DROP TABLE IF EXISTS item;
CREATE TABLE item ( CREATE TABLE item (
"ID" INT NOT NULL, "ID" INT NOT NULL,
@ -528,6 +530,35 @@ COMMENT ON TABLE activation_key IS 'Penguin activation keys';
COMMENT ON COLUMN activation_key."PenguinID" IS 'Penguin ID'; COMMENT ON COLUMN activation_key."PenguinID" IS 'Penguin ID';
COMMENT ON COLUMN activation_key."ActivationKey" IS 'Penguin activation key'; COMMENT ON COLUMN activation_key."ActivationKey" IS 'Penguin activation key';
DROP TABLE IF EXISTS permission;
CREATE TABLE permission (
"ID" SERIAL NOT NULL,
"Name" VARCHAR(50) NOT NULL,
"Enabled" BOOLEAN NOT NULL DEFAULT TRUE,
PRIMARY KEY ("ID")
);
CREATE UNIQUE INDEX "Name" ON permission("Name");
COMMENT ON TABLE permission IS 'Registered server permissions';
COMMENT ON COLUMN permission."ID" IS 'Unique permission ID';
COMMENT ON COLUMN permission."Name" IS 'Unique permission identifier';
DROP TABLE IF EXISTS penguin_permission;
CREATE TABLE penguin_permission (
"PenguinID" INT NOT NULL,
"PermissionID" INT NOT NULL,
PRIMARY KEY ("PenguinID"),
CONSTRAINT penguin_permission_ibfk_1 FOREIGN KEY ("PenguinID") REFERENCES penguin("ID") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT penguin_permission_ibfk_2 FOREIGN KEY ("PermissionID") REFERENCES permission("ID") ON DELETE CASCADE ON UPDATE CASCADE
);
COMMENT ON TABLE penguin_permission IS 'Penguin permissions';
COMMENT ON COLUMN penguin_permission."PenguinID" IS 'Penguin ID';
COMMENT ON COLUMN penguin_permission."PermissionID" IS 'Penguin permission ID';
DROP TABLE IF EXISTS report; DROP TABLE IF EXISTS report;
CREATE TABLE report ( CREATE TABLE report (
"ID" SERIAL NOT NULL, "ID" SERIAL NOT NULL,

View File

@ -0,0 +1,17 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinPermission
class Permission(db.Model):
__tablename__ = 'permission'
ID = db.Column(db.Integer, primary_key=True, server_default=db.text("nextval('\"permission_ID_seq\"'::regclass)"))
Name = db.Column(db.String(50), nullable=False, unique=True)
Enabled = db.Column(db.Boolean, nullable=False, server_default=db.text("true"))
class PermissionCrumbsCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=Permission, key='ID', inventory_model=PenguinPermission,
inventory_id=inventory_id)