Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISD-1516 Remove is_leader check when running db migration #189

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,24 @@ def _execute_migrations(self) -> None:
if not self._are_relations_ready() or not container.can_connect():
logger.info("Not ready to execute migrations")
return
if self.model.unit.is_leader():
env_settings = self._create_discourse_environment_settings()
self.model.unit.status = MaintenanceStatus("Executing migrations")
try:
migration_process: ExecProcess = container.exec(
[f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "--trace", "db:migrate"],
environment=env_settings,
working_dir=DISCOURSE_PATH,
user=CONTAINER_APP_USERNAME,
)
migration_process.wait_output()
except ExecError as cmd_err:
logger.exception("Executing migrations failed with code %d.", cmd_err.exit_code)
raise
Thanhphan1147 marked this conversation as resolved.
Show resolved Hide resolved
env_settings = self._create_discourse_environment_settings()
self.model.unit.status = MaintenanceStatus("Executing migrations")
# The rails migration task is idempotent and concurrent-safe, from
# https://stackoverflow.com/questions/17815769/are-rake-dbcreate-and-rake-dbmigrate-idempotent
# and https://github.com/rails/rails/pull/22122
# Thus it's safe to run this task on all units to
# avoid complications with how juju schedules charm upgrades
try:
migration_process: ExecProcess = container.exec(
[f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "--trace", "db:migrate"],
environment=env_settings,
working_dir=DISCOURSE_PATH,
user=CONTAINER_APP_USERNAME,
)
migration_process.wait_output()
except ExecError as cmd_err:
logger.exception("Executing migrations failed with code %d.", cmd_err.exit_code)
raise
mthaddon marked this conversation as resolved.
Show resolved Hide resolved

def _compile_assets(self) -> None:
container = self.unit.get_container(CONTAINER_NAME)
Expand Down
Loading