Index permissions by name

This commit is contained in:
Ben 2020-05-17 03:22:47 +01:00
parent 4288248864
commit 99194d79f3
2 changed files with 10 additions and 11 deletions

View File

@ -696,32 +696,31 @@ COMMENT ON COLUMN activation_key.activation_key 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)
PRIMARY KEY (name)
);
CREATE UNIQUE INDEX permission_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 (
penguin_id INT NOT NULL,
permission_id INT NOT NULL,
PRIMARY KEY (penguin_id),
permission_name VARCHAR(50) NOT NULL,
PRIMARY KEY (penguin_id, permission_name),
CONSTRAINT penguin_permission_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin(id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT penguin_permission_ibfk_2 FOREIGN KEY (permission_id) REFERENCES permission(id) ON DELETE CASCADE ON UPDATE CASCADE
CONSTRAINT penguin_permission_ibfk_2 FOREIGN KEY (permission_name) REFERENCES permission(name) ON DELETE CASCADE ON UPDATE CASCADE
);
COMMENT ON TABLE penguin_permission IS 'Penguin permissions';
COMMENT ON COLUMN penguin_permission.penguin_id IS 'Penguin ID';
COMMENT ON COLUMN penguin_permission.permission_id IS 'Penguin permission ID';
COMMENT ON COLUMN penguin_permission.permission_name IS 'Penguin permission name';
DROP TABLE IF EXISTS penguin_attribute;
CREATE TABLE penguin_attribute (
name TEXT NOT NULL,

View File

@ -4,8 +4,7 @@ from houdini.data import AbstractDataCollection, db
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)
name = db.Column(db.String(50), nullable=False, primary_key=True)
enabled = db.Column(db.Boolean, nullable=False, server_default=db.text("true"))
@ -13,7 +12,8 @@ class PenguinPermission(db.Model):
__tablename__ = 'penguin_permission'
penguin_id = db.Column(db.ForeignKey(u'penguin.id', ondelete=u'CASCADE', onupdate=u'CASCADE'), primary_key=True)
permission_id = db.Column(db.ForeignKey(u'permission.id', ondelete=u'CASCADE', onupdate=u'CASCADE'), nullable=False)
permission_name = db.Column(db.ForeignKey(u'permission.name', ondelete=u'CASCADE', onupdate=u'CASCADE'),
nullable=False, primary_key=True)
class PermissionCollection(AbstractDataCollection):
@ -24,5 +24,5 @@ class PermissionCollection(AbstractDataCollection):
class PenguinPermissionCollection(AbstractDataCollection):
__model__ = PenguinPermission
__indexby__ = 'permission_id'
__indexby__ = 'permission_name'
__filterby__ = 'penguin_id'