This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to generate your dhparam.pem file, run in the terminal | |
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER account_audit_trigger | |
AFTER INSERT OR UPDATE OR DELETE ON account | |
FOR EACH ROW EXECUTE PROCEDURE account_audit_func(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION account_audit_func() | |
RETURNS TRIGGER | |
AS $$ | |
BEGIN | |
IF TG_OP = 'INSERT' THEN | |
INSERT INTO account_audit (operation, account_id, account_name, debt, balance) VALUES | |
(TG_OP, NEW.*); | |
RETURN NEW; | |
ELSIF TG_OP = 'UPDATE' THEN | |
INSERT INTO account_audit (operation, account_id, account_name, debt, balance) VALUES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE account ( | |
id serial primary key, | |
name text, | |
debt int, | |
balance int | |
); | |
CREATE TABLE account_audit( | |
id serial primary key, | |
db_user text NOT NULL default session_user, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER passwd_trigger BEFORE INSERT OR UPDATE | |
ON passwd | |
FOR EACH ROW EXECUTE PROCEDURE passwd_func(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION passwd_func() | |
RETURNS TRIGGER | |
AS $$ | |
BEGIN | |
IF length(NEW.password) < 10 OR NEW.password IS NULL THEN | |
RAISE EXCEPTION 'password cannot be less than 10 characters'; | |
END IF; | |
IF NEW.NAME IS NULL THEN | |
RAISE EXCEPTION 'Name cannot be NULL'; | |
END IF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE passwd ( | |
id serial primary key, | |
name text, | |
password text, | |
position text | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION car_bonus_func(vehicle_id int, bonus int) | |
RETURNS cars | |
AS $$ | |
DECLARE | |
car cars; | |
BEGIN | |
PERFORM model FROM cars WHERE car_id = vehicle_id; | |
IF NOT FOUND THEN | |
RAISE EXCEPTION 'car with id of % not found', vehicle_id; | |
END IF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION quarterly_summary_func(start_date date DEFAULT CURRENT_TIMESTAMP) | |
RETURNS TABLE (staff_name text, staff_bonus int, quarter tsrange) | |
As $$ | |
DECLARE | |
employee RECORD; | |
total_bonus int; | |
sales_total int; | |
end_date date := start_date + interval '3 months'; | |
BEGIN | |
FOR employee IN SELECT staff_id FROM staff LOOP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE staff ( | |
staff_id serial primary key, | |
name text, | |
salary int, | |
created_at timestamp with time zone default now() | |
); | |
CREATE TABLE cars( | |
car_id serial primary key, | |
brand text, |
NewerOlder