-
Notifications
You must be signed in to change notification settings - Fork 0
1.8 Step | CreateDatabase
Creates the application database (
db_name) owned bydb_user, reversibly. It lives insrc/steps/create_database.rs. A port ofcreate_db_if_missingfromlib/postgres.sh.This is where the most important protection in the whole installer lives.
It is the single line of behaviour that separates “an installer that cleans up” from “an installer that can destroy a customer's data”.
A database with the same name that already existed may hold real data. The undo drops it only if we created it (
PreState::CreatedByUs). OnPreexistingthe undo is strictly a NO-OP.
The branch is designed to be impossible to get wrong: the PreState governs the drop, and the call
to dropdb is reachable only inside the CreatedByUs branch. There is no code path that leads to
dropping a Preexisting database.
undo:
if prestate != CreatedByUs → log "pre-existing DB, NOT removed" and RETURN
otherwise → dropdb --if-exists --force
| Phase | Behaviour |
|---|---|
| snapshot | does the database already exist? (SELECT 1 FROM pg_database WHERE datname = ...) → Preexisting/Untracked. This is the protection's source of truth |
| run |
Preexisting → skip. Absent → createdb --owner <user> <db>, then CreatedByUs. dry_run → log only |
| undo |
only CreatedByUs → dropdb --if-exists --force (closes active connections). Preexisting → NO-OP with an explicit log line |
The verdict this step reaches is also read by a later step: the filestore
(1.12b SetupDataDir) may only be removed if the database was ours, so it
reads the answer through the db_created_by_us channel in the Context and persists a copy of its own.
Ownership of the data and ownership of the directory are two different questions.
This is not politeness: it is the anti-destruction barrier. The tests pin it down from several angles:
-
Preexistingdatabase → the undo produces noDROP DATABASE(and nocreatedb); - absent database (
CreatedByUs) →createdbin run,dropdbin undo; -
Preexistingdatabase → nodropdbeven whenundois invoked repeatedly.
If a future refactor broke the protection, these tests would fail immediately.
-
--forceondropdbterminates active connections before removing — only for databases of ours. - Best-effort undo.
- Coordination with 1.7 CreateDbRole: this step runs after the role, so on rollback its undo (dropping the database) precedes dropping the role that owns it.
Start here
Key concepts
References
For developers
Technical detail — how it works inside
Steps:
- 1.1 PrepareOptRoot
- 1.2 CreateOdooUser
- 1.3 SetupLogDir
- 1.3b SetupCacheDir
- 1.4 AptPackages (delta)
- 1.5 InstallWkhtmltopdf
- 1.6 SetupPostgres
- 1.7 CreateDbRole
- 1.8 CreateDatabase
- 1.9 CloneOdooRepo
- 1.10 CreateVirtualenv
- 1.11 InstallPythonRequirements
- 1.12 GenerateConfig
- 1.12b SetupDataDir
- 1.13 InitializeOdooDatabase
- 1.14 SetupSystemd
- 1.15 Nginx (6 sub-steps)
- 1.16 WriteControlScript + PatchBashrc
Cross-cutting: