diff --git a/barker/alembic/versions/34fe3d061c5f_finish_import.py b/barker/alembic/versions/34fe3d061c5f_finish_import.py index 4e901ee..293c870 100644 --- a/barker/alembic/versions/34fe3d061c5f_finish_import.py +++ b/barker/alembic/versions/34fe3d061c5f_finish_import.py @@ -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 ###