From 32d114e46ac558e4b887928ffcbdd3845e973606 Mon Sep 17 00:00:00 2001 From: git_admin Date: Tue, 28 Apr 2026 13:29:40 +0000 Subject: [PATCH] odoo-deployment: db-init skips --init when base already installed (fix migrate FK clash) --- templates/odoo-deployment.yaml | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/templates/odoo-deployment.yaml b/templates/odoo-deployment.yaml index e131c51..3675d7e 100644 --- a/templates/odoo-deployment.yaml +++ b/templates/odoo-deployment.yaml @@ -67,10 +67,37 @@ spec: echo "── creating database $DBNAME ──" PGPASSWORD="$PASSWORD" createdb -h "$HOST" -p "$PORT" -U "$USER" "$DBNAME" fi - echo "── initializing base module (no-op if already installed) ──" - odoo -i base -d "$DBNAME" --stop-after-init --without-demo=all --no-http \ - --db_host="$HOST" --db_port="$PORT" --db_user="$USER" --db_password="$PASSWORD" \ - --workers=0 + # Initialise base ONLY if the DB has never been initialised. + # The earlier comment claimed `-i base` was a no-op on + # already-initialised databases — that's wrong on Odoo + # 16+. `-i base` always runs `_process_end` which tries + # to unlink stale `ir.model.data` records flagged + # noupdate=False; if any of those records are + # referenced by REAL user data (e.g. a sale_order + # pointing at the partner Odoo wants to clean up), + # ForeignKeyViolation crashes the init and the pod + # crash-loops. + # + # The migrate-from-bundle flow restores a DB that has + # `base` installed AND real user FKs. Re-running + # `-i base` against it deterministically breaks. The + # check below skips the odoo step when base is already + # installed — fresh deploys still bootstrap correctly + # because base isn't installed in a brand-new database. + IS_INIT=$(PGPASSWORD="$PASSWORD" psql -h "$HOST" -p "$PORT" -U "$USER" -d "$DBNAME" -tAc \ + "SELECT 1 FROM information_schema.tables WHERE table_schema='public' AND table_name='ir_module_module'" 2>/dev/null || true) + if [ "$IS_INIT" = "1" ]; then + BASE_INSTALLED=$(PGPASSWORD="$PASSWORD" psql -h "$HOST" -p "$PORT" -U "$USER" -d "$DBNAME" -tAc \ + "SELECT 1 FROM ir_module_module WHERE name='base' AND state='installed'" 2>/dev/null || true) + fi + if [ "$BASE_INSTALLED" = "1" ]; then + echo "── base already installed — skipping --init (preserves restored data) ──" + else + echo "── initializing base module ──" + odoo -i base -d "$DBNAME" --stop-after-init --without-demo=all --no-http \ + --db_host="$HOST" --db_port="$PORT" --db_user="$USER" --db_password="$PASSWORD" \ + --workers=0 + fi echo "── db-init done ──" env: - name: HOST