Database definition & tests organisation
* The main loader script has been updated to generate the list of files it needs to load automatically. As a consequence, files that contained manually-maintained lists of scripts have been removed, and definition directories have been renamed accordingly. * PostgreSQL extension loading and configuration has been moved to a separate script to be loaded automatically in the main transaction. * Data and function definition scripts that had the -data or -functions suffix have been renamed (the suffix is unnecessary). * Unit tests have been reorganised to follow the definition's structure. * Documentation has been improved
This commit is contained in:
parent
b054a379a9
commit
e50775ec76
112 changed files with 78 additions and 144 deletions
legacyworlds-server-data/db-structure
|
@ -1,12 +1,12 @@
|
|||
-- LegacyWorlds Beta 6
|
||||
-- PostgreSQL database scripts
|
||||
--
|
||||
-- Main database script
|
||||
-- Main database loader script
|
||||
--
|
||||
-- Initialises the various roles and the database itself,
|
||||
-- then processes scripts from the "parts" directory.
|
||||
--
|
||||
-- Copyright(C) 2004-2010, DeepClone Development
|
||||
-- Copyright(C) 2004-2012, DeepClone Development
|
||||
-- --------------------------------------------------------
|
||||
|
||||
-- Read configuration from file
|
||||
|
@ -18,6 +18,12 @@
|
|||
\set dbupass ''''`grep ^password= db-config.txt | sed -e s/.*=// -e "s/'/''/g"`''''
|
||||
|
||||
|
||||
/* List all files in the "parts" directory and create a loader script from
|
||||
* that.
|
||||
*/
|
||||
\! find parts -type f -name '*.sql' | sort | sed -e 's/^/\\i /' > loader.tmp
|
||||
|
||||
|
||||
-- Connect to the main system database
|
||||
\c postgres :pgadmin
|
||||
|
||||
|
@ -36,34 +42,10 @@ GRANT CONNECT ON DATABASE :dbname TO :dbuser;
|
|||
-- Connect to the LW database with the PostgreSQL admin user
|
||||
\c :dbname :pgadmin
|
||||
|
||||
-- Register the dblink extension
|
||||
CREATE EXTENSION dblink;
|
||||
|
||||
-- Create foreign data wrapper and server used to write logs from within
|
||||
-- transanctions
|
||||
CREATE FOREIGN DATA WRAPPER pgsql
|
||||
VALIDATOR postgresql_fdw_validator;
|
||||
CREATE SERVER srv_logging
|
||||
FOREIGN DATA WRAPPER pgsql
|
||||
OPTIONS ( hostaddr '127.0.0.1' , dbname :dbname_string );
|
||||
CREATE USER MAPPING FOR :dbuser
|
||||
SERVER srv_logging
|
||||
OPTIONS ( user :dbuser_string , password :dbupass );
|
||||
GRANT USAGE ON FOREIGN SERVER srv_logging TO :dbuser;
|
||||
|
||||
|
||||
/* Load everything from the loader script */
|
||||
BEGIN;
|
||||
\i loader.tmp
|
||||
COMMIT;
|
||||
|
||||
-- Create database schemas
|
||||
\i parts/000-schemas.sql
|
||||
|
||||
-- Process structure definition scripts
|
||||
\i parts/010-data.sql
|
||||
|
||||
-- Process functions and views definition scripts
|
||||
\i parts/020-functions.sql
|
||||
|
||||
-- Process game update functions
|
||||
\i parts/030-updates.sql
|
||||
|
||||
COMMIT;
|
||||
/* Delete loader script */
|
||||
\! rm loader.tmp
|
Reference in a new issue