From 6d8da3fae5052ba20c0b427e5c2cff71ad88f1ef Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 11:45:44 -0500 Subject: [PATCH] Add migration for Lake --- .../20250325_114539_a5aad946_create_lake.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 alembic/versions/20250325_114539_a5aad946_create_lake.py diff --git a/alembic/versions/20250325_114539_a5aad946_create_lake.py b/alembic/versions/20250325_114539_a5aad946_create_lake.py new file mode 100644 index 0000000..d399089 --- /dev/null +++ b/alembic/versions/20250325_114539_a5aad946_create_lake.py @@ -0,0 +1,50 @@ +"""create lakes table + +Revision ID: 1234567890ab +Revises: +Create Date: 2023-05-25 10:00:00.000000 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import UUID + + +# revision identifiers, used by Alembic +revision = '1234567890ab' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table( + 'lakes', + sa.Column('id', UUID(as_uuid=True), primary_key=True), + sa.Column('name', sa.String, nullable=False, unique=True), + sa.Column('description', sa.Text, nullable=True), + sa.Column('location', sa.String, nullable=False), + sa.Column('created_at', sa.DateTime, server_default=sa.func.now()), + sa.Column('updated_at', sa.DateTime, server_default=sa.func.now(), onupdate=sa.func.now()), + sa.PrimaryKeyConstraint('id'), + sa.Index('ix_lakes_name', 'name') + ) + + +def downgrade(): + op.drop_index('ix_lakes_name', 'lakes') + op.drop_table('lakes') +``` + +This Alembic migration script creates a new table called 'lakes' with the following columns: + +- `id` (UUID primary key) +- `name` (String, not nullable, unique, indexed) +- `description` (Text, nullable) +- `location` (String, not nullable) +- `created_at` (DateTime, server default to current timestamp) +- `updated_at` (DateTime, server default to current timestamp, updated on each record change) + +The `upgrade()` function creates the table and the index on the `name` column. + +The `downgrade()` function drops the index and the table, effectively reversing the changes made by the `upgrade()` function. \ No newline at end of file