cavecomm/setupdb.sh

84 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
sudo -u postgres createuser -P -e cavecommadmin
sudo -u postgres createdb --owner=cavecommadmin cavecomm 'contains all the information for the cavecomm instance on this device'
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE cavecomm TO cavecommadmin;"
sudo -u postgres psql -c "CREATE TABLE requests(
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
customerName text,
customerEmailAddress text,
customerContactDetails text,
freelancerID INT,
templateID INT,
currencyPreference varchar(6),
priceUpFront decimal,
priceOnDeliver decimal,
requestDescription text,
accepted boolean,
upFrontInvoiceID text,
onDeliverInvoiceID text,
upFrontPaid boolean,
onDeliverPaid boolean,
completed boolean
);
" cavecomm
sudo -u postgres psql -c "CREATE TABLE freelancers(
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
emailAddress text UNIQUE NOT NULL,
salt text NOT NULL,
hash text NOT NULL,
name text,
generalInformation text,
basicInformation text,
stripeAccountInformation text,
commissionLimit int,
loginValidationKey text
);
" cavecomm
sudo -u postgres psql -c "CREATE TABLE templates(
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
freelancerID int,
name text NOT NULL,
content text,
contactData text,
contactInformation text,
currencyPreference text,
priceUpFront decimal,
priceOnDeliver decimal
);
" cavecomm
sudo -u postgres psql -c "CREATE TABLE cryptoWallets(
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
freelancerID int,
name text,
walletAddress text
);
" cavecomm
sudo -u postgres psql -c "CREATE TABLE passwordResetKeys(
freelancerEmail text PRIMARY KEY,
passwordResetKey text UNIQUE,
expiration timestamp
);
" cavecomm
sudo -u postgres psql -c "CREATE TABLE loginLockOut(
email text PRIMARY KEY,
attempts int,
expiration timestamp
);
" cavecomm
sudo -u postgres psql -c "CREATE TABLE aliasRoutes(
aliasName text PRIMARY KEY,
freelancerID int,
route text,
routeParameter text
);
" cavecomm
sudo -u postgres psql cavecomm -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to cavecommadmin;"
sudo -u postgres psql cavecomm -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to cavecommadmin;"
sudo -u postgres psql cavecomm -c "GRANT ALL ON ALL TABLES IN SCHEMA public to cavecommadmin;"