Import data also adds all permissions to owner role

This commit is contained in:
Amritanshu Agrawal 2020-11-08 20:01:27 +05:30
parent 94b63e4385
commit 4aaa3fc72b
1 changed files with 28 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from alembic import op
# revision identifiers, used by Alembic.
from sqlalchemy import column, func, select, table, text
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import insert as pg_insert
revision = "34fe3d061c5f"
@ -100,8 +101,8 @@ def upgrade():
prod = table(
"product_histories",
column("id", postgresql.UUID(as_uuid=True)),
column("name", postgresql.UUID(as_uuid=True)),
column("units", postgresql.UUID(as_uuid=True)),
column("name", sa.Unicode(length=255)),
column("units", sa.Unicode(length=255)),
column("valid_from", sa.Date()),
column("valid_till", sa.Date()),
)
@ -133,6 +134,31 @@ def upgrade():
(func.daterange(prod.c.valid_from, prod.c.valid_till, text("'[]'")), "&&"),
)
op.drop_constraint("uq_products_name", "product_histories", type_="unique")
r = table(
"roles",
column("id", postgresql.UUID(as_uuid=True)),
column("name", sa.Unicode(length=255)),
)
p = table(
"permissions",
column("id", postgresql.UUID(as_uuid=True)),
column("name", sa.Unicode(length=255)),
)
rp = table(
"role_permissions",
column("id", postgresql.UUID(as_uuid=True)),
column("permission_id", postgresql.UUID(as_uuid=True)),
column("role_id", postgresql.UUID(as_uuid=True)),
)
op.execute(
pg_insert(rp)
.from_select(
[rp.c.role_id, rp.c.permission_id],
select([select([func.distinct(r.c.id)]).where(r.c.name.ilike("Owner")).as_scalar(), p.c.id]),
)
.on_conflict_do_nothing(),
)
# ### end Alembic commands ###