feat: read parameters from env in SQL scripts

This commit is contained in:
Emmanuel BENOîT 2025-01-02 14:03:02 +01:00
parent 99511fe11f
commit 2523581537
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
6 changed files with 44 additions and 51 deletions

View file

@ -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

View file

@ -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;

View file

@ -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');

View file

@ -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;

View file

@ -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

View file

@ -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;