Skip to content

Commit d9d09cc

Browse files
committed
feat(project run): migrate encrypted database when configured
1 parent 5d07218 commit d9d09cc

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/dbx_python_cli/commands/project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,40 @@ def run_project(
13561356
raise typer.Exit(code=result.returncode)
13571357
typer.echo("✅ Migrations completed successfully")
13581358

1359+
# Migrate the encrypted database if the project has one configured (e.g. QE projects)
1360+
has_encrypted_db = subprocess.run(
1361+
[
1362+
python_path,
1363+
"-c",
1364+
"import django; django.setup(); from django.conf import settings; "
1365+
"exit(0 if 'encrypted' in settings.DATABASES else 1)",
1366+
],
1367+
cwd=proj.project_path,
1368+
env=migrate_env,
1369+
check=False,
1370+
capture_output=True,
1371+
)
1372+
if has_encrypted_db.returncode == 0:
1373+
typer.echo("🔐 Running migrations for encrypted database")
1374+
enc_result = subprocess.run(
1375+
[python_path, "-m", "django", "migrate", "--database", "encrypted"],
1376+
cwd=proj.project_path,
1377+
env=migrate_env,
1378+
check=False,
1379+
capture_output=not verbose,
1380+
text=True,
1381+
)
1382+
if enc_result.returncode != 0:
1383+
typer.echo("⚠️ Encrypted database migration failed", err=True)
1384+
if enc_result.stderr:
1385+
lines = [
1386+
ln for ln in enc_result.stderr.strip().splitlines() if ln.strip()
1387+
]
1388+
for line in lines[-3:]:
1389+
typer.echo(f" {line}", err=True)
1390+
else:
1391+
typer.echo("✅ Encrypted database migrations completed successfully")
1392+
13591393
# Create initial Wagtail data (root page + default site) if Wagtail is installed
13601394
_setup_wagtail_initial_data(python_path, proj, migrate_env, verbose)
13611395

0 commit comments

Comments
 (0)