965b56353b4c_initial_migration.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. """initial migration
  2. Revision ID: 965b56353b4c
  3. Revises:
  4. Create Date: 2025-05-19 14:35:04.755433
  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 = '965b56353b4c'
  12. down_revision: Union[str, None] = None
  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('profiles',
  19. sa.Column('id', sa.UUID(), nullable=False),
  20. sa.Column('first_name', sa.Text(), nullable=True),
  21. sa.Column('last_name', sa.Text(), nullable=True),
  22. sa.Column('avatar_url', sa.Text(), nullable=True),
  23. sa.PrimaryKeyConstraint('id')
  24. )
  25. op.create_table('transforms',
  26. sa.Column('id', sa.UUID(), nullable=False),
  27. sa.Column('name', sa.Text(), nullable=False),
  28. sa.Column('description', sa.Text(), nullable=True),
  29. sa.Column('category', postgresql.ARRAY(sa.Text()), nullable=True),
  30. sa.Column('transform_schema', sa.JSON(), nullable=True),
  31. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  32. sa.Column('last_updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  33. sa.PrimaryKeyConstraint('id')
  34. )
  35. op.create_table('feedbacks',
  36. sa.Column('id', sa.Uuid(), nullable=False),
  37. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  38. sa.Column('content', sa.Text(), nullable=True),
  39. sa.Column('owner_id', sa.UUID(), nullable=True),
  40. sa.ForeignKeyConstraint(['owner_id'], ['profiles.id'], ),
  41. sa.PrimaryKeyConstraint('id')
  42. )
  43. op.create_table('investigations',
  44. sa.Column('id', sa.UUID(), nullable=False),
  45. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  46. sa.Column('name', sa.Text(), nullable=True),
  47. sa.Column('description', sa.Text(), nullable=True),
  48. sa.Column('owner_id', sa.UUID(), nullable=True),
  49. sa.Column('last_updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  50. sa.Column('status', sa.String(), server_default='active', nullable=True),
  51. sa.ForeignKeyConstraint(['owner_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
  52. sa.PrimaryKeyConstraint('id')
  53. )
  54. op.create_index('idx_investigations_id', 'investigations', ['id'], unique=False)
  55. op.create_index('idx_investigations_owner_id', 'investigations', ['owner_id'], unique=False)
  56. op.create_table('investigations_profiles',
  57. sa.Column('id', sa.Uuid(), nullable=False),
  58. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  59. sa.Column('investigation_id', sa.UUID(), nullable=True),
  60. sa.Column('profile_id', sa.UUID(), nullable=True),
  61. sa.Column('role', sa.String(), server_default='member', nullable=True),
  62. sa.ForeignKeyConstraint(['investigation_id'], ['investigations.id'], onupdate='CASCADE', ondelete='CASCADE'),
  63. sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
  64. sa.PrimaryKeyConstraint('id')
  65. )
  66. op.create_index('idx_investigations_profiles_investigation_id', 'investigations_profiles', ['investigation_id'], unique=False)
  67. op.create_index('idx_investigations_profiles_profile_id', 'investigations_profiles', ['profile_id'], unique=False)
  68. op.create_index('projects_profiles_unique_profile_project', 'investigations_profiles', ['profile_id', 'investigation_id'], unique=True)
  69. op.create_table('sketches',
  70. sa.Column('id', sa.UUID(), nullable=False),
  71. sa.Column('title', sa.Text(), nullable=True),
  72. sa.Column('description', sa.Text(), nullable=True),
  73. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  74. sa.Column('owner_id', sa.UUID(), nullable=True),
  75. sa.Column('status', sa.String(), server_default='active', nullable=True),
  76. sa.Column('investigation_id', sa.UUID(), nullable=True),
  77. sa.Column('last_updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  78. sa.ForeignKeyConstraint(['investigation_id'], ['investigations.id'], onupdate='CASCADE', ondelete='CASCADE'),
  79. sa.ForeignKeyConstraint(['owner_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
  80. sa.PrimaryKeyConstraint('id')
  81. )
  82. op.create_index('idx_sketches_investigation_id', 'sketches', ['investigation_id'], unique=False)
  83. op.create_index('idx_sketches_owner_id', 'sketches', ['owner_id'], unique=False)
  84. op.create_table('scans',
  85. sa.Column('id', sa.UUID(), nullable=False),
  86. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  87. sa.Column('status', sa.String(), nullable=True),
  88. sa.Column('results', sa.JSON(), nullable=True),
  89. sa.Column('values', postgresql.ARRAY(sa.Text()), nullable=True),
  90. sa.Column('sketch_id', sa.UUID(), nullable=True),
  91. sa.ForeignKeyConstraint(['sketch_id'], ['sketches.id'], onupdate='CASCADE', ondelete='CASCADE'),
  92. sa.PrimaryKeyConstraint('id')
  93. )
  94. op.create_index('idx_scans_sketch_id', 'scans', ['sketch_id'], unique=False)
  95. op.create_table('sketches_profiles',
  96. sa.Column('id', sa.Uuid(), nullable=False),
  97. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  98. sa.Column('profile_id', sa.UUID(), nullable=True),
  99. sa.Column('sketch_id', sa.UUID(), nullable=True),
  100. sa.Column('role', sa.String(), server_default='editor', nullable=True),
  101. sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
  102. sa.ForeignKeyConstraint(['sketch_id'], ['sketches.id'], onupdate='CASCADE', ondelete='CASCADE'),
  103. sa.PrimaryKeyConstraint('id')
  104. )
  105. op.create_index('idx_sketches_profiles_profile_id', 'sketches_profiles', ['profile_id'], unique=False)
  106. op.create_index('idx_sketches_profiles_sketch_id', 'sketches_profiles', ['sketch_id'], unique=False)
  107. op.create_index('investigations_profiles_unique_profile_investigation', 'sketches_profiles', ['profile_id', 'sketch_id'], unique=True)
  108. op.create_table('logs',
  109. sa.Column('id', sa.UUID(), nullable=False),
  110. sa.Column('scan_id', sa.UUID(), nullable=True),
  111. sa.Column('content', sa.Text(), nullable=True),
  112. sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
  113. sa.Column('sketch_id', sa.UUID(), nullable=True),
  114. sa.Column('type', sa.String(), server_default='INFO', nullable=True),
  115. sa.ForeignKeyConstraint(['scan_id'], ['scans.id'], ondelete='CASCADE'),
  116. sa.ForeignKeyConstraint(['sketch_id'], ['sketches.id'], onupdate='CASCADE', ondelete='CASCADE'),
  117. sa.PrimaryKeyConstraint('id')
  118. )
  119. # ### end Alembic commands ###
  120. def downgrade() -> None:
  121. """Downgrade schema."""
  122. # ### commands auto generated by Alembic - please adjust! ###
  123. op.drop_table('logs')
  124. op.drop_index('investigations_profiles_unique_profile_investigation', table_name='sketches_profiles')
  125. op.drop_index('idx_sketches_profiles_sketch_id', table_name='sketches_profiles')
  126. op.drop_index('idx_sketches_profiles_profile_id', table_name='sketches_profiles')
  127. op.drop_table('sketches_profiles')
  128. op.drop_index('idx_scans_sketch_id', table_name='scans')
  129. op.drop_table('scans')
  130. op.drop_index('idx_sketches_owner_id', table_name='sketches')
  131. op.drop_index('idx_sketches_investigation_id', table_name='sketches')
  132. op.drop_table('sketches')
  133. op.drop_index('projects_profiles_unique_profile_project', table_name='investigations_profiles')
  134. op.drop_index('idx_investigations_profiles_profile_id', table_name='investigations_profiles')
  135. op.drop_index('idx_investigations_profiles_investigation_id', table_name='investigations_profiles')
  136. op.drop_table('investigations_profiles')
  137. op.drop_index('idx_investigations_owner_id', table_name='investigations')
  138. op.drop_index('idx_investigations_id', table_name='investigations')
  139. op.drop_table('investigations')
  140. op.drop_table('feedbacks')
  141. op.drop_table('transforms')
  142. op.drop_table('profiles')
  143. # ### end Alembic commands ###