|
| 1 | +"""Populate electrical_cell_recording ids. |
| 2 | +
|
| 3 | +Revision ID: 06af11530839 |
| 4 | +Revises: de87a4c88ded |
| 5 | +Create Date: 2025-09-12 17:20:25.828230 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +from typing import Sequence, Union |
| 10 | + |
| 11 | +from alembic import op |
| 12 | +import sqlalchemy as sa |
| 13 | +from alembic_postgresql_enum import TableReference |
| 14 | + |
| 15 | +from sqlalchemy import Text |
| 16 | +import app.db.types |
| 17 | + |
| 18 | +# revision identifiers, used by Alembic. |
| 19 | +revision: str = "06af11530839" |
| 20 | +down_revision: Union[str, None] = "de87a4c88ded" |
| 21 | +branch_labels: Union[str, Sequence[str], None] = None |
| 22 | +depends_on: Union[str, Sequence[str], None] = None |
| 23 | + |
| 24 | + |
| 25 | +def upgrade() -> None: |
| 26 | + # add missing records into electrical_cell_recording |
| 27 | + # caused by migrations d58bc70ec10f and b352b28dae67 |
| 28 | + op.execute( |
| 29 | + """ |
| 30 | + INSERT INTO electrical_cell_recording (id) |
| 31 | + SELECT e.id |
| 32 | + FROM entity e |
| 33 | + JOIN electrical_recording er ON e.id = er.id |
| 34 | + WHERE e.type = 'electrical_cell_recording' |
| 35 | + ON CONFLICT (id) DO NOTHING |
| 36 | + """ |
| 37 | + ) |
| 38 | + # remove mesh type |
| 39 | + op.sync_enum_values( |
| 40 | + enum_schema="public", |
| 41 | + enum_name="entitytype", |
| 42 | + new_values=[ |
| 43 | + "analysis_software_source_code", |
| 44 | + "brain_atlas", |
| 45 | + "brain_atlas_region", |
| 46 | + "cell_composition", |
| 47 | + "electrical_cell_recording", |
| 48 | + "electrical_recording", |
| 49 | + "electrical_recording_stimulus", |
| 50 | + "emodel", |
| 51 | + "experimental_bouton_density", |
| 52 | + "experimental_neuron_density", |
| 53 | + "experimental_synapses_per_connection", |
| 54 | + "external_url", |
| 55 | + "ion_channel", |
| 56 | + "ion_channel_model", |
| 57 | + "ion_channel_recording", |
| 58 | + "memodel", |
| 59 | + "memodel_calibration_result", |
| 60 | + "me_type_density", |
| 61 | + "reconstruction_morphology", |
| 62 | + "simulation", |
| 63 | + "simulation_campaign", |
| 64 | + "simulation_campaign_generation", |
| 65 | + "simulation_execution", |
| 66 | + "simulation_result", |
| 67 | + "scientific_artifact", |
| 68 | + "single_neuron_simulation", |
| 69 | + "single_neuron_synaptome", |
| 70 | + "single_neuron_synaptome_simulation", |
| 71 | + "subject", |
| 72 | + "validation_result", |
| 73 | + "circuit", |
| 74 | + "em_dense_reconstruction_dataset", |
| 75 | + "em_cell_mesh", |
| 76 | + ], |
| 77 | + affected_columns=[ |
| 78 | + TableReference(table_schema="public", table_name="entity", column_name="type") |
| 79 | + ], |
| 80 | + enum_values_to_rename=[], |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +def downgrade() -> None: |
| 85 | + # restore mesh type |
| 86 | + op.sync_enum_values( |
| 87 | + enum_schema="public", |
| 88 | + enum_name="entitytype", |
| 89 | + new_values=[ |
| 90 | + "analysis_software_source_code", |
| 91 | + "brain_atlas", |
| 92 | + "brain_atlas_region", |
| 93 | + "cell_composition", |
| 94 | + "electrical_cell_recording", |
| 95 | + "electrical_recording", |
| 96 | + "electrical_recording_stimulus", |
| 97 | + "emodel", |
| 98 | + "experimental_bouton_density", |
| 99 | + "experimental_neuron_density", |
| 100 | + "experimental_synapses_per_connection", |
| 101 | + "external_url", |
| 102 | + "ion_channel", |
| 103 | + "ion_channel_model", |
| 104 | + "ion_channel_recording", |
| 105 | + "memodel", |
| 106 | + "mesh", |
| 107 | + "memodel_calibration_result", |
| 108 | + "me_type_density", |
| 109 | + "reconstruction_morphology", |
| 110 | + "simulation", |
| 111 | + "simulation_campaign", |
| 112 | + "simulation_campaign_generation", |
| 113 | + "simulation_execution", |
| 114 | + "simulation_result", |
| 115 | + "scientific_artifact", |
| 116 | + "single_neuron_simulation", |
| 117 | + "single_neuron_synaptome", |
| 118 | + "single_neuron_synaptome_simulation", |
| 119 | + "subject", |
| 120 | + "validation_result", |
| 121 | + "circuit", |
| 122 | + "em_dense_reconstruction_dataset", |
| 123 | + "em_cell_mesh", |
| 124 | + ], |
| 125 | + affected_columns=[ |
| 126 | + TableReference(table_schema="public", table_name="entity", column_name="type") |
| 127 | + ], |
| 128 | + enum_values_to_rename=[], |
| 129 | + ) |
0 commit comments