|
| 1 | +"""Fixing inconsistencies |
| 2 | +
|
| 3 | +Revision ID: 4aa1f48c6321 |
| 4 | +Revises: 3389c67fdcb4 |
| 5 | +Create Date: 2025-07-03 16:46:13.642386 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | +import sqlmodel.sql.sqltypes |
| 11 | +from sqlalchemy.dialects import postgresql |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision = "4aa1f48c6321" |
| 15 | +down_revision = "f2589428c1d0" |
| 16 | +branch_labels = None |
| 17 | +depends_on = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade(): |
| 21 | + op.alter_column( |
| 22 | + "collection", "project_id", existing_type=sa.INTEGER(), nullable=False |
| 23 | + ) |
| 24 | + op.alter_column( |
| 25 | + "credential", |
| 26 | + "inserted_at", |
| 27 | + existing_type=postgresql.TIMESTAMP(), |
| 28 | + nullable=False, |
| 29 | + ) |
| 30 | + op.alter_column( |
| 31 | + "credential", "updated_at", existing_type=postgresql.TIMESTAMP(), nullable=False |
| 32 | + ) |
| 33 | + op.alter_column( |
| 34 | + "credential", "project_id", existing_type=sa.INTEGER(), nullable=False |
| 35 | + ) |
| 36 | + op.create_index( |
| 37 | + op.f("ix_openai_assistant_assistant_id"), |
| 38 | + "openai_assistant", |
| 39 | + ["assistant_id"], |
| 40 | + unique=True, |
| 41 | + ) |
| 42 | + op.drop_constraint("project_organization_id_fkey", "project", type_="foreignkey") |
| 43 | + op.create_foreign_key( |
| 44 | + None, "project", "organization", ["organization_id"], ["id"], ondelete="CASCADE" |
| 45 | + ) |
| 46 | + op.drop_constraint("credential_project_id_fkey", "credential", type_="foreignkey") |
| 47 | + op.create_foreign_key( |
| 48 | + None, "credential", "project", ["project_id"], ["id"], ondelete="CASCADE" |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +def downgrade(): |
| 53 | + op.drop_constraint(None, "project", type_="foreignkey") |
| 54 | + op.create_foreign_key( |
| 55 | + "project_organization_id_fkey", |
| 56 | + "project", |
| 57 | + "organization", |
| 58 | + ["organization_id"], |
| 59 | + ["id"], |
| 60 | + ) |
| 61 | + op.drop_index( |
| 62 | + op.f("ix_openai_assistant_assistant_id"), table_name="openai_assistant" |
| 63 | + ) |
| 64 | + op.drop_constraint(None, "credential", type_="foreignkey") |
| 65 | + op.create_foreign_key( |
| 66 | + "credential_project_id_fkey", |
| 67 | + "credential", |
| 68 | + "project", |
| 69 | + ["project_id"], |
| 70 | + ["id"], |
| 71 | + ondelete="SET NULL", |
| 72 | + ) |
| 73 | + op.alter_column( |
| 74 | + "credential", "updated_at", existing_type=postgresql.TIMESTAMP(), nullable=True |
| 75 | + ) |
| 76 | + op.alter_column( |
| 77 | + "credential", "inserted_at", existing_type=postgresql.TIMESTAMP(), nullable=True |
| 78 | + ) |
| 79 | + op.alter_column( |
| 80 | + "collection", "project_id", existing_type=sa.INTEGER(), nullable=True |
| 81 | + ) |
| 82 | + op.alter_column( |
| 83 | + "credential", "project_id", existing_type=sa.INTEGER(), nullable=True |
| 84 | + ) |
0 commit comments