potiuk commented on pull request #19597:
URL: https://github.com/apache/airflow/pull/19597#issuecomment-972764692


   AAAAAAHHHHH
   
   ```
   {{ define "wait-for-migrations-command" }}
     {{/* From Airflow 2.0.0 this can become [airflow, db, check-migrations] 
*/}}
     - python
     - -c
     - |
           import airflow
           import logging
           import os
           import time
   
           from alembic.config import Config
           from alembic.runtime.migration import MigrationContext
           from alembic.script import ScriptDirectory
   
           from airflow import settings
   
           package_dir = os.path.abspath(os.path.dirname(airflow.__file__))
           directory = os.path.join(package_dir, 'migrations')
           config = Config(os.path.join(package_dir, 'alembic.ini'))
           config.set_main_option('script_location', directory)
           config.set_main_option('sqlalchemy.url', 
settings.SQL_ALCHEMY_CONN.replace('%', '%%'))
           script_ = ScriptDirectory.from_config(config)
   
           timeout=60
   
           with settings.engine.connect() as connection:
               context = MigrationContext.configure(connection)
               ticker = 0
               while True:
                   source_heads = set(script_.get_heads())
   
                   db_heads = set(context.get_current_heads())
                   if source_heads == db_heads:
                       break
   
                   if ticker >= timeout:
                       raise TimeoutError("There are still unapplied migrations 
after {} seconds.".format(ticker))
                   ticker += 1
                   time.sleep(1)
                   logging.info('Waiting for migrations... %s second(s)', 
ticker)
   {{- end }}
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to