6e49acfb3816_add_investigation_roles_permissions.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """add investigation roles permissions
  2. Revision ID: 6e49acfb3816
  3. Revises: 1098b7a5eabc
  4. Create Date: 2025-09-17 21:46:14.314402
  5. """
  6. from typing import Sequence, Union
  7. from alembic import op
  8. import sqlalchemy as sa
  9. from sqlalchemy.dialects import postgresql
  10. # revision identifiers, used by Alembic.
  11. revision: str = '6e49acfb3816'
  12. down_revision: Union[str, None] = '1098b7a5eabc'
  13. branch_labels: Union[str, Sequence[str], None] = None
  14. depends_on: Union[str, Sequence[str], None] = None
  15. def upgrade() -> None:
  16. """Upgrade schema."""
  17. # ### commands auto generated by Alembic - please adjust! ###
  18. op.create_table('investigation_user_roles',
  19. sa.Column('id', sa.UUID(), nullable=False),
  20. sa.Column('user_id', sa.UUID(), nullable=False),
  21. sa.Column('investigation_id', sa.UUID(), nullable=False),
  22. sa.Column('role', sa.Enum('OWNER', 'EDITOR', 'VIEWER', name='role_enum', create_constraint=True), nullable=False),
  23. sa.ForeignKeyConstraint(['investigation_id'], ['investigations.id'], onupdate='CASCADE', ondelete='CASCADE'),
  24. sa.ForeignKeyConstraint(['user_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
  25. sa.PrimaryKeyConstraint('id'),
  26. sa.UniqueConstraint('user_id', 'investigation_id', name='uq_user_investigation')
  27. )
  28. op.create_index('idx_investigation_roles_investigation_id', 'investigation_user_roles', ['investigation_id'], unique=False)
  29. op.create_index('idx_investigation_roles_user_id', 'investigation_user_roles', ['user_id'], unique=False)
  30. op.drop_index('idx_investigations_profiles_investigation_id', table_name='investigations_profiles')
  31. op.drop_index('idx_investigations_profiles_profile_id', table_name='investigations_profiles')
  32. op.drop_index('projects_profiles_unique_profile_project', table_name='investigations_profiles')
  33. op.drop_table('investigations_profiles')
  34. # ### end Alembic commands ###
  35. def downgrade() -> None:
  36. """Downgrade schema."""
  37. # ### commands auto generated by Alembic - please adjust! ###
  38. op.create_table('investigations_profiles',
  39. sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
  40. sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=True),
  41. sa.Column('investigation_id', sa.UUID(), autoincrement=False, nullable=True),
  42. sa.Column('profile_id', sa.UUID(), autoincrement=False, nullable=True),
  43. sa.Column('role', sa.VARCHAR(), server_default=sa.text("'member'::character varying"), autoincrement=False, nullable=True),
  44. sa.ForeignKeyConstraint(['investigation_id'], ['investigations.id'], name='investigations_profiles_investigation_id_fkey', onupdate='CASCADE', ondelete='CASCADE'),
  45. sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], name='investigations_profiles_profile_id_fkey', onupdate='CASCADE', ondelete='CASCADE'),
  46. sa.PrimaryKeyConstraint('id', name='investigations_profiles_pkey')
  47. )
  48. op.create_index('projects_profiles_unique_profile_project', 'investigations_profiles', ['profile_id', 'investigation_id'], unique=False)
  49. op.create_index('idx_investigations_profiles_profile_id', 'investigations_profiles', ['profile_id'], unique=False)
  50. op.create_index('idx_investigations_profiles_investigation_id', 'investigations_profiles', ['investigation_id'], unique=False)
  51. op.drop_index('idx_investigation_roles_user_id', table_name='investigation_user_roles')
  52. op.drop_index('idx_investigation_roles_investigation_id', table_name='investigation_user_roles')
  53. op.drop_table('investigation_user_roles')
  54. # ### end Alembic commands ###