|
| 1 | +"""controlled keyword modification |
| 2 | +
|
| 3 | +Revision ID: 0b29eefbe1dd |
| 4 | +Revises: 2b7a977e7e98 |
| 5 | +Create Date: 2025-08-07 15:45:43.241567 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = '0b29eefbe1dd' |
| 14 | +down_revision = '2b7a977e7e98' |
| 15 | +branch_labels = None |
| 16 | +depends_on = None |
| 17 | + |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + # ### commands auto generated by Alembic - please adjust! ### |
| 21 | + # Rename existing columns |
| 22 | + op.alter_column('controlled_keywords', 'value', new_column_name='label', existing_type=sa.String(), existing_nullable=False) |
| 23 | + op.alter_column('controlled_keywords', 'vocabulary', new_column_name='system', existing_type=sa.String(), existing_nullable=True) |
| 24 | + # Add new columns |
| 25 | + op.add_column('controlled_keywords', sa.Column('code', sa.String(), nullable=True)) |
| 26 | + op.add_column('controlled_keywords', sa.Column('version', sa.String(), nullable=True)) |
| 27 | + # Drop and recreate the correct unique constraint |
| 28 | + op.drop_constraint('ix_controlled_keywords_key_value', 'controlled_keywords', type_='unique') |
| 29 | + op.create_unique_constraint('ix_controlled_keywords_key_label', 'controlled_keywords', ['key', 'label']) |
| 30 | + # ### end Alembic commands ### |
| 31 | + |
| 32 | + # TODO: Will modify this part when we get the final GO terms. |
| 33 | + op.execute( |
| 34 | + """INSERT INTO controlled_keywords (key, label, system, code, version, special, description, creation_date, modification_date) VALUES ('Phenotypic Assay Mechanism', 'Other', NULL, NULL, NULL, False, 'The Gene Ontology (GO) is a structured, standardized representation of biological knowledge.', NOW(), NOW())""" |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | +def downgrade(): |
| 39 | + # ### commands auto generated by Alembic - please adjust! ### |
| 40 | + op.alter_column('controlled_keywords', 'label', new_column_name='value', existing_type=sa.String(), existing_nullable=False) |
| 41 | + op.alter_column('controlled_keywords', 'system', new_column_name='vocabulary', existing_type=sa.String(), existing_nullable=True) |
| 42 | + op.drop_constraint('ix_controlled_keywords_key_label', 'controlled_keywords', type_='unique') |
| 43 | + op.create_unique_constraint('ix_controlled_keywords_key_value', 'controlled_keywords', ['key', 'value']) |
| 44 | + op.drop_column('controlled_keywords', 'version') |
| 45 | + op.drop_column('controlled_keywords', 'code') |
| 46 | + # ### end Alembic commands ### |
0 commit comments