From 99194d79f3d9adf2069c03925f96b94f4a6b53b0 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 17 May 2020 03:22:47 +0100 Subject: [PATCH] Index permissions by name --- houdini.sql | 13 ++++++------- houdini/data/permission.py | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/houdini.sql b/houdini.sql index a3d8af1..c9203a1 100644 --- a/houdini.sql +++ b/houdini.sql @@ -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, diff --git a/houdini/data/permission.py b/houdini/data/permission.py index f31b837..521dffc 100644 --- a/houdini/data/permission.py +++ b/houdini/data/permission.py @@ -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'