From d36fbbde9a4c7c17c3dbdd029b5bcd5a613e66cf Mon Sep 17 00:00:00 2001 From: Chord Date: Mon, 30 Dec 2019 14:36:00 -0500 Subject: [PATCH] Add schema and readme --- README.md | 53 +++++++++++++++++++++++++++++++++++ db/schema.sql | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 db/schema.sql diff --git a/README.md b/README.md new file mode 100644 index 0000000..deed2eb --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# PSFPortal +An API + webapp to manage PSForever accounts, characters, and servers. + +## Features +* User registration, login, and sessions +* Home page +* Admin management + +### Upcoming Features +* Email verification + captcha +* Changing passwords +* WorldServer mangement + +## Developing +This requires a relatively modern version of Node that supports async/await and ES6 (v13.x+). Tested using v13.3.0. You may still get `(node:61412) ExperimentalWarning: The ESM module loader is experimental.`. Ignore this as ESM is essentially stable in recent versions. + +First download and install the Node dependencies: +``` +git clone https://github.com/psforever/PSFPortal +cd PSFPortal/ +npm install +``` + +Next, install PostgreSQL from your package manager. +Load the DB schema into a fresh database (in this case named psforever): + +``` +psql psforever < db/schema.sql +``` + +Before running, you will need to create a `.env` file like this: + +``` +PGUSER=... +PGHOST=... +PGPASSWORD=... +PGDATABASE=... +PGPORT=... +COOKIE_SECRET= +``` + +Never share/release/commit your `.env` file. + +Finally, run the following commands: +``` +# Will start the frontend Webpack builder with hot reload +npm run dev +# And in another terminal, will start the backend server +npm run dev-server +``` + +## Production Running/Building +Follow the same steps as above, but instead run `npm run production` at the very end. diff --git a/db/schema.sql b/db/schema.sql new file mode 100644 index 0000000..9a3b493 --- /dev/null +++ b/db/schema.sql @@ -0,0 +1,77 @@ +CREATE TABLE IF NOT EXISTS "accounts" ( + "id" SERIAL PRIMARY KEY NOT NULL, + "username" VARCHAR(64) NOT NULL UNIQUE, + "passhash" VARCHAR(64) NOT NULL, + "created" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "last_modified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "inactive" BOOLEAN NOT NULL DEFAULT FALSE, + "gm" BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE TABLE IF NOT EXISTS "characters" ( + "id" SERIAL PRIMARY KEY NOT NULL, + "name" VARCHAR(64) NOT NULL, + "account_id" INT NOT NULL REFERENCES accounts (id), + "faction_id" INT NOT NULL, + "gender_id" INT NOT NULL, + "head_id" INT NOT NULL, + "voice_id" INT NOT NULL, + "created" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "last_login" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "last_modified" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE TABLE IF NOT EXISTS "logins" ( + "id" SERIAL PRIMARY KEY NOT NULL, + "account_id" INT NOT NULL REFERENCES accounts (id), + "login_time" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "ip_address" VARCHAR(32) NOT NULL, + "canonical_hostname" VARCHAR(132) NOT NULL, + "hostname" VARCHAR(132) NOT NULL, + "port" INT NOT NULL +); + +CREATE TABLE IF NOT EXISTS "loadouts" ( + "id" SERIAL PRIMARY KEY NOT NULL, + "characters_id" INT NOT NULL REFERENCES characters (id), + "loadout_number" INT NOT NULL, + "exosuit_id" INT NOT NULL, + "name" VARCHAR(36) NOT NULL, + "items" TEXT NOT NULL +); + +CREATE TABLE IF NOT EXISTS "lockers" ( + "id" SERIAL PRIMARY KEY NOT NULL, + "characters_id" INT NOT NULL REFERENCES characters (id), + "items" TEXT NOT NULL +); + +CREATE TABLE "session" ( + "sid" varchar NOT NULL COLLATE "default", + "sess" json NOT NULL, + "expire" timestamp(6) NOT NULL +) +WITH (OIDS=FALSE); +ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE; + +--These triggers update the last_modified timestamp column when a table is updated +CREATE OR REPLACE FUNCTION fn_set_last_modified_timestamp() +RETURNS TRIGGER AS $$ +BEGIN + NEW.last_modified = NOW(); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS trigger_accounts_set_last_modified on accounts; +CREATE TRIGGER trigger_accounts_set_last_modified +BEFORE UPDATE ON accounts +FOR EACH ROW +EXECUTE PROCEDURE fn_set_last_modified_timestamp(); + +DROP TRIGGER IF EXISTS trigger_players_set_last_modified on characters; +CREATE TRIGGER trigger_players_set_last_modified +BEFORE UPDATE ON characters +FOR EACH ROW +EXECUTE PROCEDURE fn_set_last_modified_timestamp(); diff --git a/package.json b/package.json index a5db348..7bed32e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "psfwebui", + "name": "psfportal", "version": "1.0.0", "type": "module", "description": "A web interface to PSForever servers.",