Skip to content

Commit

Permalink
fix pk
Browse files Browse the repository at this point in the history
  • Loading branch information
parfenovma committed Aug 30, 2024
1 parent 9665696 commit 6588404
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"""add_link_full_schema3
Revision ID: 11461790578a
Revises: da280c5f1dac
Create Date: 2024-08-30 19:02:34.621922
"""

from alembic import op
import sqlalchemy as sa
import os
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '11461790578a'
down_revision = 'da280c5f1dac'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.revoke_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.revoke_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.drop_table('new_with_dates', schema='STG_RASPHYSMSU')
op.drop_table('link_new_with_dates', schema='STG_RASPHYSMSU')


def downgrade():
op.create_table(
'link_new_with_dates',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('subject', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('start', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('end', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('odd', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('even', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('weekday', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('num', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('place', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=False),
sa.Column('group', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=False),
sa.Column('teacher', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=False),
sa.Column('events_id', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='link_new_with_dates_pkey'),
schema='STG_RASPHYSMSU',
)
op.create_table(
'new_with_dates',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('subject', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('odd', sa.BOOLEAN(), autoincrement=False, nullable=False),
sa.Column('even', sa.BOOLEAN(), autoincrement=False, nullable=False),
sa.Column('weekday', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('num', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('start', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('end', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('place', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=False),
sa.Column('group', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=False),
sa.Column('teacher', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=False),
sa.Column('events_id', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='new_with_dates_pkey'),
schema='STG_RASPHYSMSU',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.grant_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.grant_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".new_with_dates',
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
"""add_link_full_schema3
Revision ID: 0e97fd76b68a
Revises: 11461790578a
Create Date: 2024-08-30 19:04:02.502893
"""

from alembic import op
import sqlalchemy as sa
import os
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '0e97fd76b68a'
down_revision = '11461790578a'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'link_new_with_dates',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('subject', sa.String(), nullable=True),
sa.Column('odd', sa.Boolean(), nullable=True),
sa.Column('even', sa.Boolean(), nullable=True),
sa.Column('weekday', sa.Integer(), nullable=True),
sa.Column('num', sa.Integer(), nullable=True),
sa.Column('start', sa.String(), nullable=True),
sa.Column('end', sa.String(), nullable=True),
sa.Column('place', sa.ARRAY(sa.Integer()), nullable=False),
sa.Column('group', sa.ARRAY(sa.Integer()), nullable=False),
sa.Column('teacher', sa.ARRAY(sa.Integer()), nullable=False),
sa.Column('events_id', sa.ARRAY(sa.Integer()), nullable=True),
schema='STG_RASPHYSMSU',
)
op.create_table(
'new_with_dates',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('subject', sa.String(), nullable=False),
sa.Column('odd', sa.Boolean(), nullable=False),
sa.Column('even', sa.Boolean(), nullable=False),
sa.Column('weekday', sa.Integer(), nullable=True),
sa.Column('num', sa.Integer(), nullable=True),
sa.Column('start', sa.String(), nullable=False),
sa.Column('end', sa.String(), nullable=False),
sa.Column('place', sa.ARRAY(sa.Integer()), nullable=False),
sa.Column('group', sa.ARRAY(sa.Integer()), nullable=False),
sa.Column('teacher', sa.ARRAY(sa.Integer()), nullable=False),
sa.Column('events_id', sa.ARRAY(sa.Integer()), nullable=True),
schema='STG_RASPHYSMSU',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.grant_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.grant_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.grant_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".new_with_dates',
)


def downgrade():
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.revoke_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".new_with_dates',
)
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_all",
['ALL'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.revoke_on_table(
(
"test_dwh_stg_rasphysmsu_write"
if os.getenv("ENVIRONMENT") != "production"
else "prod_dwh_stg_rasphysmsu_write"
),
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.revoke_on_table(
"test_dwh_stg_rasphysmsu_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_rasphysmsu_read",
['SELECT'],
'"STG_RASPHYSMSU".link_new_with_dates',
)
op.drop_table('new_with_dates', schema='STG_RASPHYSMSU')
op.drop_table('link_new_with_dates', schema='STG_RASPHYSMSU')
10 changes: 8 additions & 2 deletions profcomff_definitions/STG/rasphysmsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class New(Base):
events_id: Mapped[tp.List[int] | None] = mapped_column(ARRAY(Integer))

class LinkNewWithDates(Base):
id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[int]
subject: Mapped[str | None]
odd: Mapped[bool | None]
even: Mapped[bool | None]
Expand All @@ -74,10 +74,13 @@ class LinkNewWithDates(Base):
group: Mapped[tp.List[int]] = mapped_column(ARRAY(Integer))
teacher: Mapped[tp.List[int]] = mapped_column(ARRAY(Integer))
events_id: Mapped[tp.List[int] | None] = mapped_column(ARRAY(Integer))
__mapper_args__ = {
"primary_key": ["id", "start", "end"]
} # Used only to correctly map ORM object to sql table


class NewWithDates(Base):
id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[int]
subject: Mapped[str]
odd: Mapped[bool]
even: Mapped[bool]
Expand All @@ -89,3 +92,6 @@ class NewWithDates(Base):
group: Mapped[tp.List[int]] = mapped_column(ARRAY(Integer))
teacher: Mapped[tp.List[int]] = mapped_column(ARRAY(Integer))
events_id: Mapped[tp.List[int] | None] = mapped_column(ARRAY(Integer))
__mapper_args__ = {
"primary_key": ["id", "start", "end"]
} # Used only to correctly map ORM object to sql table

0 comments on commit 6588404

Please sign in to comment.