diff --git a/sql/00-init.sql b/sql/00-init.sql index c7b121b..a103834 100644 --- a/sql/00-init.sql +++ b/sql/00-init.sql @@ -14,32 +14,13 @@ SET search_path=public; -- Create the LW users -CREATE ROLE legacyworlds WITH LOGIN ENCRYPTED PASSWORD 'main user password'; -CREATE ROLE legacyworlds_admin WITH LOGIN ENCRYPTED PASSWORD 'administration user password' CONNECTION LIMIT 2; +CREATE ROLE legacyworlds WITH LOGIN ENCRYPTED PASSWORD :'db_user_pass'; +CREATE ROLE legacyworlds_admin WITH LOGIN ENCRYPTED PASSWORD :'db_admin_pass' CONNECTION LIMIT 2; -- Create the database CREATE DATABASE legacyworlds WITH OWNER=legacyworlds_admin ENCODING='UTF8'; - --- Connect to the LW database with the PostgreSQL admin user -\c legacyworlds postgres - --- Register PL/PgSQL's handler function -CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler AS - '$libdir/plpgsql' LANGUAGE C; - --- Register PL/PgSQL's validator function -CREATE FUNCTION plpgsql_validator(oid) RETURNS void AS - '$libdir/plpgsql' LANGUAGE C; - --- Register PL/PgSQL -CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql - HANDLER plpgsql_call_handler - VALIDATOR plpgsql_validator; - - - -- Connect to the LW database with the LW admin user \c legacyworlds legacyworlds_admin diff --git a/sql/12-main-tables.sql b/sql/12-main-tables.sql index 2780cd3..491df0e 100644 --- a/sql/12-main-tables.sql +++ b/sql/12-main-tables.sql @@ -16,7 +16,7 @@ --- +-- -- Create the account table -- @@ -55,9 +55,9 @@ CREATE TABLE main.reg_queue ( GRANT SELECT,INSERT,DELETE ON main.reg_queue TO legacyworlds; --- +-- -- Create the table that stores kick requests --- +-- CREATE TABLE main.adm_kick ( id BIGSERIAL PRIMARY KEY, @@ -138,9 +138,9 @@ GRANT SELECT,INSERT,DELETE ON TABLE main.account_log TO legacyworlds; GRANT SELECT,UPDATE ON main.account_log_id_seq TO legacyworlds; --- +-- -- Create the table that stores cache references --- +-- CREATE TABLE main.web_cache ( id BIGSERIAL PRIMARY KEY, @@ -154,10 +154,10 @@ GRANT SELECT,INSERT,UPDATE,DELETE ON TABLE main.web_cache TO legacyworlds; GRANT SELECT,UPDATE ON main.web_cache_id_seq TO legacyworlds; --- +-- -- Tables that will store rankings definitions, texts, and -- game relations --- +-- -- Definitions CREATE TABLE main.ranking_def ( @@ -194,9 +194,9 @@ CREATE TABLE main.ranking_game ( GRANT SELECT ON TABLE main.ranking_game TO legacyworlds; --- +-- -- Table that will store the rankings themselves --- +-- CREATE TABLE main.ranking ( r_type BIGINT NOT NULL REFERENCES main.ranking_game (id) ON DELETE CASCADE, id VARCHAR(32) NOT NULL, @@ -221,3 +221,14 @@ CREATE TABLE main.user_preferences ( ); GRANT SELECT,INSERT,UPDATE,DELETE ON TABLE main.user_preferences TO legacyworlds; + +-- +-- Table for contribution credits +-- +CREATE TABLE main.credits ( + account BIGINT NOT NULL PRIMARY KEY REFERENCES main.account (id) ON DELETE CASCADE, + resources_used INT NOT NULL DEFAULT 0 CHECK(resources_used >= 0), + credits_obtained INT NOT NULL DEFAULT 9000 +); + +GRANT SELECT,INSERT,UPDATE ON TABLE main.credits TO legacyworlds; diff --git a/sql/19-main-values.sql b/sql/19-main-values.sql index 93f77cf..9d4bf88 100644 --- a/sql/19-main-values.sql +++ b/sql/19-main-values.sql @@ -14,13 +14,23 @@ \c legacyworlds legacyworlds_admin +-- +-- Initial admin account +-- + +INSERT INTO main.account (name, email, password, status, vac_credits, last_login, last_logout, admin) + VALUES (:'admin_name', :'admin_mail', :'admin_password', 'STD', 240, + UNIX_TIMESTAMP(NOW()), UNIX_TIMESTAMP(NOW()) + 1, 't'); +INSERT INTO main.credits (account, credits_obtained) + VALUES ((SELECT id FROM main.account WHERE name = :'admin_name'), 1000000000); + -- -- Peacekeepers AI -- INSERT INTO main.account (name, email, password, status, vac_credits, last_login, last_logout, admin) VALUES ('AI>Peacekeepers', 'not-a-valid-email@not-a-valid-domain.com', - '[-jv&VCR3B-b}F75qS["lpBDk8C[v~DU78Oc}=6WROXt)b+&U7[ZbNRb[d0', 'STD', 240, + :'peacekeepers_password', 'STD', 240, UNIX_TIMESTAMP(NOW()), UNIX_TIMESTAMP(NOW()) + 1, 't'); diff --git a/sql/20-credits.sql b/sql/20-credits.sql deleted file mode 100644 index 86295b7..0000000 --- a/sql/20-credits.sql +++ /dev/null @@ -1,18 +0,0 @@ --- LegacyWorlds Beta 5 --- PostgreSQL database scripts --- --- 20-credits.sql --- --- Initialises the tables that store credits --- --- Copyright(C) 2004-2007, DeepClone Development --- -------------------------------------------------------- - - -CREATE TABLE main.credits ( - account BIGINT NOT NULL PRIMARY KEY REFERENCES main.account (id) ON DELETE CASCADE, - resources_used INT NOT NULL DEFAULT 0 CHECK(resources_used >= 0), - credits_obtained INT NOT NULL DEFAULT 9000 -); - -GRANT SELECT,INSERT,UPDATE ON TABLE main.credits TO legacyworlds; diff --git a/sql/INSTALL.sql b/sql/INSTALL.sql index 78c258e..d34ef28 100644 --- a/sql/INSTALL.sql +++ b/sql/INSTALL.sql @@ -8,6 +8,16 @@ -- Copyright(C) 2004-2007, DeepClone Development -- -------------------------------------------------------- + +-- Get all parameters from the environment +\getenv db_user_pass LW_DB_USER_PASS +\getenv db_admin_pass LW_DB_ADMIN_PASS +\getenv admin_name LW_ADMIN_NAME +\getenv admin_mail LW_ADMIN_MAIL +\getenv admin_password LW_ADMIN_PASSWORD +\getenv peacekeepers_password LW_PEACEKEEPERS_PASSWORD + + \i 00-init.sql \i 01-inheritance.sql \i 10-main.sql @@ -20,7 +30,6 @@ \i 13-main-proxy.sql \i 18-main-functions.sql \i 19-main-values.sql -\i 20-credits.sql \i 25-ctf-maps.sql \i 25-death-of-rats.sql \i 25-predefined-alliances.sql diff --git a/sql/beta5/structure/01-message-base.sql b/sql/beta5/structure/01-message-base.sql index d26d0d6..7161afd 100644 --- a/sql/beta5/structure/01-message-base.sql +++ b/sql/beta5/structure/01-message-base.sql @@ -42,4 +42,4 @@ CREATE INDEX message_reply_to ON message (reply_to); CREATE INDEX message_original ON message (original); GRANT INSERT,SELECT,UPDATE ON message TO legacyworlds; -GRANT INSERT,SELECT,UPDATE ON message_id_seq TO legacyworlds; +GRANT SELECT,UPDATE ON message_id_seq TO legacyworlds;