At the moment we're using a procedure similar to that in the NixOS PgAdmin module to create and populate PgAdmin tables. We basically call the pgadmin4-setup Python script from the pgadmin4 Nix package to do the job.
It turns out the PgAdmin UI process actually runs DB migrations on startup. It tries connecting to the DB given in CONFIG_DATABASE_URI and fetch the current DB config version from the version table. If that table isn't there (empty DB) or the version is older then the current one, the UI process triggers the same setup procedure that pgadmin4-setup does, eventually calling user_info_server in pgadmin.setup.user_info. Here's the call trace for the case when the DB is empty:
Now user_info_server tries reading the initial user and password from the PGADMIN_SETUP_EMAIL and PGADMIN_SETUP_PASSWORD env vars, respectively.
So in principle we don't need pgadmin4-setup, which would simplify our bootstrap procedure. We could have just a single PgAdmin service with an
ExecStartPre directive to create the PgAdmin role and DB, assign that role perms to read/write Odoo tables, and install the function to fetch DB connection params;
ExecStartPost directive to create or update the built-in UI server connection to the local Postgres service.
At the moment we're using a procedure similar to that in the NixOS PgAdmin module to create and populate PgAdmin tables. We basically call the
pgadmin4-setup
Python script from thepgadmin4
Nix package to do the job.It turns out the PgAdmin UI process actually runs DB migrations on startup. It tries connecting to the DB given in
CONFIG_DATABASE_URI
and fetch the current DB config version from theversion
table. If that table isn't there (empty DB) or the version is older then the current one, the UI process triggers the same setup procedure thatpgadmin4-setup
does, eventually callinguser_info_server
inpgadmin.setup.user_info
. Here's the call trace for the case when the DB is empty:Now
user_info_server
tries reading the initial user and password from thePGADMIN_SETUP_EMAIL
andPGADMIN_SETUP_PASSWORD
env vars, respectively.So in principle we don't need
pgadmin4-setup
, which would simplify our bootstrap procedure. We could have just a single PgAdmin service with anExecStartPre
directive to create the PgAdmin role and DB, assign that role perms to read/write Odoo tables, and install the function to fetch DB connection params;ExecStartPost
directive to create or update the built-in UI server connection to the local Postgres service.If we do this, we could easily implement #14 too.