I've created a few migrations already using Alembic, it's a really interesting tool.
Using it on a new DB would be straightforward enough, however our usecase is to apply these migrations to existing DB's, not only to bring them "up to speed" but to make sure that for example, should a table or column be altered through the phpmyadmin front-end or if a table exists already, that it can correct/created.
This would be perfect, as the MigrationID created for that script would then be able to be applied to any DB we have, correcting any inconsistencies without creating duplicates by skipping over what it deems to be correct.
As mentioned, a fresh database built using Alembic would able to be fixed via downgrade and reapplication, but I'm wondering if this can be done to an existing DB where Alembic is applied post.
For reference, here's the first migration code example if it's somehow useful.
"""create account table
Revision ID: bd4ec9e8afe8
Revises:
Create Date: 2019-10-29 15:25:39.736234
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.mysql import TINYINT
# revision identifiers, used by Alembic.
revision = 'bd4ec9e8afe8'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
'account',
sa.Column('id', sa.Integer, primary_key=True, nullable=False),
sa.Column('title', sa.String(150), nullable=False),
sa.Column('description', sa.Text, nullable=False),
sa.Column('uploads_allowed', TINYINT(), nullable=True),
sa.Column('viewers_contact_details', TINYINT(), default=0),
)
op.alter_column('account', sa.Column('id', sa.Integer, nullable=False, autoincrement=True))
# op.execute("""
# CREATE TABLE `account` (
# `id` int(11) NOT NULL,
# `title` varchar(150) NOT NULL,
# `description` text,
# `uploads_allowed` tinyint(1) DEFAULT '0',
# `viewers_contact_details` tinyint(1) DEFAULT '0'
# );
# """)
def downgrade():
op.drop_table('account')