odoo-deployment: db-init skips --init when base already installed (fix migrate FK clash)
This commit is contained in:
@@ -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) ──"
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user