From 38dfe4208747e60383a7576011f8b399a50ce4a8 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 13:05:10 -0500 Subject: [PATCH] Add migration for Planet --- .../20250325_130505_4bf2ca14_create_planet.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 alembic/versions/20250325_130505_4bf2ca14_create_planet.py diff --git a/alembic/versions/20250325_130505_4bf2ca14_create_planet.py b/alembic/versions/20250325_130505_4bf2ca14_create_planet.py new file mode 100644 index 0000000..08b4db7 --- /dev/null +++ b/alembic/versions/20250325_130505_4bf2ca14_create_planet.py @@ -0,0 +1,52 @@ +"""create planets table + +Revision ID: 1234567890ab +Revises: +Create Date: 2023-05-25 10:00:00.000000 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.sql import func + +# revision identifiers, used by Alembic +revision = '1234567890ab' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # Create planets table + op.create_table( + 'planets', + sa.Column('id', sa.Integer, primary_key=True, index=True), + sa.Column('name', sa.String, unique=True, nullable=False), + sa.Column('description', sa.String, nullable=True), + sa.Column('diameter', sa.Integer, nullable=False), + sa.Column('mass', sa.Integer, nullable=False), + sa.Column('distance_from_sun', sa.Integer, nullable=False), + sa.Column('created_at', sa.Integer, default=func.now()), + sa.Column('updated_at', sa.Integer, default=func.now()) + ) + + +def downgrade(): + # Drop planets table + op.drop_table('planets') +``` + +This Alembic migration script creates a new table named 'planets' with the following columns: + +- `id` (Integer, Primary Key, Indexed) +- `name` (String, Unique, Not Nullable) +- `description` (String, Nullable) +- `diameter` (Integer, Not Nullable) +- `mass` (Integer, Not Nullable) +- `distance_from_sun` (Integer, Not Nullable) +- `created_at` (Integer, Default value from `func.now()`) +- `updated_at` (Integer, Default value from `func.now()`) + +The `upgrade()` function creates the table using the `op.create_table()` operation, while the `downgrade()` function drops the table using `op.drop_table()`. + +Note that the revision ID, revision identifiers, and create date are included as comments at the top of the script. \ No newline at end of file