diff --git a/shared/django_apps/db_settings.py b/shared/django_apps/db_settings.py index 7a0fa3173..334dbdd3c 100644 --- a/shared/django_apps/db_settings.py +++ b/shared/django_apps/db_settings.py @@ -3,6 +3,7 @@ import django_prometheus from shared.config import get_config +from shared.timeseries.helpers import is_timeseries_enabled db_url = get_config("services", "database_url") if db_url: @@ -48,7 +49,7 @@ ) DATABASE_READ_PORT = get_config("services", "database_read", "port", default=5432) -TIMESERIES_ENABLED = get_config("setup", "timeseries", "enabled", default=False) +TIMESERIES_ENABLED = is_timeseries_enabled() TIMESERIES_REAL_TIME_AGGREGATES = get_config( "setup", "timeseries", "real_time_aggregates", default=False ) diff --git a/shared/django_apps/legacy_migrations/management/commands/migrate.py b/shared/django_apps/legacy_migrations/management/commands/migrate.py index d13f04693..a36f4d1c5 100644 --- a/shared/django_apps/legacy_migrations/management/commands/migrate.py +++ b/shared/django_apps/legacy_migrations/management/commands/migrate.py @@ -8,6 +8,7 @@ from shared.django_apps.utils.config import RUN_ENV from shared.helpers.redis import get_redis_connection +from shared.timeseries.helpers import is_timeseries_enabled log = logging.getLogger(__name__) @@ -115,7 +116,13 @@ def _obtain_lock(self): def handle(self, *args, **options): log.info("Codecov is starting migrations...") database = options["database"] - db_connection = connections[database] + try: + db_connection = connections[database] + except Exception: + log.info( + f"Failed to establish connection with {database}. Cannot do migrations" + ) + return None options["run_syncdb"] = False lock = self._obtain_lock() @@ -129,7 +136,7 @@ def handle(self, *args, **options): with db_connection.cursor() as cursor: self._fake_initial_migrations(cursor, args, options) - if database == "timeseries": + if database == "timeseries" and is_timeseries_enabled(): self._fake_initial_timeseries_migrations(cursor, args, options) super().handle(*args, **options) diff --git a/shared/timeseries/__init__.py b/shared/timeseries/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/shared/timeseries/helpers.py b/shared/timeseries/helpers.py new file mode 100644 index 000000000..01ce4e983 --- /dev/null +++ b/shared/timeseries/helpers.py @@ -0,0 +1,5 @@ +from shared.config import get_config + + +def is_timeseries_enabled() -> bool: + return get_config("setup", "timeseries", "enabled", default=False)