Skip to content

Commit 0a6018f

Browse files
Add IonChannel and IonChannelRecording (#305)
1 parent 2521354 commit 0a6018f

23 files changed

+1853
-34
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Rename table electrical_cell_recording to electrical_recording
2+
3+
Revision ID: d58bc70ec10f
4+
Revises: 9df9950d73a0
5+
Create Date: 2025-09-10 14:51:21.492590
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+
from sqlalchemy.dialects import postgresql
15+
16+
from sqlalchemy import Text
17+
import app.db.types
18+
19+
# revision identifiers, used by Alembic.
20+
revision: str = "d58bc70ec10f"
21+
down_revision: Union[str, None] = "9df9950d73a0"
22+
branch_labels: Union[str, Sequence[str], None] = None
23+
depends_on: Union[str, Sequence[str], None] = None
24+
25+
26+
def upgrade() -> None:
27+
op.rename_table("electrical_cell_recording", "electrical_recording")
28+
op.execute("ALTER INDEX pk_electrical_cell_recording RENAME TO pk_electrical_recording")
29+
30+
31+
def downgrade() -> None:
32+
op.rename_table("electrical_recording", "electrical_cell_recording")
33+
op.execute("ALTER INDEX pk_electrical_recording RENAME TO pk_electrical_cell_recording")
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
"""Add ion_channel and ion_channel_recording
2+
3+
Revision ID: b352b28dae67
4+
Revises: d58bc70ec10f
5+
Create Date: 2025-09-10 15:04:38.633137
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+
from sqlalchemy.dialects import postgresql
15+
16+
from sqlalchemy import Text
17+
import app.db.types
18+
19+
# revision identifiers, used by Alembic.
20+
revision: str = "b352b28dae67"
21+
down_revision: Union[str, None] = "d58bc70ec10f"
22+
branch_labels: Union[str, Sequence[str], None] = None
23+
depends_on: Union[str, Sequence[str], None] = None
24+
25+
26+
def upgrade() -> None:
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.create_table(
29+
"ion_channel",
30+
sa.Column("label", sa.String(), nullable=False),
31+
sa.Column("gene", sa.String(), nullable=False),
32+
sa.Column("synonyms", sa.ARRAY(sa.VARCHAR()), nullable=False),
33+
sa.Column("name", sa.String(), nullable=False),
34+
sa.Column("description", sa.String(), nullable=False),
35+
sa.Column("description_vector", postgresql.TSVECTOR(), nullable=True),
36+
sa.Column("id", sa.Uuid(), nullable=False),
37+
sa.Column("created_by_id", sa.Uuid(), nullable=False),
38+
sa.Column("updated_by_id", sa.Uuid(), nullable=False),
39+
sa.Column(
40+
"creation_date",
41+
sa.DateTime(timezone=True),
42+
server_default=sa.text("now()"),
43+
nullable=False,
44+
),
45+
sa.Column(
46+
"update_date",
47+
sa.DateTime(timezone=True),
48+
server_default=sa.text("now()"),
49+
nullable=False,
50+
),
51+
sa.ForeignKeyConstraint(
52+
["created_by_id"], ["agent.id"], name=op.f("fk_ion_channel_created_by_id_agent")
53+
),
54+
sa.ForeignKeyConstraint(
55+
["updated_by_id"], ["agent.id"], name=op.f("fk_ion_channel_updated_by_id_agent")
56+
),
57+
sa.PrimaryKeyConstraint("id", name=op.f("pk_ion_channel")),
58+
)
59+
op.create_index(
60+
op.f("ix_ion_channel_created_by_id"), "ion_channel", ["created_by_id"], unique=False
61+
)
62+
op.create_index(
63+
op.f("ix_ion_channel_creation_date"), "ion_channel", ["creation_date"], unique=False
64+
)
65+
op.create_index(
66+
"ix_ion_channel_description_vector",
67+
"ion_channel",
68+
["description_vector"],
69+
unique=False,
70+
postgresql_using="gin",
71+
)
72+
op.create_index(op.f("ix_ion_channel_label"), "ion_channel", ["label"], unique=True)
73+
op.create_index(op.f("ix_ion_channel_name"), "ion_channel", ["name"], unique=False)
74+
op.create_index(
75+
op.f("ix_ion_channel_updated_by_id"), "ion_channel", ["updated_by_id"], unique=False
76+
)
77+
op.create_table(
78+
"electrical_cell_recording",
79+
sa.Column("id", sa.Uuid(), nullable=False),
80+
sa.ForeignKeyConstraint(
81+
["id"],
82+
["electrical_recording.id"],
83+
name=op.f("fk_electrical_cell_recording_id_electrical_recording"),
84+
),
85+
sa.PrimaryKeyConstraint("id", name=op.f("pk_electrical_cell_recording")),
86+
)
87+
op.create_table(
88+
"ion_channel_recording",
89+
sa.Column("id", sa.Uuid(), nullable=False),
90+
sa.Column("cell_line", sa.String(), nullable=False),
91+
sa.Column("ion_channel_id", sa.Uuid(), nullable=False),
92+
sa.ForeignKeyConstraint(
93+
["id"],
94+
["electrical_recording.id"],
95+
name=op.f("fk_ion_channel_recording_id_electrical_recording"),
96+
),
97+
sa.ForeignKeyConstraint(
98+
["ion_channel_id"],
99+
["ion_channel.id"],
100+
name=op.f("fk_ion_channel_recording_ion_channel_id_ion_channel"),
101+
),
102+
sa.PrimaryKeyConstraint("id", name=op.f("pk_ion_channel_recording")),
103+
)
104+
op.create_index(
105+
op.f("ix_ion_channel_recording_ion_channel_id"),
106+
"ion_channel_recording",
107+
["ion_channel_id"],
108+
unique=False,
109+
)
110+
op.drop_index(
111+
op.f("ix_electrical_cell_recording_description_vector"),
112+
table_name="electrical_recording",
113+
postgresql_using="gin",
114+
)
115+
op.drop_index(op.f("ix_electrical_cell_recording_name"), table_name="electrical_recording")
116+
op.create_index(
117+
"ix_electrical_recording_description_vector",
118+
"electrical_recording",
119+
["description_vector"],
120+
unique=False,
121+
postgresql_using="gin",
122+
)
123+
op.create_index(
124+
op.f("ix_electrical_recording_name"), "electrical_recording", ["name"], unique=False
125+
)
126+
op.sync_enum_values(
127+
enum_schema="public",
128+
enum_name="entitytype",
129+
new_values=[
130+
"analysis_software_source_code",
131+
"brain_atlas",
132+
"brain_atlas_region",
133+
"cell_composition",
134+
"electrical_cell_recording",
135+
"electrical_recording",
136+
"electrical_recording_stimulus",
137+
"emodel",
138+
"experimental_bouton_density",
139+
"experimental_neuron_density",
140+
"experimental_synapses_per_connection",
141+
"external_url",
142+
"ion_channel",
143+
"ion_channel_model",
144+
"ion_channel_recording",
145+
"memodel",
146+
"mesh",
147+
"memodel_calibration_result",
148+
"me_type_density",
149+
"reconstruction_morphology",
150+
"simulation",
151+
"simulation_campaign",
152+
"simulation_campaign_generation",
153+
"simulation_execution",
154+
"simulation_result",
155+
"scientific_artifact",
156+
"single_neuron_simulation",
157+
"single_neuron_synaptome",
158+
"single_neuron_synaptome_simulation",
159+
"subject",
160+
"validation_result",
161+
"circuit",
162+
],
163+
affected_columns=[
164+
TableReference(table_schema="public", table_name="entity", column_name="type")
165+
],
166+
enum_values_to_rename=[],
167+
)
168+
# ### end Alembic commands ###
169+
170+
171+
def downgrade() -> None:
172+
# ### commands auto generated by Alembic - please adjust! ###
173+
op.sync_enum_values(
174+
enum_schema="public",
175+
enum_name="entitytype",
176+
new_values=[
177+
"analysis_software_source_code",
178+
"brain_atlas",
179+
"brain_atlas_region",
180+
"cell_composition",
181+
"electrical_cell_recording",
182+
"electrical_recording_stimulus",
183+
"emodel",
184+
"experimental_bouton_density",
185+
"experimental_neuron_density",
186+
"experimental_synapses_per_connection",
187+
"external_url",
188+
"ion_channel_model",
189+
"memodel",
190+
"mesh",
191+
"memodel_calibration_result",
192+
"me_type_density",
193+
"reconstruction_morphology",
194+
"simulation",
195+
"simulation_campaign",
196+
"simulation_campaign_generation",
197+
"simulation_execution",
198+
"simulation_result",
199+
"scientific_artifact",
200+
"single_neuron_simulation",
201+
"single_neuron_synaptome",
202+
"single_neuron_synaptome_simulation",
203+
"subject",
204+
"validation_result",
205+
"circuit",
206+
],
207+
affected_columns=[
208+
TableReference(table_schema="public", table_name="entity", column_name="type")
209+
],
210+
enum_values_to_rename=[],
211+
)
212+
op.drop_index(op.f("ix_electrical_recording_name"), table_name="electrical_recording")
213+
op.drop_index(
214+
"ix_electrical_recording_description_vector",
215+
table_name="electrical_recording",
216+
postgresql_using="gin",
217+
)
218+
op.create_index(
219+
op.f("ix_electrical_cell_recording_name"), "electrical_recording", ["name"], unique=False
220+
)
221+
op.create_index(
222+
op.f("ix_electrical_cell_recording_description_vector"),
223+
"electrical_recording",
224+
["description_vector"],
225+
unique=False,
226+
postgresql_using="gin",
227+
)
228+
op.drop_index(
229+
op.f("ix_ion_channel_recording_ion_channel_id"), table_name="ion_channel_recording"
230+
)
231+
op.drop_table("ion_channel_recording")
232+
op.drop_table("electrical_cell_recording")
233+
op.drop_index(op.f("ix_ion_channel_updated_by_id"), table_name="ion_channel")
234+
op.drop_index(op.f("ix_ion_channel_name"), table_name="ion_channel")
235+
op.drop_index(op.f("ix_ion_channel_label"), table_name="ion_channel")
236+
op.drop_index(
237+
"ix_ion_channel_description_vector", table_name="ion_channel", postgresql_using="gin"
238+
)
239+
op.drop_index(op.f("ix_ion_channel_creation_date"), table_name="ion_channel")
240+
op.drop_index(op.f("ix_ion_channel_created_by_id"), table_name="ion_channel")
241+
op.drop_table("ion_channel")
242+
# ### end Alembic commands ###
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Update triggers
2+
3+
Revision ID: b89af5e363b9
4+
Revises: b352b28dae67
5+
Create Date: 2025-09-10 15:13:20.918399
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
import sqlalchemy as sa
13+
from alembic_utils.pg_trigger import PGTrigger
14+
from sqlalchemy import text as sql_text
15+
16+
from sqlalchemy import Text
17+
import app.db.types
18+
19+
# revision identifiers, used by Alembic.
20+
revision: str = "b89af5e363b9"
21+
down_revision: Union[str, None] = "b352b28dae67"
22+
branch_labels: Union[str, Sequence[str], None] = None
23+
depends_on: Union[str, Sequence[str], None] = None
24+
25+
26+
def upgrade() -> None:
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
public_ion_channel_ion_channel_description_vector = PGTrigger(
29+
schema="public",
30+
signature="ion_channel_description_vector",
31+
on_entity="public.ion_channel",
32+
is_constraint=False,
33+
definition="BEFORE INSERT OR UPDATE ON ion_channel\n FOR EACH ROW EXECUTE FUNCTION\n tsvector_update_trigger(description_vector, 'pg_catalog.english', description, name)",
34+
)
35+
op.create_entity(public_ion_channel_ion_channel_description_vector)
36+
37+
public_electrical_recording_electrical_recording_description_vector = PGTrigger(
38+
schema="public",
39+
signature="electrical_recording_description_vector",
40+
on_entity="public.electrical_recording",
41+
is_constraint=False,
42+
definition="BEFORE INSERT OR UPDATE ON electrical_recording\n FOR EACH ROW EXECUTE FUNCTION\n tsvector_update_trigger(description_vector, 'pg_catalog.english', description, name)",
43+
)
44+
op.create_entity(public_electrical_recording_electrical_recording_description_vector)
45+
46+
public_electrical_recording_electrical_cell_recording_description_vector = PGTrigger(
47+
schema="public",
48+
signature="electrical_cell_recording_description_vector",
49+
on_entity="public.electrical_recording",
50+
is_constraint=False,
51+
definition="BEFORE INSERT OR UPDATE ON public.electrical_recording FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('description_vector', 'pg_catalog.english', 'description', 'name')",
52+
)
53+
op.drop_entity(public_electrical_recording_electrical_cell_recording_description_vector)
54+
55+
# ### end Alembic commands ###
56+
57+
58+
def downgrade() -> None:
59+
# ### commands auto generated by Alembic - please adjust! ###
60+
public_electrical_recording_electrical_cell_recording_description_vector = PGTrigger(
61+
schema="public",
62+
signature="electrical_cell_recording_description_vector",
63+
on_entity="public.electrical_recording",
64+
is_constraint=False,
65+
definition="BEFORE INSERT OR UPDATE ON public.electrical_recording FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('description_vector', 'pg_catalog.english', 'description', 'name')",
66+
)
67+
op.create_entity(public_electrical_recording_electrical_cell_recording_description_vector)
68+
69+
public_electrical_recording_electrical_recording_description_vector = PGTrigger(
70+
schema="public",
71+
signature="electrical_recording_description_vector",
72+
on_entity="public.electrical_recording",
73+
is_constraint=False,
74+
definition="BEFORE INSERT OR UPDATE ON electrical_recording\n FOR EACH ROW EXECUTE FUNCTION\n tsvector_update_trigger(description_vector, 'pg_catalog.english', description, name)",
75+
)
76+
op.drop_entity(public_electrical_recording_electrical_recording_description_vector)
77+
78+
public_ion_channel_ion_channel_description_vector = PGTrigger(
79+
schema="public",
80+
signature="ion_channel_description_vector",
81+
on_entity="public.ion_channel",
82+
is_constraint=False,
83+
definition="BEFORE INSERT OR UPDATE ON ion_channel\n FOR EACH ROW EXECUTE FUNCTION\n tsvector_update_trigger(description_vector, 'pg_catalog.english', description, name)",
84+
)
85+
op.drop_entity(public_ion_channel_ion_channel_description_vector)
86+
87+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)