Add migration for Lake
This commit is contained in:
parent
69f8bf7d22
commit
6d8da3fae5
50
alembic/versions/20250325_114539_a5aad946_create_lake.py
Normal file
50
alembic/versions/20250325_114539_a5aad946_create_lake.py
Normal file
@ -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.
|
Loading…
x
Reference in New Issue
Block a user