Ejemplo n.º 1
0
def apply_db_migrations() -> None:
    """
    Apply any pending DB migrations.
    """
    log.info("-------- START - APPLY DB MIGRATIONS --------")
    upgradedb()
    log.info("-------- FINISH - APPLY DB MIGRATIONS --------")
Ejemplo n.º 2
0
def upgradedb(args):  # noqa
    print("DB: " + repr(settings.engine.url))
    db_utils.upgradedb()

    # Populate DagStats table
    session = settings.Session()
    ds_rows = session.query(DagStat).count()
    if not ds_rows:
        qry = (session.query(DagRun.dag_id, DagRun.state,
                             func.count('*')).group_by(DagRun.dag_id,
                                                       DagRun.state))
        for dag_id, state, count in qry:
            session.add(DagStat(dag_id=dag_id, state=state, count=count))
        session.commit()
Ejemplo n.º 3
0
def upgradedb(args):  # noqa
    print("DB: " + repr(settings.engine.url))
    db_utils.upgradedb()

    # Populate DagStats table
    session = settings.Session()
    ds_rows = session.query(DagStat).count()
    if not ds_rows:
        qry = (
            session.query(DagRun.dag_id, DagRun.state, func.count('*'))
            .group_by(DagRun.dag_id, DagRun.state)
        )
        for dag_id, state, count in qry:
            session.add(DagStat(dag_id=dag_id, state=state, count=count))
        session.commit()
Ejemplo n.º 4
0
def upgradedb(args):
    """Upgrades the metadata database"""
    print("DB: " + repr(settings.engine.url))
    if args.to_revision and args.to_version:
        raise SystemExit(
            "Cannot supply both `--to-revision` and `--to-version`.")
    if args.from_version and args.from_revision:
        raise SystemExit(
            "Cannot supply both `--from-revision` and `--from-version`")
    if (args.from_revision or args.from_version) and not args.show_sql_only:
        raise SystemExit(
            "Args `--from-revision` and `--from-version` may only be used with `--show-sql-only`"
        )
    to_revision = None
    from_revision = None
    if args.from_revision:
        from_revision = args.from_revision
    elif args.from_version:
        if parse_version(args.from_version) < parse_version('2.0.0'):
            raise SystemExit(
                "--from-version must be greater or equal to than 2.0.0")
        from_revision = REVISION_HEADS_MAP.get(args.from_version)
        if not from_revision:
            raise SystemExit(
                f"Unknown version {args.from_version!r} supplied as `--from-version`."
            )

    if args.to_version:
        to_revision = REVISION_HEADS_MAP.get(args.to_version)
        if not to_revision:
            raise SystemExit(
                f"Upgrading to version {args.to_version} is not supported.")
    elif args.to_revision:
        to_revision = args.to_revision

    if not args.show_sql_only:
        print("Performing upgrade with database " + repr(settings.engine.url))
    else:
        print(
            "Generating sql for upgrade -- upgrade commands will *not* be submitted."
        )

    db.upgradedb(to_revision=to_revision,
                 from_revision=from_revision,
                 show_sql_only=args.show_sql_only)
    if not args.show_sql_only:
        print("Upgrades done")
Ejemplo n.º 5
0
    def setUp(self):
        if self.require_local_executor:
            self._check_local_executor_setup()
        try:
            # We want to avoid random errors while database got reset - those
            # Are apparently triggered by parser trying to parse DAGs while
            # The tables are dropped. We move the dags temporarily out of the dags folder
            # and move them back after reset
            self._store_dags_to_temporary_directory()
            try:
                db_utils.upgradedb()
                db_utils.resetdb()
            finally:
                self._restore_dags_from_temporary_directory()
            self._symlink_dag_and_associated_files()
            super().setUp()

        except Exception as e:
            # In case of any error during setup - restore the authentication
            self.gcp_authenticator.gcp_restore_authentication()
            raise e
    def setUp(self):
        if self.require_local_executor:
            self._check_local_executor_setup()
        try:
            # We want to avoid random errors while database got reset - those
            # Are apparently triggered by parser trying to parse DAGs while
            # The tables are dropped. We move the dags temporarily out of the dags folder
            # and move them back after reset
            self._store_dags_to_temporary_directory()
            try:
                db_utils.upgradedb()
                db_utils.resetdb()
            finally:
                self._restore_dags_from_temporary_directory()
            self._symlink_dag_and_associated_files()
            super(DagGcpSystemTestCase, self).setUp()

        except Exception as e:
            # In case of any error during setup - restore the authentication
            self.gcp_authenticator.gcp_restore_authentication()
            raise e
Ejemplo n.º 7
0
def upgradedb(args):
    """Upgrades the metadata database"""
    print("DB: " + repr(settings.engine.url))
    db.upgradedb(version_range=args.range, revision_range=args.revision_range)
    print("Upgrades done")
Ejemplo n.º 8
0
def upgradedb(args):  # noqa
    print("DB: " + repr(settings.engine.url))
    db_utils.upgradedb()
def upgradedb(args):
    """Upgrades the metadata database"""
    print("DB: " + repr(settings.engine.url))
    db.upgradedb()
Ejemplo n.º 10
0
import os

from airflow.utils import db

# Mocked AWS Credentials for moto.
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SECURITY_TOKEN"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"


# Setup Airflow DB.
db.upgradedb()
Ejemplo n.º 11
0
def airflow_db_backend():
    db.upgradedb()
    return 100