[ 
https://issues.apache.org/jira/browse/AIRFLOW-2218?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Aizhamal Nurmamat kyzy updated AIRFLOW-2218:
--------------------------------------------
    Component/s:     (was: db)
                     (was: cli)
                 database

> Support user defined database migrations in "airflow upgradedb" and "airflow 
> initdb"
> ------------------------------------------------------------------------------------
>
>                 Key: AIRFLOW-2218
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-2218
>             Project: Apache Airflow
>          Issue Type: New Feature
>          Components: database
>            Reporter: Jesper Baasch-Larsen
>            Priority: Minor
>
> We want to record some domain specific statistics about our task runs. An 
> obvious place to put these are in the airflow metadatabase. To do this we 
> will need to apply some custom migrations to the database.
> A clean solution to this would be to be able to apply custom migrations on 
> top of the official airflow migrations by providing a second directory with 
> these migrations as an optional command line argument.
> If the first of the custom migrations has a "down_revision" of None this 
> should be substituted by the last of the official revisions. If a specific 
> official "down_revision" is specified the migration should fail if this is 
> (no longer) the last official revision.
> An example interface could be:
> airflow upgradedb [-h] [--custom-migrations-dir]
> and the same for initdb and possibly for resetdb as well.
> The implementation would involve changing the airflow.utils.db.upgradedb 
> method to something like:
> {code:java}
> def upgradedb(extra_versions_dirs=[]):
>     # alembic adds significant import time, so we import it lazily
>     from alembic import command
>     from alembic.config import Config
>     log.info("Creating tables")
>     current_dir = os.path.dirname(os.path.abspath(__file__))
>     package_dir = os.path.normpath(os.path.join(current_dir, '..'))
>     directory = os.path.join(package_dir, 'migrations')
>     versions_dir = os.path.join(directory, 'versions')
>     versions_dirs = ' '.join([versions_dir].extend(extra_versions_dirs))
>     config = Config(os.path.join(package_dir, 'alembic.ini'))
>     config.set_main_option('script_location', directory)
>     config.set_main_option('version_locations', versions_dirs)
>     config.set_main_option('sqlalchemy.url', settings.SQL_ALCHEMY_CONN)
>     command.upgrade(config, 'heads')
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to