diff --git a/lib/dl_core_testing/dl_core_testing/configuration.py b/lib/dl_core_testing/dl_core_testing/configuration.py index d25d8941d..89d249b13 100644 --- a/lib/dl_core_testing/dl_core_testing/configuration.py +++ b/lib/dl_core_testing/dl_core_testing/configuration.py @@ -26,6 +26,7 @@ class UnitedStorageConfiguration: us_master_token: str = attr.ib(kw_only=True) us_pg_dsn: str = attr.ib(kw_only=True) force: bool = attr.ib(kw_only=True, default=True) + migrations: Optional[list[list[str]]] = attr.ib(kw_only=True, default=None) @attr.s(frozen=True) diff --git a/lib/dl_core_testing/dl_core_testing/environment.py b/lib/dl_core_testing/dl_core_testing/environment.py index b234179e9..05e56e104 100644 --- a/lib/dl_core_testing/dl_core_testing/environment.py +++ b/lib/dl_core_testing/dl_core_testing/environment.py @@ -16,6 +16,10 @@ LOGGER = logging.getLogger(__name__) +DEFAULT_US_MIGRATIONS = [ + # TODO change to a more pretty command when it is wrapped in US + ["node", "/opt/app/dist/server/platform/src/db/scripts/migrate.js"], +] US_SERVICE_DOCKER_COMPOSE_LABEL = "united-storage" @@ -90,10 +94,13 @@ def prepare_united_storage( tenant_id: str = "common", us_pg_dsn: Optional[str] = None, force: bool = False, + us_migrations: Optional[list[list[str]]] = None, ) -> None: if not force and not os.environ.get("CLEAR_US_DATABASE", ""): LOGGER.debug("prepare_united_storage: CLEAR_US_DATABASE env is disabled, skipping.") return + if us_migrations is None: + us_migrations = DEFAULT_US_MIGRATIONS if us_pg_dsn is not None: LOGGER.debug("prepare_united_storage: wait for pg-us to be up...") @@ -109,11 +116,8 @@ def _wait_for_us() -> tuple[bool, str]: with requests.Session() as reqr: resp = reqr.get(f"{us_host}/ping-db", headers=headers) resp.raise_for_status() - run_cmd_in_containers_by_label( - US_SERVICE_DOCKER_COMPOSE_LABEL, - ["node", "/opt/app/dist/server/platform/src/db/scripts/migrate.js"], - ) - # TODO change to a more pretty command when it is wrapped in US ^^^ + for migration in us_migrations: + run_cmd_in_containers_by_label(US_SERVICE_DOCKER_COMPOSE_LABEL, migration) return True, "" except Exception as e: return False, str(e) @@ -132,6 +136,7 @@ def prepare_united_storage_from_config(us_config: UnitedStorageConfiguration) -> us_master_token=us_config.us_master_token, us_pg_dsn=us_config.us_pg_dsn, force=us_config.force, + us_migrations=us_config.migrations, )