You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ashb (via GitHub)" <gi...@apache.org> on 2023/04/08 11:52:40 UTC
[GitHub] [airflow] ashb commented on a diff in pull request #29804: Use the engine provided in the session
ashb commented on code in PR #29804:
URL: https://github.com/apache/airflow/pull/29804#discussion_r1161102914
##########
airflow/utils/db.py:
##########
@@ -682,17 +682,19 @@ def _create_db_from_orm(session):
from airflow.www.fab_security.sqla.models import Model
from airflow.www.session import AirflowDatabaseSessionInterface
- def _create_flask_session_tbl():
+ def _create_flask_session_tbl(sql_database_uri):
flask_app = Flask(__name__)
- flask_app.config["SQLALCHEMY_DATABASE_URI"] = conf.get("database", "SQL_ALCHEMY_CONN")
+ flask_app.config["SQLALCHEMY_DATABASE_URI"] = sql_database_uri
flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(flask_app)
AirflowDatabaseSessionInterface(app=flask_app, db=db, table="session", key_prefix="")
db.create_all()
- with create_global_lock(session=session, lock=DBLocks.MIGRATIONS):
- Base.metadata.create_all(settings.engine)
- Model.metadata.create_all(settings.engine)
+ with create_global_lock(session=session , lock=DBLocks.MIGRATIONS):
+ engine = session.get_bind().engine
+ Base.metadata.create_all(engine)
+ Model.metadata.create_all(engine)
+ _create_flask_session_tbl(engine.url)
_create_flask_session_tbl()
Review Comment:
```suggestion
```
##########
airflow/utils/db.py:
##########
@@ -682,17 +682,19 @@ def _create_db_from_orm(session):
from airflow.www.fab_security.sqla.models import Model
from airflow.www.session import AirflowDatabaseSessionInterface
- def _create_flask_session_tbl():
+ def _create_flask_session_tbl(sql_database_uri):
flask_app = Flask(__name__)
- flask_app.config["SQLALCHEMY_DATABASE_URI"] = conf.get("database", "SQL_ALCHEMY_CONN")
+ flask_app.config["SQLALCHEMY_DATABASE_URI"] = sql_database_uri
flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(flask_app)
AirflowDatabaseSessionInterface(app=flask_app, db=db, table="session", key_prefix="")
db.create_all()
- with create_global_lock(session=session, lock=DBLocks.MIGRATIONS):
- Base.metadata.create_all(settings.engine)
- Model.metadata.create_all(settings.engine)
+ with create_global_lock(session=session , lock=DBLocks.MIGRATIONS):
Review Comment:
```suggestion
with create_global_lock(session=session, lock=DBLocks.MIGRATIONS):
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org