Comments (2)
I think of another simpler way:
Determine if process-revision_directives
exists in the env. py
file.
configure_args = current_app.extensions['migrate'].configure_args
if configure_args.get("process_revision_directives") is None:
configure_args["process_revision_directives"] = process_revision_directives
complete code:
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
I think of another simpler way:
"""python
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
connectable = get_engine()
configure_args = current_app.extensions['migrate'].configure_args
if configure_args.get("process_revision_directives") is None:
configure_args["process_revision_directives"] = process_revision_directives
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
**configure_args
)
with context.begin_transaction():
context.run_migrations()
from flask-migrate.
@luolingchun Let's go with the second approach, which only requires changes to env.py. Thanks!
from flask-migrate.
Related Issues (20)
- Alembic upgrade head in infinite loop HOT 1
- Migrations sometimes end with status 1 HOT 4
- How to check if models are in sync with generated migrations? HOT 1
- Type hints HOT 2
- [4.0] app factory is called before click groups HOT 6
- flask db migrate taking ~30min to autogenerate and throwing unrelated warnings HOT 2
- How is this possible?
- Failure to run flask db migrate after upgrade 3.1 -> 4.0 HOT 4
- Custom Template is not included in the sdist HOT 1
- Compatibility with sqlalchemy v2 HOT 5
- DeprecationWarning: 'get_engine' is deprecated HOT 5
- Enum Field changes, but no changes in schema detected when run "flask db migrate" HOT 1
- Do not automatically import of sqlalchemy_utils HOT 1
- The pgvector vector field cannot generate a normal migration script HOT 1
- An error was reported during migration
- Problems connecting to Postsgress Because of no encryption HOT 5
- No such command 'db'
- db.create_all() not working with PostgreSQL on windows platform HOT 1
- flask db doesn't make migrations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-migrate.