Emmanuel BENOîT
e50775ec76
* 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
51 lines
No EOL
1.4 KiB
PL/PgSQL
51 lines
No EOL
1.4 KiB
PL/PgSQL
-- LegacyWorlds Beta 6
|
|
-- PostgreSQL database scripts
|
|
--
|
|
-- Main database loader script
|
|
--
|
|
-- Initialises the various roles and the database itself,
|
|
-- then processes scripts from the "parts" directory.
|
|
--
|
|
-- Copyright(C) 2004-2012, DeepClone Development
|
|
-- --------------------------------------------------------
|
|
|
|
-- Read configuration from file
|
|
\set pgadmin `grep ^admin= db-config.txt | sed -e s/.*=//`
|
|
\set dbname `grep ^db= db-config.txt | sed -e s/.*=//`
|
|
\set dbname_string '''':dbname''''
|
|
\set dbuser `grep ^user= db-config.txt | sed -e s/.*=//`
|
|
\set dbuser_string '''':dbuser''''
|
|
\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
|
|
|
|
-- Drop the database and users if they exist
|
|
DROP DATABASE IF EXISTS :dbname;
|
|
DROP ROLE IF EXISTS :dbuser;
|
|
|
|
-- Create the LW users
|
|
CREATE ROLE :dbuser WITH LOGIN ENCRYPTED PASSWORD :dbupass;
|
|
|
|
-- Create the database
|
|
CREATE DATABASE :dbname ENCODING='UTF8' TEMPLATE=template0;
|
|
GRANT CONNECT ON DATABASE :dbname TO :dbuser;
|
|
|
|
|
|
-- Connect to the LW database with the PostgreSQL admin user
|
|
\c :dbname :pgadmin
|
|
|
|
/* Load everything from the loader script */
|
|
BEGIN;
|
|
\i loader.tmp
|
|
COMMIT;
|
|
|
|
/* Delete loader script */
|
|
\! rm loader.tmp |