#
# README-DB-VERSIONING.txt
#

#
# WARNING: Information in this file inteded for the internal use of PipelineFX
# LLC's Qube developers. Any and all of Qube's internal workings, including
# the DB schema and how it's maintained, are subject to change without notice.
#

The PostgreSQL schema (table definitions, etc) are set up using the
qubedb*.sql files found in this directory, $QBDIR/utils/pgsql. More precisely,
the init_supe_db.py script is the "driver" that calls PostgreSQL's "psql"
command to execute the qubedb_*.sql files in the appropriate order (and under
the proper user account), taking into account the current schema version
stored in the "qube.tableversion" table.

These are the files in this directory that are used to initialize and maintain
the PostgreSQL database server and its data for the Qube supervisor.

init_supe_db.py:

	Python "driver" script that calls the psql command with the *.sql scripts
	to prepare the PostgreSQL DB for Qube.

qubedb_prep.sql:
qubedb_prep_####.sql:
qubedb_####.sql:

	These scripts are used by init_supe_db.py via psql to initialze and/or
	upgrade the DB by creating/altering tables, schema, and adding initial
	data.

	qubedb_prep.sql is run the very first time that the PGSQL DB server is
	installed by the supervisor package via init_supe_db.py, to create the
	"qube" role and the "pfx" database.

	The other *.sql files have the DB schema version number in the file names,
	like qubedb_0051.sql and qubedb_prep_0053.sql. When a new version of Qube
	supervisor is released, this version number is incremented if there were
	DB schema changes. For the initial PostgreSQL-based release, Qube 7.0-0,
	this DB version number is "51" (padded to "0051" in the .sql file name).

	The init_supe_db.py script is normally run by the supervisor installation
	process. In turn, it runs the qubedb_prep_####.sql, if it exists, via the
	"psql" command, , under the DB's administrator user "pfx" first. Then,
	qubedb_####.sql is run under the "qube" user.

	Once released, qubedb_*.sql files should not be altered. Instead, a new
	version must be created for the next release. For instance,
	qubedb_0051.sql was released with Qube 7.0-0, so any DB schema changes
	required for the next release, Qube 7.0-1, was implemented in a separate
	file, qubedb_0052.sql.

	Refer to the init_supe_db.py script itself, and the individual
	qubedb_*.sql for more details.

