2018-10-23 09:38:02 +02:00
|
|
|
-- LegacyWorlds Beta 6
|
|
|
|
-- PostgreSQL database scripts
|
|
|
|
--
|
|
|
|
-- Main database script
|
|
|
|
--
|
|
|
|
-- Initialises the various roles and the database itself,
|
|
|
|
-- then processes scripts from the "parts" directory.
|
|
|
|
--
|
|
|
|
-- Copyright(C) 2004-2010, DeepClone Development
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
|
2025-01-03 16:48:13 +01:00
|
|
|
-- Set configuration defaults
|
|
|
|
\set pgadmin postgres
|
|
|
|
\set dbname lwb6
|
|
|
|
\set dbuser lwb6
|
|
|
|
-- Read configuration from environment vars
|
|
|
|
\getenv pgadmin DB_ADMIN
|
|
|
|
\getenv dbname LW_DB_NAME
|
|
|
|
\getenv dbuser LW_DB_USER
|
|
|
|
\getenv dbupass LW_DB_USER_PASS
|
2018-10-23 09:38:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- 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
|
2025-01-03 16:48:13 +01:00
|
|
|
CREATE ROLE :dbuser WITH LOGIN ENCRYPTED PASSWORD :'dbupass';
|
2018-10-23 09:38:02 +02:00
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
|
|
|
-- Register PL/PgSQL
|
|
|
|
CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql;
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2025-01-03 16:48:13 +01:00
|
|
|
COMMIT;
|