Skip to content

Commit f2ef35a

Browse files
Create SQL files for managing dev schema
1 parent f397396 commit f2ef35a

11 files changed

+217
-159
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- AUTHOR: Eric MIlgram, PhD
2+
--
3+
-- DATE: 08 Dec 2021
4+
--
5+
-- PURPOSE
6+
-- The purpose of these SQL statements is to properly set up required
7+
-- schemas and tables for the PostgreSQL database used for the
8+
-- Paylocity Coding Challenge.
9+
--
10+
-- ############################################################################
11+
-- Create the 'dev' schema, which is for DB development only
12+
-- ############################################################################
13+
CREATE SCHEMA dev;
14+
15+
COMMENT ON SCHEMA dev IS 'The dev schema for Paylocity Coding Challenge developers';
16+
17+
SET search_path TO dev;
18+
19+
CREATE TABLE IF NOT EXISTS Company
20+
(
21+
guid uuid PRIMARY KEY,
22+
name varchar(50) NOT NULL UNIQUE,
23+
status integer NOT NULL
24+
);
25+
26+
27+
-- ############################################################################
28+
-- Create the Position table
29+
-- ############################################################################
30+
CREATE TABLE IF NOT EXISTS Position
31+
(
32+
guid uuid PRIMARY KEY,
33+
name varchar(50) NOT NULL UNIQUE,
34+
status integer NOT NULL
35+
);
36+
37+
-- ############################################################################
38+
-- Create the Employee table
39+
-- ############################################################################
40+
CREATE TABLE IF NOT EXISTS Employee
41+
(
42+
guid uuid PRIMARY KEY,
43+
state varchar(50) NOT NULL,
44+
status integer NOT NULL
45+
);
46+
47+
-- ############################################################################
48+
-- Create the Job table
49+
-- ############################################################################
50+
CREATE TABLE IF NOT EXISTS Job
51+
(
52+
guid uuid NOT NULL,
53+
company_guid uuid NOT NULL,
54+
position_guid uuid NOT NULL,
55+
employee_guid uuid NOT NULL,
56+
CONSTRAINT Job_PK PRIMARY KEY (guid),
57+
CONSTRAINT Job_FK_company_guid FOREIGN KEY (company_guid) REFERENCES Company (guid),
58+
CONSTRAINT Job_FK_position_guid FOREIGN KEY (position_guid) REFERENCES Position (guid),
59+
CONSTRAINT Job_FK_employee_guid FOREIGN KEY (employee_guid) REFERENCES Employee (guid),
60+
CONSTRAINT Job_unique_comp_pos_emp UNIQUE (company_guid, position_guid, employee_guid)
61+
);
62+
63+
COMMENT ON CONSTRAINT Job_unique_comp_pos_emp ON Job
64+
IS 'Prevent same person from having same job at same company';
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- ############################################################################
2+
-- CREATE pccdev ROLE, then GRANT the ROLE permission to connect to the DB.
3+
-- ############################################################################
4+
CREATE ROLE pccdev;
5+
6+
GRANT CONNECT
7+
ON DATABASE paylocity
8+
TO pccdev;
9+
10+
-- ############################################################################
11+
-- GRANT the pccdev ROLE the necessary permissions for
12+
-- using the 'dev' SCHEMA.
13+
-- ############################################################################
14+
GRANT USAGE, CREATE
15+
ON SCHEMA dev
16+
TO pccdev;
17+
18+
GRANT
19+
ALL PRIVILEGES
20+
ON ALL TABLES
21+
IN SCHEMA dev
22+
TO pccdev;
23+
24+
ALTER DEFAULT PRIVILEGES
25+
IN SCHEMA dev
26+
GRANT ALL PRIVILEGES
27+
ON TABLES
28+
TO pccdev;
29+
30+
GRANT USAGE
31+
ON ALL SEQUENCES
32+
IN SCHEMA dev
33+
TO pccdev;
34+
35+
ALTER DEFAULT PRIVILEGES
36+
IN SCHEMA dev
37+
GRANT USAGE
38+
ON SEQUENCES
39+
TO pccdev;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- ############################################################################
2+
-- Create the first user of the 'dev' schema.
3+
-- ############################################################################
4+
CREATE USER emilgram WITH PASSWORD 'CHANGE_ON_FIRST_LOGIN';
5+
6+
-- ############################################################################
7+
-- Grant privileges to users
8+
-- ############################################################################
9+
GRANT pccdev TO emilgram;
10+
11+
ALTER ROLE emilgram
12+
IN DATABASE paylocity
13+
SET search_path TO dev;
14+
15+
-- ############################################################################
16+
-- CREATE Table: Company
17+
-- ############################################################################
18+
SET SCHEMA 'dev';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- ############################################################################
2+
-- WARNING: THIS SCRIPT WILL ERASE THE 'dev' SCHEMA CREATED FOR THE
3+
-- PAYLOCITY CODING CHALLENGE, WHICH INCLUDES THE TABLES. IT WILL ALSO
4+
-- ERASE THE ROLES AND USERS CREATED BY THE SET-UP SCRIPT.
5+
--
6+
-- IF THE DATBASE THROWS AN ERROR WHILE TRYING TO RUN THIS SCRIPT, THEN
7+
-- UNEXPECTED CHANGES HAVE BEEN MADE TO THE 'dev' SCHEMA. TO RESOLVE SUCH
8+
-- CONFLICTS, PLEASE CONSULT A POSTGRESQL DBA TO HELP YOU.
9+
-- ############################################################################
10+
11+
REVOKE ALL PRIVILEGES
12+
ON SCHEMA dev
13+
FROM emilgram;
14+
15+
DROP USER emilgram;
16+
17+
REVOKE ALL PRIVILEGES
18+
ON SCHEMA dev
19+
FROM pccdev;
20+
21+
REVOKE ALL PRIVILEGES
22+
ON DATABASE paylocity
23+
FROM pccdev;
24+
25+
DROP SCHEMA dev CASCADE;
26+
27+
DROP ROLE pccdev;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- AUTHOR: Eric MIlgram, PhD
2+
--
3+
-- DATE: 09 Dec 2021
4+
--
5+
-- PURPOSE
6+
-- The purpose of these SQL statements is to insert record data
7+
-- into the 'company', 'position', 'employee', and 'job' tables in
8+
-- the 'dev' schema for the PostgreSQL database used for the
9+
-- Paylocity Coding Challenge.
10+
--
11+
-- ############################################################################
12+
-- Be sure to set the correct value for the schema.
13+
-- ############################################################################
14+
SET search_path TO dev;
15+
16+
17+
-- ############################################################################
18+
-- Start the transaction before any inserts and only commit it if all
19+
-- inserts work properly.
20+
-- ############################################################################
21+
BEGIN TRANSACTION;
22+
23+
INSERT INTO Company
24+
(guid, name, status)
25+
VALUES
26+
('{4c948630-bce9-4aae-ae6d-9898f3539dab}', 'My Test Company 1', 1),
27+
('{78bffbd2-c6db-441f-b981-f92813e1791b}', 'My Test Company 2', 1),
28+
('{ab447037-2255-4882-826b-56f598baba71}', 'My Test Company 3', 1),
29+
('{5a2d1bf8-9367-4f07-9643-64e08dd0e874}', 'My Test Company 4', 1),
30+
('{38a41864-38b6-4a28-b742-5f5ecfe6ad17}', 'My Test Company 5', 1);
31+
32+
INSERT INTO Position
33+
(guid, name, status)
34+
VALUES
35+
('{0550f13e-76d0-4b8e-99bf-fb3f16429f9b}', 'Data Scientist 1', 1),
36+
('{5b22cf08-a93e-4457-a869-203cc1e6370e}', 'Data Scientist 2', 1),
37+
('{5781d41f-cc64-469b-aba8-637b0204a096}', 'Data Scientist 3', 1),
38+
('{041ce313-3b4e-40ca-bcc7-4ba348a60d85}', 'Business Analyst 1', 1),
39+
('{b8121811-ca23-4209-a981-20651ec16200}', 'Business Analyst 2', 1),
40+
('{df4e534f-82e7-46b2-be90-5829e26eb5bb}', 'Program Manager 1', 1),
41+
('{db7e3090-38bc-49bd-803c-d047be20600c}', 'Program Manager 2', 1),
42+
('{7325831e-7701-42d7-87a0-bdc144cf0558}', 'Systems Architect 1', 1),
43+
('{e1b37547-5899-46cd-8af5-2bcf421d0a43}', 'Systems Architect 2', 1);
44+
45+
INSERT INTO Employee
46+
(guid, state, status)
47+
VALUES
48+
('{1d1ca01f-1ada-4463-817b-79e15ffd9875}', 'NY', 3),
49+
('{d0d46dba-e96e-4401-b4d9-d8c8c3e7119e}', 'MN', 1),
50+
('{13ef8f03-daa0-46a0-8b66-720ea84bc12f}', 'CA', 1),
51+
('{5908c141-12d1-4ff5-9f8f-12c1ef71f430}', 'IA', 3),
52+
('{88f9ddd6-cfa1-4201-9268-4c0dcff9c017}', 'LA', 1),
53+
('{d9537cf4-02a6-4900-805c-cd214a31a6e8}', 'GA', 3),
54+
('{baa94efd-fea0-4065-b0f1-98cd1a74a8bf}', 'CA', 2),
55+
('{e6878e0a-a8b9-40cc-b73b-530096c7401d}', 'IL', 2);
56+
57+
INSERT INTO JOB
58+
(guid, company_guid, position_guid, employee_guid)
59+
VALUES
60+
('{75db0af2-ef36-4c9d-a7c1-0549eb3e24e9}', '{78bffbd2-c6db-441f-b981-f92813e1791b}', '{df4e534f-82e7-46b2-be90-5829e26eb5bb}', '{1d1ca01f-1ada-4463-817b-79e15ffd9875}'),
61+
('{2ee639aa-035a-4dfe-a3ed-e11d5a4b6a30}', '{4c948630-bce9-4aae-ae6d-9898f3539dab}', '{df4e534f-82e7-46b2-be90-5829e26eb5bb}', '{d0d46dba-e96e-4401-b4d9-d8c8c3e7119e}'),
62+
('{adc12833-475e-4027-8fe8-d7845381b867}', '{4c948630-bce9-4aae-ae6d-9898f3539dab}', '{7325831e-7701-42d7-87a0-bdc144cf0558}', '{13ef8f03-daa0-46a0-8b66-720ea84bc12f}'),
63+
('{caa7ba66-f120-45fb-808f-2e0e16aae2bc}', '{4c948630-bce9-4aae-ae6d-9898f3539dab}', '{5781d41f-cc64-469b-aba8-637b0204a096}', '{5908c141-12d1-4ff5-9f8f-12c1ef71f430}'),
64+
('{5f6cdd10-de9c-430a-9143-45b79eba7e44}', '{5a2d1bf8-9367-4f07-9643-64e08dd0e874}', '{7325831e-7701-42d7-87a0-bdc144cf0558}', '{88f9ddd6-cfa1-4201-9268-4c0dcff9c017}'),
65+
('{9347dea5-fcfa-48e1-8efd-af486d0fe575}', '{78bffbd2-c6db-441f-b981-f92813e1791b}', '{b8121811-ca23-4209-a981-20651ec16200}', '{d9537cf4-02a6-4900-805c-cd214a31a6e8}'),
66+
('{f36be466-2b5b-4404-a864-8de1dea27f10}', '{38a41864-38b6-4a28-b742-5f5ecfe6ad17}', '{5781d41f-cc64-469b-aba8-637b0204a096}', '{baa94efd-fea0-4065-b0f1-98cd1a74a8bf}'),
67+
('{240fecb7-b6eb-4f33-b526-ba65cc097c43}', '{78bffbd2-c6db-441f-b981-f92813e1791b}', '{041ce313-3b4e-40ca-bcc7-4ba348a60d85}', '{e6878e0a-a8b9-40cc-b73b-530096c7401d}');
68+
69+
COMMIT TRANSACTION;

code/SQL/100-000 DB SETUP - CREATE SCHEMA.sql

Lines changed: 0 additions & 99 deletions
This file was deleted.

code/SQL/100-010 DB SETUP - CREATE TABLE Company.sql

Lines changed: 0 additions & 11 deletions
This file was deleted.

code/SQL/100-020 DB SETUP - CREATE TABLE Position.sql

Lines changed: 0 additions & 11 deletions
This file was deleted.

code/SQL/100-030 DB SETUP - CREATE TABLE Employee.sql

Lines changed: 0 additions & 11 deletions
This file was deleted.

code/SQL/100-040 DB SETUP - CREATE TABLE Job.sql

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)