refactor: using DeclarativeBase as parent class of models, refactored tools

This commit is contained in:
Yeuoly
2024-09-29 17:00:58 +08:00
parent c8bc3892b3
commit e9e5c8806a
17 changed files with 225 additions and 120 deletions

View File

@ -31,19 +31,16 @@ def get_engine_url():
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
from models.base import Base
def get_metadata():
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata
return Base.metadata
def include_object(object, name, type_, reflected, compare_to):
if type_ == "foreign_key_constraint":