sprint14-19: ABAC UI rule editor + permission templates + bulk share + analytics + delegation + resolution strategies + migrations 0056-0058
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Create permission_templates table.
|
||||
|
||||
Revision ID: 0056
|
||||
Revises: 0055
|
||||
Create Date: 2026-07-29
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import JSONB, UUID as PGUUID
|
||||
|
||||
revision = "0056"
|
||||
down_revision = "0055"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"permission_templates",
|
||||
sa.Column("id", PGUUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("name", sa.String(200), nullable=False),
|
||||
sa.Column("entity_type", sa.String(50), nullable=False),
|
||||
sa.Column("trigger_condition", JSONB, nullable=True),
|
||||
sa.Column("auto_share_with", JSONB, nullable=True),
|
||||
sa.Column("level", sa.String(20), nullable=False, server_default=sa.text("'read'")),
|
||||
sa.Column("tenant_id", PGUUID(as_uuid=True), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.CheckConstraint(
|
||||
"level IN ('read', 'write', 'admin', 'delete')",
|
||||
name="ck_pt_level",
|
||||
),
|
||||
)
|
||||
op.create_index("ix_pt_entity_type", "permission_templates", ["entity_type"])
|
||||
op.create_index("ix_pt_tenant", "permission_templates", ["tenant_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_pt_tenant", table_name="permission_templates")
|
||||
op.drop_index("ix_pt_entity_type", table_name="permission_templates")
|
||||
op.drop_table("permission_templates")
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Create permission_delegations table.
|
||||
|
||||
Revision ID: 0057
|
||||
Revises: 0056
|
||||
Create Date: 2026-07-29
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import JSONB, UUID as PGUUID
|
||||
|
||||
revision = "0057"
|
||||
down_revision = "0056"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"permission_delegations",
|
||||
sa.Column("id", PGUUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("from_user_id", PGUUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("to_user_id", PGUUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("start_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("end_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("scope", JSONB, nullable=True),
|
||||
sa.Column("active", sa.Boolean, nullable=False, server_default=sa.text("true")),
|
||||
sa.Column("tenant_id", PGUUID(as_uuid=True), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.CheckConstraint(
|
||||
"end_at > start_at",
|
||||
name="ck_pd_end_after_start",
|
||||
),
|
||||
)
|
||||
op.create_index("ix_pd_from_user", "permission_delegations", ["from_user_id"])
|
||||
op.create_index("ix_pd_to_user", "permission_delegations", ["to_user_id"])
|
||||
op.create_index("ix_pd_tenant", "permission_delegations", ["tenant_id"])
|
||||
op.create_index("ix_pd_active", "permission_delegations", ["active"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_pd_active", table_name="permission_delegations")
|
||||
op.drop_index("ix_pd_tenant", table_name="permission_delegations")
|
||||
op.drop_index("ix_pd_to_user", table_name="permission_delegations")
|
||||
op.drop_index("ix_pd_from_user", table_name="permission_delegations")
|
||||
op.drop_table("permission_delegations")
|
||||
@@ -0,0 +1,39 @@
|
||||
"""Add resolution_strategy field to tenants table.
|
||||
|
||||
Revision ID: 0058
|
||||
Revises: 0057
|
||||
Create Date: 2026-07-29
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "0058"
|
||||
down_revision = "0057"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"tenants",
|
||||
sa.Column(
|
||||
"resolution_strategy",
|
||||
sa.String(30),
|
||||
nullable=False,
|
||||
server_default=sa.text("'highest_wins'"),
|
||||
),
|
||||
)
|
||||
op.create_check_constraint(
|
||||
"ck_tenant_resolution_strategy",
|
||||
"tenants",
|
||||
sa.schema.CheckConstraint(
|
||||
"resolution_strategy IN ('highest_wins', 'deny_overrides_allow', 'direct_overrides_group', 'most_restrictive_wins')",
|
||||
name="ck_tenant_resolution_strategy",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_constraint("ck_tenant_resolution_strategy", "tenants")
|
||||
op.drop_column("tenants", "resolution_strategy")
|
||||
Reference in New Issue
Block a user