Creating minimal POC code for testing op.create_table(), op.create_index(), etc. #1704
-
I'd like to create a minimalist code example to test certain Alembic operations without a full-blown migration setup. I started with the following, fully expecting it to fail because it didn't address how to create the engine (e.g., what the connection URL is). Still, I thought I'd try it to see what failed. from alembic import op
import sqlalchemy as sa
op.create_table(
"invoice",
sa.Column("invoice_number", sa.Integer(), nullable=False),
sa.Column("account_number", sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint("invoice_number"),
)
op.create_index(op.f("ix_invoice_account_number"), "invoice", ["account_number"], unique=False) The error is
My hope is to jury-rig an environment that is sufficiently Alembic-aware to run relatively simple operations on a third-party dialect without creating formal migrations. Can anyone suggest a place to start? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
you can run operations against any engine using the short example that's at https://alembic.sqlalchemy.org/en/latest/ops.html#alembic.operations.Operations from alembic.migration import MigrationContext
from alembic.operations import Operations
myengine = create_engine(whatever)
conn = myengine.connect()
ctx = MigrationContext.configure(conn)
op = Operations(ctx)
op.alter_column("t", "c", nullable=True) |
Beta Was this translation helpful? Give feedback.
you can run operations against any engine using the short example that's at https://alembic.sqlalchemy.org/en/latest/ops.html#alembic.operations.Operations