Skip to content

Commit

Permalink
260 support disabled timescaledb (#315)
Browse files Browse the repository at this point in the history
* gracefully raise when a connection can't be established

* Adjust exception message

* fix import
  • Loading branch information
adrian-codecov authored Aug 16, 2024
1 parent 76a3263 commit 49f1bc9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion shared/django_apps/db_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
Empty file added shared/timeseries/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions shared/timeseries/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from shared.config import get_config


def is_timeseries_enabled() -> bool:
return get_config("setup", "timeseries", "enabled", default=False)

0 comments on commit 49f1bc9

Please sign in to comment.