@tamu-dor/famis-db 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/actions.yml +16 -0
- package/docs/index.html +1453 -335
- package/docs.md +363 -190
- package/index.d.ts +619 -0
- package/index.js +56 -2
- package/package.json +3 -3
- package/readme.md +2 -2
- package/schemas/migrations/202102041628.sql +26 -0
- package/schemas/migrations/202102261131.sql +68 -0
- package/schemas/migrations/202104011516.sql +12 -0
- package/schemas/migrations/202104210829.sql +69 -0
- package/schemas/migrations/202104210926.sql +77 -0
- package/schemas/migrations/202105201344.sql +17 -0
- package/schemas/migrations/202105201355.sql +26 -0
- package/schemas/migrations/202105251323.sql +17 -0
- package/schemas/migrations/202106081436.sql +20 -0
- package/schemas/migrations/202106221333.sql +20 -0
- package/schemas/migrations/202107291406.sql +35 -0
- package/schemas/migrations/202108181427.sql +26 -0
- package/schemas/migrations/202110041133.sql +75 -0
- package/schemas/migrations/202110251113.sql +20 -0
- package/schemas/migrations/202111021104.sql +13 -0
- package/schemas/migrations/202111021110.sql +16 -0
- package/schemas/migrations/202111100901.sql +16 -0
- package/schemas/migrations/202111101041.sql +79 -0
- package/schemas/migrations/20211115.sql +71 -0
- package/schemas/migrations/202112171038.sql +89 -0
- package/schemas/migrations/202201211055.sql +97 -0
- package/schemas/migrations/202201211124.sql +24 -0
- package/schemas/migrations/202201261015.sql +17 -0
- package/schemas/migrations/202201311403.sql +91 -0
- package/schemas/migrations/202202081201.sql +41 -0
- package/schemas/migrations/202202081205.sql +45 -0
- package/schemas/migrations/202202141101.sql +21 -0
- package/schemas/migrations/202202141117.sql +76 -0
- package/schemas/migrations/202202151329.sql +21 -0
- package/schemas/migrations/202202171025.sql +4 -0
- package/schemas/migrations/20220225.sql +23 -0
- package/schemas/migrations/202203150618.sql +13 -0
- package/schemas/migrations/202204041316.sql +12 -0
- package/schemas/migrations/202204141018.sql +78 -0
- package/schemas/migrations/202204141301.sql +36 -0
- package/schemas/migrations/202205061236.sql +15 -0
- package/schemas/migrations/202206021248.sql +20 -0
- package/schemas/migrations/20220615.sql +39 -0
- package/schemas/migrations/202206291132.sql +15 -0
- package/schemas/migrations/202207290901.sql +31 -0
- package/schemas/migrations/202207290907.sql +26 -0
- package/schemas/migrations/202208241422.sql +21 -0
- package/schemas/migrations/202209141529.sql +21 -0
- package/schemas/migrations/202209300911.sql +35 -0
- package/schemas/migrations/202210111429.sql +35 -0
- package/schemas/migrations/202210111456.sql +57 -0
- package/schemas/migrations/202210171517.sql +23 -0
- package/schemas/migrations/202211091403.sql +26 -0
- package/schemas/migrations/202211091410.sql +26 -0
- package/schemas/migrations/202211091417.sql +31 -0
- package/schemas/migrations/202211161451.sql +81 -0
- package/schemas/migrations/202212141236.sql +37 -0
- package/schemas/migrations/202302201117.sql +73 -0
- package/schemas/migrations/202303081110.sql +78 -0
- package/schemas/migrations/202304191238.sql +12 -0
- package/schemas/migrations/202304271214.sql +7 -0
- package/schemas/schema.sql +57 -22
- package/change.txt +0 -123
- package/changes.md +0 -405
- package/famisDb.pdf +0 -0
- package/readme.wiki +0 -332
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
BEGIN;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE accounts_all ADD COLUMN srs boolean DEFAULT FALSE;
|
|
4
|
+
|
|
5
|
+
/* The accounts view was originally created as SELECT * FROM accounts_all, but
|
|
6
|
+
that was expanded to the column list as of creation time. To the column list
|
|
7
|
+
for selecting a subset and/or reordering, use:
|
|
8
|
+
select string_agg(column_name, ', ') from information_schema.columns where table_name='accounts_all'
|
|
9
|
+
and edit as desired.
|
|
10
|
+
|
|
11
|
+
Note that CREATE OR REPLACE VIEW can only add columns to the end; anything else
|
|
12
|
+
requires a DROP and CREATE (remember to recreate permissions).
|
|
13
|
+
*/
|
|
14
|
+
DROP VIEW accounts;
|
|
15
|
+
CREATE VIEW accounts AS
|
|
16
|
+
-- exclude the last_seen column; can optionally reorder columns
|
|
17
|
+
SELECT uid, account_number, campus_code, fiscal_year, account, support_account, budget_support_account, budget_account_number, title, expiration_date, status, uin, responsible_uin, department, setup_date, budget_access, abr_rule, idt_allowed, adloc_campus_code, adloc_department, adloc_name, preferred_first_name, first_name, middle_name, last_name, email, work_phone, active, default_bank, bank_override, srs
|
|
18
|
+
FROM accounts_all
|
|
19
|
+
WHERE last_seen = (SELECT MAX(last_seen) FROM accounts_all);
|
|
20
|
+
|
|
21
|
+
-- permissions copied from schema in dumpparser
|
|
22
|
+
ALTER VIEW public.accounts OWNER TO dba;
|
|
23
|
+
GRANT SELECT ON public.accounts TO famis;
|
|
24
|
+
-- The "upsert" operation (INSERT ... ON CONFLICT (key) DO UPDATE SET ...)
|
|
25
|
+
-- also needs SELECT and UPDATE permissions. Change: grant these on the
|
|
26
|
+
-- underlying table directly, and change the parser to insert there instead of
|
|
27
|
+
-- to the view.
|
|
28
|
+
GRANT SELECT, INSERT, UPDATE ON public.accounts_all TO famisparser;
|
|
29
|
+
-- The update_idt_allowed() procedure needs to query accounts.
|
|
30
|
+
GRANT SELECT ON public.accounts TO famisparser;
|
|
31
|
+
|
|
32
|
+
-- Replace function with procedure (it was created before postgres gained
|
|
33
|
+
-- stored procedure support).
|
|
34
|
+
DROP FUNCTION update_idt_allowed;
|
|
35
|
+
CREATE OR REPLACE PROCEDURE update_idt_allowed()
|
|
36
|
+
AS $$
|
|
37
|
+
DECLARE
|
|
38
|
+
row record;
|
|
39
|
+
allowed BOOLEAN := NULL;
|
|
40
|
+
BEGIN
|
|
41
|
+
FOR row IN SELECT uid, a.campus_code, default_bank, bank_override, alt_bank1, alt_bank2,
|
|
42
|
+
alt_bank3, alt_bank4, alt_bank5
|
|
43
|
+
FROM accounts a LEFT JOIN alt_bank ab ON a.campus_code = ab.campus_code AND a.account = ab.account
|
|
44
|
+
AND a.support_account = ab.support_account AND a.fiscal_year = ab.fiscal_year
|
|
45
|
+
LOOP
|
|
46
|
+
-- part 09 (TEEX) doesn't use FAMIS directly and is thus always forced AR
|
|
47
|
+
if row.campus_code = '09' then
|
|
48
|
+
allowed = FALSE;
|
|
49
|
+
elsif bank_idt(row.default_bank) then
|
|
50
|
+
allowed = TRUE;
|
|
51
|
+
elsif row.bank_override = TRUE then
|
|
52
|
+
if row.alt_bank1 IS NULL then
|
|
53
|
+
allowed = NULL;
|
|
54
|
+
elsif bank_idt(row.alt_bank1) OR bank_idt(row.alt_bank2)
|
|
55
|
+
OR bank_idt(row.alt_bank3) OR bank_idt(row.alt_bank4)
|
|
56
|
+
OR bank_idt(row.alt_bank5) then
|
|
57
|
+
allowed = TRUE;
|
|
58
|
+
else
|
|
59
|
+
allowed = FALSE;
|
|
60
|
+
end if;
|
|
61
|
+
else
|
|
62
|
+
allowed = FALSE;
|
|
63
|
+
end if;
|
|
64
|
+
|
|
65
|
+
-- update the underlying table directly
|
|
66
|
+
UPDATE accounts_all SET idt_allowed = allowed WHERE uid = row.uid;
|
|
67
|
+
END LOOP;
|
|
68
|
+
END;
|
|
69
|
+
$$ LANGUAGE plpgsql;
|
|
70
|
+
|
|
71
|
+
--COMMIT;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
-- Add Rigor and Reproducibility
|
|
2
|
+
-- Add Wilkerson, Macie Judy and provision for core
|
|
3
|
+
-- Add Zhang, Ke and provision for core
|
|
4
|
+
-- Provision DuBose, Candida for core
|
|
5
|
+
BEGIN TRANSACTION;
|
|
6
|
+
DO $$
|
|
7
|
+
DECLARE
|
|
8
|
+
core_id integer;
|
|
9
|
+
user_id integer;
|
|
10
|
+
system_id integer;
|
|
11
|
+
core_name CONSTANT varchar := 'IBT Rigor and Reproducibility';
|
|
12
|
+
core_contact CONSTANT varchar := 'Ke (Kurt) Zhang';
|
|
13
|
+
core_contact_email CONSTANT varchar := 'kzhang@tamu.edu';
|
|
14
|
+
core_email CONSTANT varchar := NULL;
|
|
15
|
+
core_address CONSTANT varchar := '2121 W. Holcombe
|
|
16
|
+
Houston, TX 77030';
|
|
17
|
+
core_phone CONSTANT varchar := '713-677-7476';
|
|
18
|
+
revenue_account CONSTANT varchar := '2328026000000';
|
|
19
|
+
part_number CONSTANT varchar := '23';
|
|
20
|
+
user1 CONSTANT varchar := 'f7386259c58616a0686fddcb2614010e';
|
|
21
|
+
user2 CONSTANT varchar := '57c8bbe8fc602a7fd5f204f780443857';
|
|
22
|
+
user3 CONSTANT varchar := '1bd645107a1b040cd187591af43a2680';
|
|
23
|
+
effective_date date := '2021-11-01';
|
|
24
|
+
BEGIN
|
|
25
|
+
SELECT id INTO STRICT system_id FROM public.system WHERE part = part_number;
|
|
26
|
+
IF NOT EXISTS (
|
|
27
|
+
SELECT 1 FROM public.cores WHERE facility = core_name
|
|
28
|
+
) THEN
|
|
29
|
+
INSERT INTO public.cores (facility, contact, "contactEmail",
|
|
30
|
+
"systemId", enabled, "coreEmail", "corePhone", "coreAddress")
|
|
31
|
+
VALUES (
|
|
32
|
+
core_name,
|
|
33
|
+
core_contact,
|
|
34
|
+
core_contact_email,
|
|
35
|
+
system_id,
|
|
36
|
+
TRUE,
|
|
37
|
+
core_email,
|
|
38
|
+
core_phone,
|
|
39
|
+
core_address
|
|
40
|
+
);
|
|
41
|
+
ELSE
|
|
42
|
+
UPDATE public.cores SET
|
|
43
|
+
contact = core_contact,
|
|
44
|
+
"contactEmail" = core_contact_email,
|
|
45
|
+
"systemId" = system_id,
|
|
46
|
+
enabled = TRUE,
|
|
47
|
+
"coreEmail" = core_email,
|
|
48
|
+
"corePhone" = core_phone,
|
|
49
|
+
"coreAddress" = core_address
|
|
50
|
+
WHERE facility = core_name;
|
|
51
|
+
END IF;
|
|
52
|
+
-- assign id to variable; STRICT requires exactly one row be found
|
|
53
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
54
|
+
|
|
55
|
+
IF NOT EXISTS (
|
|
56
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = core_id
|
|
57
|
+
) THEN
|
|
58
|
+
INSERT INTO public.core_accounts ("coreId", account, effective)
|
|
59
|
+
VALUES (core_id, revenue_account, effective_date);
|
|
60
|
+
ELSE
|
|
61
|
+
UPDATE public.core_accounts SET account = revenue_account, effective = effective_date
|
|
62
|
+
WHERE "coreId" = core_id AND effective = (SELECT MAX(effective)
|
|
63
|
+
FROM public.core_accounts WHERE "coreId" = core_id);
|
|
64
|
+
END IF;
|
|
65
|
+
|
|
66
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
67
|
+
INSERT INTO public.users ("userId") VALUES (user1)
|
|
68
|
+
ON CONFLICT DO NOTHING;
|
|
69
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
70
|
+
WHERE "userId" = user1;
|
|
71
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
72
|
+
ON CONFLICT DO NOTHING;
|
|
73
|
+
|
|
74
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
75
|
+
INSERT INTO public.users ("userId") VALUES (user2)
|
|
76
|
+
ON CONFLICT DO NOTHING;
|
|
77
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
78
|
+
WHERE "userId" = user2;
|
|
79
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
80
|
+
ON CONFLICT DO NOTHING;
|
|
81
|
+
|
|
82
|
+
-- user3 already exists; only insert permissions for user on core
|
|
83
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
84
|
+
WHERE "userId" = user3;
|
|
85
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
86
|
+
ON CONFLICT DO NOTHING;
|
|
87
|
+
|
|
88
|
+
END $$ ;
|
|
89
|
+
COMMIT;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
-- Add Mechanical Engineering Shared Services Facilities core
|
|
2
|
+
-- Provision Caldwell, Amy B for core
|
|
3
|
+
-- Add Galetka, Nicholas and provision for core
|
|
4
|
+
-- Provision Crouch, Christopher M for core
|
|
5
|
+
BEGIN TRANSACTION;
|
|
6
|
+
DO $$
|
|
7
|
+
DECLARE
|
|
8
|
+
core_id integer;
|
|
9
|
+
user_id integer;
|
|
10
|
+
system_id integer;
|
|
11
|
+
core_name CONSTANT varchar := 'Mechanical Engineering Shared Services Facilities';
|
|
12
|
+
old_name CONSTANT varchar := 'Mechanical Engineering Shared Service Facility';
|
|
13
|
+
core_contact CONSTANT varchar := 'Amy Caldwell';
|
|
14
|
+
core_contact_email CONSTANT varchar := 'amy@tamu.edu';
|
|
15
|
+
core_email CONSTANT varchar := 'meen-ar@tamu.edu';
|
|
16
|
+
core_address CONSTANT varchar := '3123 TAMU
|
|
17
|
+
College Station, TX 77843';
|
|
18
|
+
core_phone CONSTANT varchar := '979-845-1289';
|
|
19
|
+
revenue_account CONSTANT varchar := '0227061000000';
|
|
20
|
+
part_number CONSTANT varchar := '02';
|
|
21
|
+
user1 CONSTANT varchar := 'ba52eaee6e9af44695defdd27994e9bf';
|
|
22
|
+
user2 CONSTANT varchar := '7324ccb811bdcd2037a2c65989a4371a';
|
|
23
|
+
user3 CONSTANT varchar := 'cf76157fe60feaf0377beae43a077390';
|
|
24
|
+
effective_date date := '2021-12-01';
|
|
25
|
+
BEGIN
|
|
26
|
+
SELECT id INTO STRICT system_id FROM public.system WHERE part = part_number;
|
|
27
|
+
-- rename existing core
|
|
28
|
+
IF EXISTS (
|
|
29
|
+
SELECT 1 FROM public.cores WHERE facility = old_name
|
|
30
|
+
) THEN
|
|
31
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = old_name;
|
|
32
|
+
UPDATE public.cores SET facility = core_name WHERE id = core_id;
|
|
33
|
+
END IF;
|
|
34
|
+
|
|
35
|
+
IF NOT EXISTS (
|
|
36
|
+
SELECT 1 FROM public.cores WHERE facility = core_name
|
|
37
|
+
) THEN
|
|
38
|
+
INSERT INTO public.cores (facility, contact, "contactEmail",
|
|
39
|
+
"systemId", enabled, "coreEmail", "corePhone", "coreAddress")
|
|
40
|
+
VALUES (
|
|
41
|
+
core_name,
|
|
42
|
+
core_contact,
|
|
43
|
+
core_contact_email,
|
|
44
|
+
system_id,
|
|
45
|
+
TRUE,
|
|
46
|
+
core_email,
|
|
47
|
+
core_phone,
|
|
48
|
+
core_address
|
|
49
|
+
);
|
|
50
|
+
ELSE
|
|
51
|
+
UPDATE public.cores SET
|
|
52
|
+
contact = core_contact,
|
|
53
|
+
"contactEmail" = core_contact_email,
|
|
54
|
+
"systemId" = system_id,
|
|
55
|
+
enabled = TRUE,
|
|
56
|
+
"coreEmail" = core_email,
|
|
57
|
+
"corePhone" = core_phone,
|
|
58
|
+
"coreAddress" = core_address
|
|
59
|
+
WHERE facility = core_name;
|
|
60
|
+
END IF;
|
|
61
|
+
-- assign id to variable; STRICT requires exactly one row be found
|
|
62
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
63
|
+
|
|
64
|
+
IF NOT EXISTS (
|
|
65
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = core_id
|
|
66
|
+
) THEN
|
|
67
|
+
INSERT INTO public.core_accounts ("coreId", account, effective)
|
|
68
|
+
VALUES (core_id, revenue_account, effective_date);
|
|
69
|
+
ELSE
|
|
70
|
+
UPDATE public.core_accounts SET account = revenue_account, effective = effective_date
|
|
71
|
+
WHERE "coreId" = core_id AND effective = (
|
|
72
|
+
SELECT MAX(effective)
|
|
73
|
+
FROM public.core_accounts WHERE "coreId" = core_id);
|
|
74
|
+
END IF;
|
|
75
|
+
|
|
76
|
+
-- user1 already exists; only insert permissions for user on core
|
|
77
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
78
|
+
WHERE "userId" = user1;
|
|
79
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
80
|
+
ON CONFLICT DO NOTHING;
|
|
81
|
+
|
|
82
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
83
|
+
INSERT INTO public.users ("userId") VALUES (user2)
|
|
84
|
+
ON CONFLICT DO NOTHING;
|
|
85
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
86
|
+
WHERE "userId" = user2;
|
|
87
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
88
|
+
ON CONFLICT DO NOTHING;
|
|
89
|
+
|
|
90
|
+
-- user3 already exists; only insert permissions for user on core
|
|
91
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
92
|
+
WHERE "userId" = user3;
|
|
93
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
94
|
+
ON CONFLICT DO NOTHING;
|
|
95
|
+
|
|
96
|
+
END $$ ;
|
|
97
|
+
COMMIT;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Provision Grimm, Tribbie to Experimental Genomics Core
|
|
2
|
+
-- Remove Loukanis, Darrell J from Experimental Genomics Core
|
|
3
|
+
|
|
4
|
+
BEGIN TRANSACTION;
|
|
5
|
+
DO $$
|
|
6
|
+
DECLARE
|
|
7
|
+
core_id integer;
|
|
8
|
+
user_id integer;
|
|
9
|
+
core_name CONSTANT varchar := 'Experimental Genomics Core';
|
|
10
|
+
BEGIN
|
|
11
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
12
|
+
|
|
13
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
14
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
15
|
+
WHERE "userId" = '91b1221071c7dae4faf3feee14ab858f';
|
|
16
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
17
|
+
ON CONFLICT DO NOTHING;
|
|
18
|
+
|
|
19
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
20
|
+
WHERE "userId" = 'c01cc78dcee73ac0965c837bf667e64a';
|
|
21
|
+
DELETE FROM public.user_cores WHERE "coreId" = core_id AND "userId" = user_id;
|
|
22
|
+
UPDATE public.users SET deleted = CURRENT_TIMESTAMP WHERE "userId" = 'c01cc78dcee73ac0965c837bf667e64a';
|
|
23
|
+
END $$ ;
|
|
24
|
+
COMMIT;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- Remove Grimm, Tribbie from Comparative Medicine Program
|
|
2
|
+
|
|
3
|
+
BEGIN TRANSACTION;
|
|
4
|
+
DO $$
|
|
5
|
+
DECLARE
|
|
6
|
+
core_id integer;
|
|
7
|
+
user_id integer;
|
|
8
|
+
core_name CONSTANT varchar := 'Comparative Medicine Program';
|
|
9
|
+
BEGIN
|
|
10
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
11
|
+
|
|
12
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
13
|
+
WHERE "userId" = '91b1221071c7dae4faf3feee14ab858f';
|
|
14
|
+
DELETE FROM public.user_cores WHERE "coreId" = core_id AND "userId" = user_id;
|
|
15
|
+
UPDATE public.users SET deleted = CURRENT_TIMESTAMP WHERE "userId" = '91b1221071c7dae4faf3feee14ab858f';
|
|
16
|
+
END $$ ;
|
|
17
|
+
COMMIT;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
-- Add Texas A&M AggieFab Nanofabrication Facility
|
|
2
|
+
-- Add Prichard, Hanna E and provision for core
|
|
3
|
+
-- Add Malhotra, Sandra Guy and provision for core
|
|
4
|
+
BEGIN TRANSACTION;
|
|
5
|
+
DO $$
|
|
6
|
+
DECLARE
|
|
7
|
+
core_id integer;
|
|
8
|
+
user_id integer;
|
|
9
|
+
system_id integer;
|
|
10
|
+
core_name CONSTANT varchar := 'Texas A&M AggieFab Nanofabrication Facility';
|
|
11
|
+
old_name CONSTANT varchar := 'AggieFab Nanofabrication Facility';
|
|
12
|
+
core_contact CONSTANT varchar := 'Hanna Prichard';
|
|
13
|
+
core_contact_email CONSTANT varchar := 'hprichard@tamu.edu';
|
|
14
|
+
core_email CONSTANT varchar := null;
|
|
15
|
+
core_address CONSTANT varchar := '1617 Research Pkwy.
|
|
16
|
+
College Station, TX 77843';
|
|
17
|
+
core_phone CONSTANT varchar := '979-845-3189';
|
|
18
|
+
revenue_account CONSTANT varchar := '2827006000000';
|
|
19
|
+
part_number CONSTANT varchar := '28';
|
|
20
|
+
user1 CONSTANT varchar := '827c53d865180b0ce129384492443029';
|
|
21
|
+
user2 CONSTANT varchar := 'ca0a310519ace7db2322c96e664605db';
|
|
22
|
+
effective_date date := '2021-12-01';
|
|
23
|
+
BEGIN
|
|
24
|
+
SELECT id INTO STRICT system_id FROM public.system WHERE part = part_number;
|
|
25
|
+
-- rename existing core
|
|
26
|
+
IF EXISTS (
|
|
27
|
+
SELECT 1 FROM public.cores WHERE facility = old_name
|
|
28
|
+
) THEN
|
|
29
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = old_name;
|
|
30
|
+
UPDATE public.cores SET facility = core_name WHERE id = core_id;
|
|
31
|
+
END IF;
|
|
32
|
+
|
|
33
|
+
IF NOT EXISTS (
|
|
34
|
+
SELECT 1 FROM public.cores WHERE facility = core_name
|
|
35
|
+
) THEN
|
|
36
|
+
INSERT INTO public.cores (facility, contact, "contactEmail",
|
|
37
|
+
"systemId", enabled, "coreEmail", "corePhone", "coreAddress")
|
|
38
|
+
VALUES (
|
|
39
|
+
core_name,
|
|
40
|
+
core_contact,
|
|
41
|
+
core_contact_email,
|
|
42
|
+
system_id,
|
|
43
|
+
TRUE,
|
|
44
|
+
core_email,
|
|
45
|
+
core_phone,
|
|
46
|
+
core_address
|
|
47
|
+
);
|
|
48
|
+
ELSE
|
|
49
|
+
UPDATE public.cores SET
|
|
50
|
+
contact = core_contact,
|
|
51
|
+
"contactEmail" = core_contact_email,
|
|
52
|
+
"systemId" = system_id,
|
|
53
|
+
enabled = TRUE,
|
|
54
|
+
"coreEmail" = core_email,
|
|
55
|
+
"corePhone" = core_phone,
|
|
56
|
+
"coreAddress" = core_address
|
|
57
|
+
WHERE facility = core_name;
|
|
58
|
+
END IF;
|
|
59
|
+
-- assign id to variable; STRICT requires exactly one row be found
|
|
60
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
61
|
+
|
|
62
|
+
IF NOT EXISTS (
|
|
63
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = core_id
|
|
64
|
+
) THEN
|
|
65
|
+
INSERT INTO public.core_accounts ("coreId", account, effective)
|
|
66
|
+
VALUES (core_id, revenue_account, effective_date);
|
|
67
|
+
ELSE
|
|
68
|
+
UPDATE public.core_accounts SET account = revenue_account, effective = effective_date
|
|
69
|
+
WHERE "coreId" = core_id AND effective = (
|
|
70
|
+
SELECT MAX(effective)
|
|
71
|
+
FROM public.core_accounts WHERE "coreId" = core_id);
|
|
72
|
+
END IF;
|
|
73
|
+
|
|
74
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
75
|
+
INSERT INTO public.users ("userId") VALUES (user1)
|
|
76
|
+
ON CONFLICT DO NOTHING;
|
|
77
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
78
|
+
WHERE "userId" = user1;
|
|
79
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
80
|
+
ON CONFLICT DO NOTHING;
|
|
81
|
+
|
|
82
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
83
|
+
INSERT INTO public.users ("userId") VALUES (user2)
|
|
84
|
+
ON CONFLICT DO NOTHING;
|
|
85
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
86
|
+
WHERE "userId" = user2;
|
|
87
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
88
|
+
ON CONFLICT DO NOTHING;
|
|
89
|
+
|
|
90
|
+
END $$ ;
|
|
91
|
+
COMMIT;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Add table invoice_comments
|
|
2
|
+
-- Add index invoice_comments_invoice_id
|
|
3
|
+
-- Add index invoice_comments_user_id
|
|
4
|
+
BEGIN TRANSACTION;
|
|
5
|
+
DO $$
|
|
6
|
+
BEGIN
|
|
7
|
+
CREATE TABLE IF NOT EXISTS public.invoice_comments (
|
|
8
|
+
id integer GENERATED ALWAYS AS IDENTITY,
|
|
9
|
+
uid character varying(29) NOT NULL,
|
|
10
|
+
invoice_id character varying(29) NOT NULL,
|
|
11
|
+
user_id integer NOT NULL,
|
|
12
|
+
comment text,
|
|
13
|
+
type character varying(255) DEFAULT 'srs',
|
|
14
|
+
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
+
deleted timestamp with time zone DEFAULT NULL,
|
|
16
|
+
PRIMARY KEY("id"),
|
|
17
|
+
UNIQUE("uid")
|
|
18
|
+
);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS invoice_comments_invoice_id ON public.invoice_comments USING btree ("invoice_id");
|
|
20
|
+
CREATE INDEX IF NOT EXISTS invoice_comments_user_id ON public.invoice_comments USING btree ("user_id");
|
|
21
|
+
|
|
22
|
+
CREATE TABLE IF NOT EXISTS public.invoice_comment_files (
|
|
23
|
+
id integer GENERATED ALWAYS AS IDENTITY,
|
|
24
|
+
uid character varying(29) NOT NULL,
|
|
25
|
+
invoice_id character varying(29) NOT NULL,
|
|
26
|
+
comment_id character varying(29) NOT NULL,
|
|
27
|
+
original_filename text,
|
|
28
|
+
filename text,
|
|
29
|
+
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
30
|
+
deleted timestamp with time zone DEFAULT NULL,
|
|
31
|
+
PRIMARY KEY("id"),
|
|
32
|
+
UNIQUE("uid")
|
|
33
|
+
);
|
|
34
|
+
CREATE INDEX IF NOT EXISTS invoice_comment_files_invoice_id ON public.invoice_comment_files USING btree ("invoice_id");
|
|
35
|
+
CREATE INDEX IF NOT EXISTS invoice_comment_files_comment_id ON public.invoice_comment_files USING btree ("comment_id");
|
|
36
|
+
ALTER TABLE public.invoice_comment_files OWNER TO dba;
|
|
37
|
+
ALTER TABLE public.invoice_comments OWNER TO dba;
|
|
38
|
+
GRANT SELECT ON public.invoice_comment_files, public.invoice_comments TO famis;
|
|
39
|
+
GRANT INSERT, UPDATE ON public.invoice_comment_files, public.invoice_comments TO famis;
|
|
40
|
+
END $$ ;
|
|
41
|
+
COMMIT;
|