You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/07/04 15:09:12 UTC

[GitHub] [airflow] ashb commented on a diff in pull request #24156: Create new databases from the ORM

ashb commented on code in PR #24156:
URL: https://github.com/apache/airflow/pull/24156#discussion_r913089743


##########
airflow/models/base.py:
##########
@@ -25,9 +25,23 @@
 
 SQL_ALCHEMY_SCHEMA = conf.get("database", "SQL_ALCHEMY_SCHEMA")
 
+# For more information about what the tokens in the naming convention
+# below mean, see:
+# https://docs.sqlalchemy.org/en/14/core/metadata.html#sqlalchemy.schema.MetaData.params.naming_convention
+naming_convention = {
+    "ix": "idx_%(column_0_N_label)s",
+    "uq": "%(table_name)s_%(column_0_N_name)s_uq",
+    "ck": "ck_%(table_name)s_%(constraint_name)s",
+    "fk": "%(table_name)s_%(column_0_name)s_%(referred_table_name)s_fkey",
+    "pk": "%(table_name)s_pkey",
+}
+
 metadata = (
-    None if not SQL_ALCHEMY_SCHEMA or SQL_ALCHEMY_SCHEMA.isspace() else MetaData(schema=SQL_ALCHEMY_SCHEMA)
+    MetaData(naming_convention=naming_convention)
+    if not SQL_ALCHEMY_SCHEMA or SQL_ALCHEMY_SCHEMA.isspace()
+    else MetaData(schema=SQL_ALCHEMY_SCHEMA, naming_convention=naming_convention)
 )
+

Review Comment:
   I think this can be simplified:
   
   ```suggestion
   if not SQL_ALCHEMY_SCHEMA or SQL_ALCHEMY_SCHEMA.isspace():
       SQL_ALCHEMY_SCHEMA = None
   metadata =  MetaData(schema=SQL_ALCHEMY_SCHEMA, naming_convention=naming_convention)
   ```



-- 
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