aboutsummaryrefslogtreecommitdiff
path: root/migrations/auth/20240606_02_ubZri-create-resource-roles-table.py
blob: 0695c0e579ceddde26e1fbc39e0e84a1dc3dc7d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Create 'resource_roles' table.
"""

from yoyo import step

__depends__ = {'20240606_01_xQDwL-move-role-manipulation-privileges-from-group-to-resources'}

steps = [
    step(
        """
        CREATE TABLE IF NOT EXISTS resource_roles(
          resource_id TEXT NOT NULL,
          role_created_by TEXT NOT NULL,
          role_id TEXT NOT NULL,
          PRIMARY KEY (resource_id, role_created_by, role_id),
          FOREIGN KEY(resource_id) REFERENCES resources(resource_id)
            ON UPDATE CASCADE ON DELETE RESTRICT,
          FOREIGN KEY(role_created_by) REFERENCES users(user_id)
            ON UPDATE CASCADE ON DELETE RESTRICT,
          FOREIGN KEY(role_id) REFERENCES roles(role_id)
            ON UPDATE CASCADE ON DELETE RESTRICT
        ) WITHOUT ROWID
        """,
        "DROP TABLE IF EXISTS resource_roles"),
    step(
        """
        CREATE INDEX IF NOT EXISTS
        tbl_resource_roles_cols_resource_id_role_created_by
        ON resource_roles(resource_id, role_created_by)
        """,
        """
        DROP INDEX IF EXISTS
        tbl_resource_roles_cols_resource_id_role_created_by
        """)
]