pallets-eco / flask-alembic Goto Github PK
View Code? Open in Web Editor NEWIntegrate Alembic with Flask.
Home Page: https://flask-alembic.readthedocs.io
License: MIT License
Integrate Alembic with Flask.
Home Page: https://flask-alembic.readthedocs.io
License: MIT License
The docs say:
The latest code is hosted on BitBucket.
But the docs also include "Edit on GitHub" and the code is here. Maybe they are mirrored? Just thought I'd mention the possible confusion.
When calling db downgrade
without any arguments from my Flask app, I get following:
File "my_project/.venv/lib/python3.11/site-packages/flask_alembic/cli.py", line 118, in downgrade
alembic.downgrade(target)
File "my_project/.venv/lib/python3.11/site-packages/flask_alembic/extension.py", line 408, in downgrade
self.run_migrations(do_downgrade)
File "my_project/.venv/lib/python3.11/site-packages/flask_alembic/extension.py", line 272, in run_migrations
env.run_migrations(**kwargs)
File "my_project/.venv/lib/python3.11/site-packages/alembic/runtime/environment.py", line 948, in run_migrations
self.get_context().run_migrations(**kw)
File "my_project/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 615, in run_migrations
for step in self._migrations_fn(heads, self):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "my_project/.venv/lib/python3.11/site-packages/flask_alembic/extension.py", line 403, in do_downgrade
return self.script_directory._downgrade_revs( # type: ignore[return-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "my_project/.venv/lib/python3.11/site-packages/alembic/script/base.py", line 473, in _downgrade_revs
return [
^
File "my_project/.venv/lib/python3.11/site-packages/alembic/script/base.py", line 473, in <listcomp>
return [
^
File "my_project/.venv/lib/python3.11/site-packages/alembic/script/revision.py", line 813, in iterate_revisions
revisions, heads = fn(
^^^
File "my_project/.venv/lib/python3.11/site-packages/alembic/script/revision.py", line 1330, in _collect_downgrade_revisions
branch_label, target_revision = self._parse_downgrade_target(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "my_project/.venv/lib/python3.11/site-packages/alembic/script/revision.py", line 1112, in _parse_downgrade_target
assert isinstance(
AssertionError: Expected downgrade target in string form
I did some debugging to ensure that alembic.downgrade(target)
is called with default argument and it looks like this:
alembic.downgrade("-1")
problem happens here:
# flask-alembic/extension.py
def downgrade(self, target: int | str | Script = -1) -> None:
"""Run migrations to downgrade database.
:param target: Revision to go down to.
"""
target_arg = self._simplify_rev(target, handle_int=True)
def do_downgrade(
revision: str | list[str] | tuple[str, ...], context: MigrationContext
) -> list[MigrationStep]:
return self.script_directory._downgrade_revs( # type: ignore[return-value]
target_arg, # type: ignore[arg-type]
revision, # type: ignore[arg-type]
)
self._simplify_rev()
always returns list of strings, but notice that method _downgrade_revs
in alembic
is declared as following:
# alembic/script/base.py
def _downgrade_revs(
self, destination: str, current_rev: Optional[str]
) -> List[RevisionStep]:
...
No time to dig deeper, hope that above helps.
Good day,
I need to use alembic render_as_batch
feature. However, I tried using
ALEMBIC_CONTEXT = {
"render_as_batch": True
}
and it did not work. What am I missing? how may I enable this feature?
Thank you
Is there a way to do the equivalent of alembic check
with flask-alembic?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.