Import data also adds all permissions to owner role
This commit is contained in:
parent
94b63e4385
commit
4aaa3fc72b
@ -12,6 +12,7 @@ from alembic import op
|
|||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
from sqlalchemy import column, func, select, table, text
|
from sqlalchemy import column, func, select, table, text
|
||||||
from sqlalchemy.dialects import postgresql
|
from sqlalchemy.dialects import postgresql
|
||||||
|
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||||
|
|
||||||
|
|
||||||
revision = "34fe3d061c5f"
|
revision = "34fe3d061c5f"
|
||||||
@ -100,8 +101,8 @@ def upgrade():
|
|||||||
prod = table(
|
prod = table(
|
||||||
"product_histories",
|
"product_histories",
|
||||||
column("id", postgresql.UUID(as_uuid=True)),
|
column("id", postgresql.UUID(as_uuid=True)),
|
||||||
column("name", postgresql.UUID(as_uuid=True)),
|
column("name", sa.Unicode(length=255)),
|
||||||
column("units", postgresql.UUID(as_uuid=True)),
|
column("units", sa.Unicode(length=255)),
|
||||||
column("valid_from", sa.Date()),
|
column("valid_from", sa.Date()),
|
||||||
column("valid_till", sa.Date()),
|
column("valid_till", sa.Date()),
|
||||||
)
|
)
|
||||||
@ -133,6 +134,31 @@ def upgrade():
|
|||||||
(func.daterange(prod.c.valid_from, prod.c.valid_till, text("'[]'")), "&&"),
|
(func.daterange(prod.c.valid_from, prod.c.valid_till, text("'[]'")), "&&"),
|
||||||
)
|
)
|
||||||
op.drop_constraint("uq_products_name", "product_histories", type_="unique")
|
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 ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user