|
| 1 | +"""Add release version models |
| 2 | +
|
| 3 | +Revision ID: a33ed87f86ff |
| 4 | +Revises: 0c0dd1a8925c |
| 5 | +Create Date: 2026-04-07 18:23:02.276428 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = "a33ed87f86ff" |
| 14 | +down_revision = "0c0dd1a8925c" |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # 1. Add the Virtual Table |
| 21 | + op.execute( |
| 22 | + """ |
| 23 | + CREATE VIRTUAL TABLE IF NOT EXISTS release_file_search_index USING fts5( |
| 24 | + file_id, |
| 25 | + file_name, |
| 26 | + file_description, |
| 27 | + file_datatype, |
| 28 | + release_version_name, |
| 29 | + release_name, |
| 30 | + release_version_description, |
| 31 | + release_version_content_hash, |
| 32 | + tokenize='unicode61' |
| 33 | + ); |
| 34 | + """ |
| 35 | + ) |
| 36 | + # ### commands auto generated by Alembic - please adjust! ### |
| 37 | + op.create_table( |
| 38 | + "release_version", |
| 39 | + sa.Column("version_name", sa.String(), nullable=False), |
| 40 | + sa.Column("version_date", sa.Date(), nullable=False), |
| 41 | + sa.Column("description", sa.String(), nullable=True), |
| 42 | + sa.Column("content_hash", sa.String(length=32), nullable=False), |
| 43 | + sa.Column("release_name", sa.String(), nullable=False), |
| 44 | + sa.Column("citation", sa.String(), nullable=True), |
| 45 | + sa.Column("funding", sa.String(), nullable=True), |
| 46 | + sa.Column("terms", sa.String(), nullable=True), |
| 47 | + sa.Column("id", sa.String(length=36), nullable=False), |
| 48 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_release_version")), |
| 49 | + sa.UniqueConstraint( |
| 50 | + "version_name", "release_name", name=op.f("uq_release_version_version_name") |
| 51 | + ), |
| 52 | + ) |
| 53 | + with op.batch_alter_table("release_version", schema=None) as batch_op: |
| 54 | + batch_op.create_index( |
| 55 | + batch_op.f("ix_release_version_content_hash"), |
| 56 | + ["content_hash"], |
| 57 | + unique=False, |
| 58 | + ) |
| 59 | + batch_op.create_index( |
| 60 | + batch_op.f("ix_release_version_release_name"), |
| 61 | + ["release_name"], |
| 62 | + unique=False, |
| 63 | + ) |
| 64 | + batch_op.create_index( |
| 65 | + batch_op.f("ix_release_version_version_name"), |
| 66 | + ["version_name"], |
| 67 | + unique=False, |
| 68 | + ) |
| 69 | + |
| 70 | + op.create_table( |
| 71 | + "release_file", |
| 72 | + sa.Column("release_version_id", sa.String(), nullable=False), |
| 73 | + sa.Column("file_name", sa.String(), nullable=False), |
| 74 | + sa.Column("datatype", sa.String(), nullable=False), |
| 75 | + sa.Column("size", sa.String(), nullable=True), |
| 76 | + sa.Column("description", sa.String(), nullable=True), |
| 77 | + sa.Column("bucket_url", sa.String(), nullable=True), |
| 78 | + sa.Column("taiga_id", sa.String(), nullable=True), |
| 79 | + sa.Column("canonical_taiga_id", sa.String(), nullable=True), |
| 80 | + sa.Column("md5_hash", sa.String(length=32), nullable=True), |
| 81 | + sa.Column("version", sa.Integer(), nullable=True), |
| 82 | + sa.Column("pipeline_name", sa.String(), nullable=True), |
| 83 | + sa.Column("is_main_file", sa.Boolean(), nullable=False), |
| 84 | + sa.Column("id", sa.String(length=36), nullable=False), |
| 85 | + sa.ForeignKeyConstraint( |
| 86 | + ["release_version_id"], |
| 87 | + ["release_version.id"], |
| 88 | + name=op.f("fk_release_file_release_version_id_release_version"), |
| 89 | + ondelete="CASCADE", |
| 90 | + ), |
| 91 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_release_file")), |
| 92 | + ) |
| 93 | + with op.batch_alter_table("release_file", schema=None) as batch_op: |
| 94 | + batch_op.create_index( |
| 95 | + batch_op.f("ix_release_file_file_name"), ["file_name"], unique=False |
| 96 | + ) |
| 97 | + |
| 98 | + op.create_table( |
| 99 | + "release_pipeline", |
| 100 | + sa.Column("release_version_id", sa.String(), nullable=False), |
| 101 | + sa.Column("pipeline_name", sa.String(), nullable=False), |
| 102 | + sa.Column("description", sa.String(), nullable=True), |
| 103 | + sa.Column("id", sa.String(length=36), nullable=False), |
| 104 | + sa.ForeignKeyConstraint( |
| 105 | + ["release_version_id"], |
| 106 | + ["release_version.id"], |
| 107 | + name=op.f("fk_release_pipeline_release_version_id_release_version"), |
| 108 | + ondelete="CASCADE", |
| 109 | + ), |
| 110 | + sa.PrimaryKeyConstraint("id", name=op.f("pk_release_pipeline")), |
| 111 | + ) |
| 112 | + # ### end Alembic commands ### |
| 113 | + |
| 114 | + |
| 115 | +def downgrade(): |
| 116 | + # ### commands auto generated by Alembic - please adjust! ### |
| 117 | + op.drop_table("release_pipeline") |
| 118 | + with op.batch_alter_table("release_file", schema=None) as batch_op: |
| 119 | + batch_op.drop_index(batch_op.f("ix_release_file_file_name")) |
| 120 | + |
| 121 | + op.drop_table("release_file") |
| 122 | + with op.batch_alter_table("release_version", schema=None) as batch_op: |
| 123 | + batch_op.drop_index(batch_op.f("ix_release_version_version_name")) |
| 124 | + batch_op.drop_index(batch_op.f("ix_release_version_release_name")) |
| 125 | + batch_op.drop_index(batch_op.f("ix_release_version_content_hash")) |
| 126 | + |
| 127 | + op.drop_table("release_version") |
| 128 | + op.execute("DROP TABLE IF EXISTS release_file_search_index") |
| 129 | + # ### end Alembic commands ### |
0 commit comments