alembic init database/migrations
alembic revision --autogenerate -m "<some message>"
alembic upgrade head
e.g., the first commit (adding the order table)
(weird_salads) ➜ weird_salads git:(feature/orders_implementation) ✗ alembic revision --autogenerate -m "initial order table"
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'order'
Generating /Users/pjwright/Documents/weird_salads/database/migrations/versions/d5be4204230b_initial_order_table.py ... done
(weird_salads) ➜ weird_salads git:(feature/orders_implementation) ✗ alembic upgrade head
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> d5be4204230b, initial order table
which gives, a version, e.g.
# revision identifiers, used by Alembic.
revision: str = 'd5be4204230b'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('order',
sa.Column('id', sa.String(), nullable=False),
sa.Column('menu_id', sa.Integer(), nullable=False),
sa.Column('created', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('order')
# ### end Alembic commands ###
And every time the SQLalchemy Models are changed, the DB should be versioned! This database is upgraded through the Dockerfile for the main FastAPI service (see /docker/docker/Dockerfile)