Skip to content

Commit

Permalink
feat: BI-5748 allow custom US migrations in tests (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
MCPN authored Aug 23, 2024
1 parent 9979607 commit a307853
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/dl_core_testing/dl_core_testing/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions lib/dl_core_testing/dl_core_testing/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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...")
Expand All @@ -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)
Expand All @@ -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,
)


Expand Down

0 comments on commit a307853

Please sign in to comment.