@tamu-dor/famis-db 1.3.0
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/change.txt +123 -0
- package/changes.md +405 -0
- package/docs/assets/anchor.js +350 -0
- package/docs/assets/bass-addons.css +12 -0
- package/docs/assets/bass.css +544 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/docs/assets/fonts/LICENSE.txt +93 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/docs/assets/fonts/source-code-pro.css +23 -0
- package/docs/assets/github.css +123 -0
- package/docs/assets/site.js +168 -0
- package/docs/assets/split.css +15 -0
- package/docs/assets/split.js +782 -0
- package/docs/assets/style.css +147 -0
- package/docs/index.html +3737 -0
- package/docs.md +591 -0
- package/famisDb.pdf +0 -0
- package/index.js +1497 -0
- package/package.json +25 -0
- package/readme.md +38 -0
- package/readme.wiki +332 -0
- package/schemas/00-initial-data.sql +116 -0
- package/schemas/migrations/201906101221.sql +29 -0
- package/schemas/migrations/201907081530.sql +51 -0
- package/schemas/migrations/201908230849.sql +40 -0
- package/schemas/migrations/201910031358.sql +73 -0
- package/schemas/migrations/20191024.sql +38 -0
- package/schemas/migrations/201911060915.sql +3 -0
- package/schemas/migrations/202001221335.sql +58 -0
- package/schemas/migrations/202003041114.sql +53 -0
- package/schemas/migrations/202003261143.sql +47 -0
- package/schemas/migrations/202004201456.sql +3 -0
- package/schemas/migrations/20200722.sql +92 -0
- package/schemas/migrations/202007281124.sql +17 -0
- package/schemas/migrations/20200729.sql +76 -0
- package/schemas/migrations/20200806-FCF.sql +72 -0
- package/schemas/migrations/20200806-IMAC.sql +60 -0
- package/schemas/migrations/20200811.sql +46 -0
- package/schemas/migrations/20200813.sql +36 -0
- package/schemas/migrations/202010210924.sql +66 -0
- package/schemas/migrations/202010211558.sql +20 -0
- package/schemas/migrations/202011130651.sql +4 -0
- package/schemas/migrations/202011130951.sql +17 -0
- package/schemas/migrations/202101201051.sql +33 -0
- package/schemas/migrations/postponed-202004221221.sql +66 -0
- package/schemas/schema.sql +155 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
DROP TABLE IF EXISTS "forceAr";
|
|
3
|
+
END TRANSACTION;
|
|
4
|
+
BEGIN TRANSACTION;
|
|
5
|
+
UPDATE public.cores SET
|
|
6
|
+
"facility" = 'Experimental Genomics Core',
|
|
7
|
+
"contact" = 'Andrew Hillhouse',
|
|
8
|
+
"contactEmail" = 'hillhouse@tamu.edu',
|
|
9
|
+
"account" = '0227043000000',
|
|
10
|
+
"systemId" = '2',
|
|
11
|
+
"enabled" = 'TRUE',
|
|
12
|
+
"deleted" = NULL,
|
|
13
|
+
"coreEmail" = 'tigss@tamu.edu',
|
|
14
|
+
"corePhone" = '979-458-5678',
|
|
15
|
+
"coreAddress" = NULL
|
|
16
|
+
WHERE id = 1;
|
|
17
|
+
UPDATE public.core_accounts SET account = '0227043000000' WHERE id = 1;
|
|
18
|
+
END TRANSACTION;
|
|
19
|
+
BEGIN TRANSACTION;
|
|
20
|
+
INSERT INTO public.users ("userId")
|
|
21
|
+
SELECT '7ab9f2e7395196cd7ea428689fae1f52'
|
|
22
|
+
WHERE NOT EXISTS (
|
|
23
|
+
SELECT 1 FROM public.users WHERE "userId" = '7ab9f2e7395196cd7ea428689fae1f52'
|
|
24
|
+
);
|
|
25
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
26
|
+
SELECT 1, (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
27
|
+
WHERE NOT EXISTS (
|
|
28
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = 1 AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
29
|
+
);
|
|
30
|
+
END TRANSACTION;
|
|
31
|
+
BEGIN TRANSACTION;
|
|
32
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
33
|
+
SELECT 1, 2, 'TRUE'
|
|
34
|
+
WHERE NOT EXISTS (
|
|
35
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = 1 AND "userId" = 2 AND email = 'TRUE'
|
|
36
|
+
);
|
|
37
|
+
END TRANSACTION;
|
|
38
|
+
BEGIN TRANSACTION;
|
|
39
|
+
UPDATE public.cores SET
|
|
40
|
+
"facility" = 'Image Analysis Laboratory',
|
|
41
|
+
"contact" = 'Sybil Camacho',
|
|
42
|
+
"contactEmail" = 'scamacho@tamu.edu',
|
|
43
|
+
"enabled" = 'TRUE',
|
|
44
|
+
"deleted" = NULL,
|
|
45
|
+
"coreEmail" = NULL,
|
|
46
|
+
"corePhone" = NULL,
|
|
47
|
+
"coreAddress" = NULL
|
|
48
|
+
WHERE id = 22;
|
|
49
|
+
END TRANSACTION;
|
|
50
|
+
BEGIN TRANSACTION;
|
|
51
|
+
INSERT INTO public.users ("userId")
|
|
52
|
+
SELECT '43e161d7c13fce71ea6c6814dfb4695f'
|
|
53
|
+
WHERE NOT EXISTS (
|
|
54
|
+
SELECT 1 FROM public.users WHERE "userId" = '43e161d7c13fce71ea6c6814dfb4695f'
|
|
55
|
+
);
|
|
56
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
57
|
+
SELECT 22, (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
58
|
+
WHERE NOT EXISTS (
|
|
59
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = 22 AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
60
|
+
);
|
|
61
|
+
END TRANSACTION;
|
|
62
|
+
BEGIN TRANSACTION;
|
|
63
|
+
INSERT INTO public.users ("userId")
|
|
64
|
+
SELECT 'dea7a1e2a041fc9efb808fb8d73ee35b'
|
|
65
|
+
WHERE NOT EXISTS (
|
|
66
|
+
SELECT 1 FROM public.users WHERE "userId" = 'dea7a1e2a041fc9efb808fb8d73ee35b'
|
|
67
|
+
);
|
|
68
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
69
|
+
SELECT 22, (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
70
|
+
WHERE NOT EXISTS (
|
|
71
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = 22 AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
72
|
+
);
|
|
73
|
+
END TRANSACTION;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
-- Fix account number for IBT High Throughput Research and Screening Center Core
|
|
2
|
+
UPDATE core_accounts SET account='2328027000000' WHERE account='2371202802700';
|
|
3
|
+
|
|
4
|
+
-- Remove obsolete account column from cores table (replaced by the
|
|
5
|
+
-- core_accounts table in the 201908230849 migration, which also copied all
|
|
6
|
+
-- accounts to the new table).
|
|
7
|
+
ALTER TABLE cores DROP COLUMN IF EXISTS account;
|
|
8
|
+
|
|
9
|
+
-- Add a foreign key to the core_accounts table (only for coreId -- not yet
|
|
10
|
+
-- doing account).
|
|
11
|
+
DO $$
|
|
12
|
+
BEGIN
|
|
13
|
+
-- key_column_usage is the referring table/column; constraint_column_usage is
|
|
14
|
+
-- the referred-to table/column.
|
|
15
|
+
IF NOT EXISTS (SELECT 1 FROM information_schema.key_column_usage AS kcu
|
|
16
|
+
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_name)
|
|
17
|
+
JOIN information_schema.table_constraints AS tc USING (constraint_name)
|
|
18
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
19
|
+
AND ccu.table_name = 'cores'
|
|
20
|
+
AND ccu.column_name = 'id'
|
|
21
|
+
AND kcu.table_name = 'core_accounts'
|
|
22
|
+
AND kcu.column_name = 'coreId') THEN
|
|
23
|
+
ALTER TABLE core_accounts ADD FOREIGN KEY ("coreId") REFERENCES cores(id)
|
|
24
|
+
ON DELETE CASCADE ON UPDATE CASCADE;
|
|
25
|
+
ELSE
|
|
26
|
+
RAISE NOTICE 'core_accounts.coreId foreign key already present';
|
|
27
|
+
END IF;
|
|
28
|
+
END $$;
|
|
29
|
+
/*
|
|
30
|
+
The target column must be unique, and we currently have some duplicates in
|
|
31
|
+
accounts.account_number (differing by setup_date, and thus uid). Will revisit
|
|
32
|
+
that after restructuring the accounts table (maybe a view with only the
|
|
33
|
+
current/active ones?).
|
|
34
|
+
|
|
35
|
+
Also need to be aware of interaction with updating the accounts feed (use
|
|
36
|
+
ON DELETE RESTRICT?). We're currently doing an "upsert" rather than
|
|
37
|
+
truncating, so that should _probably_ be OK?
|
|
38
|
+
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
INSERT INTO public.cores (
|
|
3
|
+
"facility",
|
|
4
|
+
"contact",
|
|
5
|
+
"contactEmail",
|
|
6
|
+
"systemId",
|
|
7
|
+
"enabled",
|
|
8
|
+
"deleted",
|
|
9
|
+
"coreEmail",
|
|
10
|
+
"corePhone",
|
|
11
|
+
"coreAddress"
|
|
12
|
+
) SELECT
|
|
13
|
+
'Rodent Pre-clinical Phenotyping Core',
|
|
14
|
+
'Aimee Curington',
|
|
15
|
+
'acurington@tamu.edu',
|
|
16
|
+
'2',
|
|
17
|
+
'1',
|
|
18
|
+
NULL,
|
|
19
|
+
'atrott@tamu.edu',
|
|
20
|
+
NULL,
|
|
21
|
+
NULL
|
|
22
|
+
WHERE NOT EXISTS (
|
|
23
|
+
SELECT 1 FROM public.cores WHERE facility = 'Rodent Pre-clinical Phenotyping Core' AND contact = 'Aimee Curington' AND "contactEmail" = 'acurington@tamu.edu' AND "systemId" = 2 AND "enabled" = 'TRUE' AND "coreEmail" = 'atrott@tamu.edu'
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
INSERT INTO public.core_accounts ("coreId", "account", "effective")
|
|
27
|
+
SELECT (SELECT currval('public.cores_id_seq')), '0227044000000', '2019-09-01'
|
|
28
|
+
WHERE NOT EXISTS (
|
|
29
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = (SELECT currval('public.cores_id_seq')) AND account = '0227044000000' AND effective = '2019-09-01'
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
INSERT INTO public.users ("userId")
|
|
33
|
+
SELECT '1df80ba44155481ab711b9fc577a50ba'
|
|
34
|
+
WHERE NOT EXISTS (
|
|
35
|
+
SELECT 1 FROM public.users WHERE "userId" = '1df80ba44155481ab711b9fc577a50ba'
|
|
36
|
+
);
|
|
37
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
38
|
+
SELECT (SELECT currval('public.cores_id_seq')), (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
39
|
+
WHERE NOT EXISTS (
|
|
40
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = (SELECT currval('public.cores_id_seq')) AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
INSERT INTO public.users ("userId")
|
|
44
|
+
SELECT '00d536ef7f6c81766c7c00cbb2566481'
|
|
45
|
+
WHERE NOT EXISTS (
|
|
46
|
+
SELECT 1 FROM public.users WHERE "userId" = '00d536ef7f6c81766c7c00cbb2566481'
|
|
47
|
+
);
|
|
48
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
49
|
+
SELECT (SELECT currval('public.cores_id_seq')), (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
50
|
+
WHERE NOT EXISTS (
|
|
51
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = (SELECT currval('public.cores_id_seq')) AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
52
|
+
);
|
|
53
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
54
|
+
SELECT (SELECT currval('public.cores_id_seq')), 2, 'TRUE'
|
|
55
|
+
WHERE NOT EXISTS (
|
|
56
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = (SELECT currval('public.cores_id_seq')) AND "userId" = 2 AND email = 'TRUE'
|
|
57
|
+
);
|
|
58
|
+
END TRANSACTION;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
UPDATE "cores" SET
|
|
3
|
+
"facility" = 'Biomedical Engineering Shared Laboratories',
|
|
4
|
+
"contact" = 'ATTN Accounts Payable',
|
|
5
|
+
"contactEmail" = 'Nathan.howard@tamu.edu',
|
|
6
|
+
"systemId" = '23',
|
|
7
|
+
"enabled" = '1',
|
|
8
|
+
"deleted" = NULL,
|
|
9
|
+
"coreEmail" = 'bmenbusiness@tamu.edu',
|
|
10
|
+
"corePhone" = '979-458-2317',
|
|
11
|
+
"coreAddress" = '101 Bizzell St.
|
|
12
|
+
College Station, TX 77843
|
|
13
|
+
MS3120'
|
|
14
|
+
WHERE "id" = '14';
|
|
15
|
+
|
|
16
|
+
UPDATE "core_accounts" SET "account" = '2827095000000' WHERE "account" = '2823313100000' AND "coreId" = 14;
|
|
17
|
+
END TRANSACTION;
|
|
18
|
+
BEGIN TRANSACTION;
|
|
19
|
+
INSERT INTO public.users ("userId")
|
|
20
|
+
SELECT '51cb543b9fa46a3b939309f51541eb78'
|
|
21
|
+
WHERE NOT EXISTS (
|
|
22
|
+
SELECT 1 FROM public.users WHERE "userId" = '51cb543b9fa46a3b939309f51541eb78'
|
|
23
|
+
);
|
|
24
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
25
|
+
SELECT 14, (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
26
|
+
WHERE NOT EXISTS (
|
|
27
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = 14 AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
28
|
+
);
|
|
29
|
+
END TRANSACTION;
|
|
30
|
+
BEGIN TRANSACTION;
|
|
31
|
+
INSERT INTO public.users ("userId")
|
|
32
|
+
SELECT '101b6adeec4d7445a4c2b8901a2d062d'
|
|
33
|
+
WHERE NOT EXISTS (
|
|
34
|
+
SELECT 1 FROM public.users WHERE "userId" = '101b6adeec4d7445a4c2b8901a2d062d'
|
|
35
|
+
);
|
|
36
|
+
INSERT INTO public.user_cores ("coreId", "userId", email)
|
|
37
|
+
SELECT 14, (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
38
|
+
WHERE NOT EXISTS (
|
|
39
|
+
SELECT 1 FROM public.user_cores WHERE "coreId" = 14 AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
40
|
+
);
|
|
41
|
+
END TRANSACTION;
|
|
42
|
+
BEGIN TRANSACTION;
|
|
43
|
+
INSERT INTO public.users ("userId")
|
|
44
|
+
SELECT '012c3dae7906b70c88b8849b11fab522'
|
|
45
|
+
WHERE NOT EXISTS (
|
|
46
|
+
SELECT 1 FROM public.users WHERE "userId" = '012c3dae7906b70c88b8849b11fab522'
|
|
47
|
+
);
|
|
48
|
+
INSERT INTO public.user_systems ("systemId", "userId", email)
|
|
49
|
+
SELECT 23, (SELECT currval('public.users_id_seq')), 'TRUE'
|
|
50
|
+
WHERE NOT EXISTS (
|
|
51
|
+
SELECT 1 FROM public.user_systems WHERE "systemId" = 23 AND "userId" = (SELECT currval('public.users_id_seq')) AND email = 'TRUE'
|
|
52
|
+
);
|
|
53
|
+
END TRANSACTION;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
DO $$
|
|
3
|
+
DECLARE
|
|
4
|
+
core_id integer;
|
|
5
|
+
user_id integer;
|
|
6
|
+
core_name CONSTANT varchar := 'College of Dentistry Research Core';
|
|
7
|
+
BEGIN
|
|
8
|
+
IF NOT EXISTS (
|
|
9
|
+
SELECT 1 FROM public.cores WHERE facility = core_name
|
|
10
|
+
) THEN
|
|
11
|
+
INSERT INTO public.cores (facility, contact, "contactEmail", "systemId",
|
|
12
|
+
enabled, "coreEmail" /* no phone or address supplied */)
|
|
13
|
+
VALUES (core_name, 'Shannon F. Kramer', 'sfkramer@tamu.edu', 19,
|
|
14
|
+
TRUE, 'COD-Core@tamu.edu');
|
|
15
|
+
ELSE
|
|
16
|
+
RAISE NOTICE 'Core already exists.';
|
|
17
|
+
END IF;
|
|
18
|
+
-- assign id to variable; STRICT requires exactly one row be found
|
|
19
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
20
|
+
|
|
21
|
+
IF NOT EXISTS (
|
|
22
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = core_id
|
|
23
|
+
) THEN
|
|
24
|
+
INSERT INTO public.core_accounts ("coreId", account, effective)
|
|
25
|
+
VALUES (core_id, '2321117500000', '2019-09-01');
|
|
26
|
+
ELSE
|
|
27
|
+
UPDATE public.core_accounts SET account = '2321117500000', effective = '2019-09-01'
|
|
28
|
+
WHERE "coreId" = core_id AND effective = (SELECT MAX(effective)
|
|
29
|
+
FROM public.core_accounts WHERE "coreId" = core_id);
|
|
30
|
+
END IF;
|
|
31
|
+
|
|
32
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
33
|
+
INSERT INTO public.users ("userId") VALUES ('7a271673a32a33852e52a0359045fda8')
|
|
34
|
+
ON CONFLICT DO NOTHING;
|
|
35
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
36
|
+
WHERE "userId" = '7a271673a32a33852e52a0359045fda8';
|
|
37
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
38
|
+
ON CONFLICT DO NOTHING;
|
|
39
|
+
|
|
40
|
+
INSERT INTO public.users ("userId") VALUES ('f04e2f56e956bf1da03144adc00603c8')
|
|
41
|
+
ON CONFLICT DO NOTHING;
|
|
42
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
43
|
+
WHERE "userId" = 'f04e2f56e956bf1da03144adc00603c8';
|
|
44
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
45
|
+
ON CONFLICT DO NOTHING;
|
|
46
|
+
END $$ ;
|
|
47
|
+
COMMIT;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE accounts RENAME COLUMN "type" TO idt_allowed;
|
|
4
|
+
/* convert existing data: 'idt' => true, else false
|
|
5
|
+
|
|
6
|
+
To avoid issues with the default NULL (varchar), drop it first, then set
|
|
7
|
+
again afterwards.
|
|
8
|
+
*/
|
|
9
|
+
ALTER TABLE accounts ALTER COLUMN idt_allowed DROP DEFAULT,
|
|
10
|
+
ALTER COLUMN idt_allowed TYPE boolean USING idt_allowed = 'idt',
|
|
11
|
+
ALTER COLUMN idt_allowed SET DEFAULT NULL;
|
|
12
|
+
COMMENT ON COLUMN accounts.idt_allowed IS 'if not set, must process as AR';
|
|
13
|
+
/* Verification (has been done manually): ensure that the numbers output by
|
|
14
|
+
these queries match (ar => false, idt => true).
|
|
15
|
+
Before: select type, count(type) from accounts group by type;
|
|
16
|
+
After: select idt_allowed, count(idt_allowed) from accounts group by idt_allowed;
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/* These new fields are not part of the employeedata block, so update the
|
|
20
|
+
comment accordingly. */
|
|
21
|
+
COMMENT ON COLUMN accounts.adloc_campus_code IS
|
|
22
|
+
'These columns (up through "active") describe the person in uin';
|
|
23
|
+
ALTER TABLE accounts ADD COLUMN default_bank CHAR(5) DEFAULT NULL,
|
|
24
|
+
ADD COLUMN bank_override boolean DEFAULT NULL;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
-- Alternate bank codes received from FAMIS, used to determine an account's
|
|
28
|
+
-- IDT eligibility. The stored procedure update_idt_allowed() will update the
|
|
29
|
+
-- idt_allowed column in the accounts table, using this information.
|
|
30
|
+
CREATE TABLE public.alt_bank (
|
|
31
|
+
campus_code character(2) NOT NULL,
|
|
32
|
+
fiscal_year integer NOT NULL,
|
|
33
|
+
account character varying(6) NOT NULL,
|
|
34
|
+
support_account character varying(5) NOT NULL,
|
|
35
|
+
-- The parser strips records without any alternate bank fields, so only 2-5 are optional.
|
|
36
|
+
alt_bank1 character(5) NOT NULL,
|
|
37
|
+
alt_bank2 character(5),
|
|
38
|
+
alt_bank3 character(5),
|
|
39
|
+
alt_bank4 character(5),
|
|
40
|
+
alt_bank5 character(5)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
COMMENT ON TABLE alt_bank IS 'alternate bank codes used in IDT eligibility';
|
|
44
|
+
COMMENT ON COLUMN alt_bank.alt_bank1 IS 'IDT allowed with 0 or * in first position';
|
|
45
|
+
|
|
46
|
+
ALTER TABLE public.alt_bank OWNER TO dba;
|
|
47
|
+
GRANT SELECT, INSERT, TRUNCATE ON public.alt_bank TO famisparser;
|
|
48
|
+
|
|
49
|
+
CREATE INDEX alt_bank_acct_idx ON alt_bank (campus_code, account, support_account, fiscal_year);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
-- Helper function for IDT status: if the first character is '0' or '*', IDT is allowed.
|
|
53
|
+
CREATE OR REPLACE FUNCTION bank_idt(bank char) RETURNS boolean
|
|
54
|
+
AS $$
|
|
55
|
+
SELECT length(bank) = 5 AND left(bank, 1) IN ('0', '*');
|
|
56
|
+
$$ LANGUAGE SQL;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
-- Procedure to update accounts.idt_allowed based on default_bank,
|
|
60
|
+
-- bank_override, and alt_bank[1-5]. (Technically a function, as procedures
|
|
61
|
+
-- weren't added until PostgreSQL 11.) Default in pgsql is SECURITY INVOKER,
|
|
62
|
+
-- which is what we want.
|
|
63
|
+
CREATE OR REPLACE FUNCTION update_idt_allowed() RETURNS boolean
|
|
64
|
+
AS $$
|
|
65
|
+
DECLARE
|
|
66
|
+
row record;
|
|
67
|
+
allowed BOOLEAN := FALSE;
|
|
68
|
+
BEGIN
|
|
69
|
+
FOR row IN SELECT uid, a.campus_code, default_bank, bank_override, alt_bank1, alt_bank2,
|
|
70
|
+
alt_bank3, alt_bank4, alt_bank5
|
|
71
|
+
FROM accounts a LEFT JOIN alt_bank ab ON a.campus_code = ab.campus_code AND a.account = ab.account
|
|
72
|
+
AND a.support_account = ab.support_account AND a.fiscal_year = ab.fiscal_year
|
|
73
|
+
LOOP
|
|
74
|
+
-- part 09 (TEEX) doesn't use FAMIS directly and is thus always forced AR
|
|
75
|
+
if row.campus_code = '09' then
|
|
76
|
+
allowed = FALSE;
|
|
77
|
+
elsif bank_idt(row.default_bank) then
|
|
78
|
+
allowed = TRUE;
|
|
79
|
+
elsif row.bank_override = TRUE AND (bank_idt(row.alt_bank1) OR bank_idt(row.alt_bank2)
|
|
80
|
+
OR bank_idt(row.alt_bank3) OR bank_idt(row.alt_bank4) OR bank_idt(row.alt_bank5)) then
|
|
81
|
+
allowed = TRUE;
|
|
82
|
+
else
|
|
83
|
+
allowed = FALSE;
|
|
84
|
+
end if;
|
|
85
|
+
|
|
86
|
+
UPDATE accounts SET idt_allowed = allowed WHERE uid = row.uid;
|
|
87
|
+
END LOOP;
|
|
88
|
+
RETURN TRUE;
|
|
89
|
+
END;
|
|
90
|
+
$$ LANGUAGE plpgsql;
|
|
91
|
+
|
|
92
|
+
COMMIT;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
DO $$
|
|
3
|
+
DECLARE
|
|
4
|
+
core_id integer;
|
|
5
|
+
user_id integer;
|
|
6
|
+
core_name CONSTANT varchar := 'IBT High Throughput Research and Screening Center Core';
|
|
7
|
+
BEGIN
|
|
8
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
9
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
10
|
+
INSERT INTO public.users ("userId") VALUES ('b951128c63caad9ff50fee453f153609')
|
|
11
|
+
ON CONFLICT DO NOTHING;
|
|
12
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
13
|
+
WHERE "userId" = 'b951128c63caad9ff50fee453f153609';
|
|
14
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
15
|
+
ON CONFLICT DO NOTHING;
|
|
16
|
+
END $$ ;
|
|
17
|
+
COMMIT;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
|
|
3
|
+
-- Clean up obsolete tables (funds/fund_codes were replaced by accounts,
|
|
4
|
+
-- account_balances, and abr_rules; departments is now being sent as a feed,
|
|
5
|
+
-- with a different schema defined below).
|
|
6
|
+
DROP TABLE IF EXISTS fund_codes;
|
|
7
|
+
DROP TABLE IF EXISTS funds;
|
|
8
|
+
DROP TABLE IF EXISTS departments;
|
|
9
|
+
|
|
10
|
+
-- Departments feed sent to us from FAMIS in the file DEPTTABL.VPR.DAILY.TXT.
|
|
11
|
+
-- Note that as a fixed-width text file, it is not parsed by dumpparser.py but
|
|
12
|
+
-- by using a temporary table and SQL substring().
|
|
13
|
+
--
|
|
14
|
+
-- All columns provided in the feed are listed, but many are not currently
|
|
15
|
+
-- used. If a column is added, double-check whether varchar or another type
|
|
16
|
+
-- (e.g. int, date) would be more appropriate.
|
|
17
|
+
|
|
18
|
+
-- This schema is written to be portable between MySQL and PostgreSQL.
|
|
19
|
+
CREATE TABLE IF NOT EXISTS departments (
|
|
20
|
+
part char(2) NOT NULL,
|
|
21
|
+
dept varchar(5) NOT NULL,
|
|
22
|
+
sub varchar(5),
|
|
23
|
+
dept_name varchar(40) NOT NULL,
|
|
24
|
+
dept_head char(9), -- UIN, may be blank
|
|
25
|
+
-- mail_code varchar(5) NOT NULL,
|
|
26
|
+
exec_level varchar(2),
|
|
27
|
+
division char(2),
|
|
28
|
+
school char(2),
|
|
29
|
+
-- off_campus_flag varchar(1) NOT NULL,
|
|
30
|
+
-- department_number varchar(5) NOT NULL,
|
|
31
|
+
-- fa_allow_flag varchar(1) NOT NULL,
|
|
32
|
+
-- fpr_training_flag varchar(1) NOT NULL,
|
|
33
|
+
-- other_system_part_number varchar(2) NOT NULL,
|
|
34
|
+
-- other_system_part_department varchar(5) NOT NULL,
|
|
35
|
+
-- other_system_part_sub_department varchar(5) NOT NULL,
|
|
36
|
+
-- expiration_date varchar(8) NOT NULL,
|
|
37
|
+
exp_date date,
|
|
38
|
+
-- alternate_apo_person_id varchar(9) NOT NULL,
|
|
39
|
+
-- building_number varchar(5) NOT NULL,
|
|
40
|
+
-- building_campus_code varchar(2) NOT NULL,
|
|
41
|
+
-- room_floor varchar(6) NOT NULL,
|
|
42
|
+
-- group_code varchar(5) NOT NULL,
|
|
43
|
+
-- other_location varchar(20) NOT NULL,
|
|
44
|
+
-- approximate_inventory_count int(11) NOT NULL,
|
|
45
|
+
-- ffx_allow_flag varchar(1) NOT NULL,
|
|
46
|
+
-- ffx_certified_month int(11) NOT NULL,
|
|
47
|
+
-- mail_to_department_head_flag varchar(1) NOT NULL,
|
|
48
|
+
-- office varchar(10) NOT NULL,
|
|
49
|
+
-- view varchar(10) NOT NULL,
|
|
50
|
+
-- epa_allow varchar(1) NOT NULL,
|
|
51
|
+
-- exec_office varchar(10) NOT NULL,
|
|
52
|
+
-- exec_view varchar(5) NOT NULL,
|
|
53
|
+
-- proc_unit varchar(1) NOT NULL,
|
|
54
|
+
-- dbr_allow_flag varchar(1) NOT NULL,
|
|
55
|
+
idt_email varchar(50)
|
|
56
|
+
-- Stuff inside /*! */ will only be executed by MySQL.
|
|
57
|
+
) /*! ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci */;
|
|
58
|
+
|
|
59
|
+
CREATE INDEX IF NOT EXISTS departments_dept ON departments (dept);
|
|
60
|
+
CREATE INDEX IF NOT EXISTS departments_dept_head ON departments (dept_head);
|
|
61
|
+
-- campus code + dept + sub dept should be unique
|
|
62
|
+
CREATE UNIQUE INDEX IF NOT EXISTS departments_part_dept_sub ON departments
|
|
63
|
+
(part, dept, sub);
|
|
64
|
+
CREATE INDEX IF NOT EXISTS departments_idt_email ON departments (idt_email);
|
|
65
|
+
|
|
66
|
+
-- The parser user will need INSERT and TRUNCATE privileges on this table (in
|
|
67
|
+
-- MySQL, use DROP instead of TRUNCATE). MySQL also needs CREATE TEMPORARY
|
|
68
|
+
-- TABLES on the database (grant on db.*); PostgreSQL default privileges
|
|
69
|
+
-- already allow this.
|
|
70
|
+
-- Additionally, any application reading the table will need SELECT privileges
|
|
71
|
+
-- for its user.
|
|
72
|
+
ALTER TABLE departments OWNER TO dba;
|
|
73
|
+
GRANT INSERT, TRUNCATE ON departments TO famisparser;
|
|
74
|
+
GRANT SELECT ON departments TO famis;
|
|
75
|
+
|
|
76
|
+
COMMIT;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
DO $$
|
|
3
|
+
DECLARE
|
|
4
|
+
core_id integer;
|
|
5
|
+
user_id integer;
|
|
6
|
+
account_number CONSTANT varchar := '0227157000000';
|
|
7
|
+
old_core_name CONSTANT varchar := 'CVM Flow Cytometry Core Facility';
|
|
8
|
+
core_name CONSTANT varchar := 'Flow Cytometry Facility';
|
|
9
|
+
core_address CONSTANT varchar := 'Vet Med Research Bldg. Addition (Building 1811)
|
|
10
|
+
Room 257
|
|
11
|
+
588 Raymond Stotzer Pkwy.
|
|
12
|
+
College Station, TX 77843';
|
|
13
|
+
|
|
14
|
+
BEGIN
|
|
15
|
+
IF NOT EXISTS (
|
|
16
|
+
SELECT 1 FROM public.cores WHERE facility = old_core_name OR facility = core_name
|
|
17
|
+
) THEN
|
|
18
|
+
INSERT INTO public.cores (facility, contact, "contactEmail", "systemId",
|
|
19
|
+
enabled, "coreEmail", "corePhone", "coreAddress")
|
|
20
|
+
VALUES (core_name, 'Gus Alan Wright', 'gwright@cvm.tamu.edu', 2,
|
|
21
|
+
TRUE, null, '979-458-9859', core_address);
|
|
22
|
+
ELSE
|
|
23
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = old_core_name OR facility = core_name;
|
|
24
|
+
UPDATE public.cores SET
|
|
25
|
+
"facility" = core_name,
|
|
26
|
+
"contact" = 'Gus Alan Wright',
|
|
27
|
+
"contactEmail" = 'gwright@cvm.tamu.edu',
|
|
28
|
+
"systemId" = 2,
|
|
29
|
+
"enabled" = TRUE,
|
|
30
|
+
"deleted" = NULL,
|
|
31
|
+
"coreEmail" = NULL,
|
|
32
|
+
"corePhone" = '979-458-9859',
|
|
33
|
+
"coreAddress" = core_address
|
|
34
|
+
WHERE id = core_id;
|
|
35
|
+
END IF;
|
|
36
|
+
-- assign id to variable; STRICT requires exactly one row be found
|
|
37
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
38
|
+
|
|
39
|
+
IF NOT EXISTS (
|
|
40
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = core_id
|
|
41
|
+
) THEN
|
|
42
|
+
INSERT INTO public.core_accounts ("coreId", account, effective)
|
|
43
|
+
VALUES (core_id, account_number, '2019-09-01');
|
|
44
|
+
ELSE
|
|
45
|
+
UPDATE public.core_accounts SET account = account_number, effective = '2019-09-01'
|
|
46
|
+
WHERE "coreId" = core_id AND effective = (SELECT MAX(effective)
|
|
47
|
+
FROM public.core_accounts WHERE "coreId" = core_id);
|
|
48
|
+
END IF;
|
|
49
|
+
|
|
50
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
51
|
+
INSERT INTO public.users ("userId") VALUES ('17aee3f1044e6ee9f006deadf5fa7f48')
|
|
52
|
+
ON CONFLICT DO NOTHING;
|
|
53
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
54
|
+
WHERE "userId" = '17aee3f1044e6ee9f006deadf5fa7f48';
|
|
55
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
56
|
+
ON CONFLICT DO NOTHING;
|
|
57
|
+
|
|
58
|
+
INSERT INTO public.users ("userId") VALUES ('c2ca211343fca3a6220f83a1eaa1bb4d')
|
|
59
|
+
ON CONFLICT DO NOTHING;
|
|
60
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
61
|
+
WHERE "userId" = 'c2ca211343fca3a6220f83a1eaa1bb4d';
|
|
62
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
63
|
+
ON CONFLICT DO NOTHING;
|
|
64
|
+
|
|
65
|
+
INSERT INTO public.users ("userId") VALUES ('f8c468ebec93a4c4b709e62210c08dee')
|
|
66
|
+
ON CONFLICT DO NOTHING;
|
|
67
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
68
|
+
WHERE "userId" = 'f8c468ebec93a4c4b709e62210c08dee';
|
|
69
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
70
|
+
ON CONFLICT DO NOTHING;
|
|
71
|
+
END $$ ;
|
|
72
|
+
COMMIT;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
DO $$
|
|
3
|
+
DECLARE
|
|
4
|
+
core_id integer;
|
|
5
|
+
user_id integer;
|
|
6
|
+
account_number CONSTANT varchar := '0227102050000';
|
|
7
|
+
old_core_name CONSTANT varchar := 'Integrated Metabolics Analysis Core';
|
|
8
|
+
core_name CONSTANT varchar := 'Integrated Metabolomics Analysis Core';
|
|
9
|
+
BEGIN
|
|
10
|
+
IF NOT EXISTS (
|
|
11
|
+
SELECT 1 FROM public.cores WHERE facility = old_core_name OR facility = core_name
|
|
12
|
+
) THEN
|
|
13
|
+
INSERT INTO public.cores (facility, contact, "contactEmail", "systemId",
|
|
14
|
+
enabled, "coreEmail" /* no phone or address supplied */)
|
|
15
|
+
VALUES (core_name, 'Shelly Pasket', 'spasket@tamu.edu', 2,
|
|
16
|
+
TRUE, null);
|
|
17
|
+
ELSE
|
|
18
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = old_core_name OR facility = core_name;
|
|
19
|
+
UPDATE public.cores SET
|
|
20
|
+
"facility" = core_name,
|
|
21
|
+
"contact" = 'Shelly Pasket',
|
|
22
|
+
"contactEmail" = 'spasket@tamu.edu',
|
|
23
|
+
"systemId" = 2,
|
|
24
|
+
"enabled" = 'TRUE',
|
|
25
|
+
"deleted" = NULL,
|
|
26
|
+
"coreEmail" = NULL,
|
|
27
|
+
"corePhone" = NULL,
|
|
28
|
+
"coreAddress" = NULL
|
|
29
|
+
WHERE id = core_id;
|
|
30
|
+
END IF;
|
|
31
|
+
-- assign id to variable; STRICT requires exactly one row be found
|
|
32
|
+
SELECT id INTO STRICT core_id FROM public.cores WHERE facility = core_name;
|
|
33
|
+
|
|
34
|
+
IF NOT EXISTS (
|
|
35
|
+
SELECT 1 FROM public.core_accounts WHERE "coreId" = core_id
|
|
36
|
+
) THEN
|
|
37
|
+
INSERT INTO public.core_accounts ("coreId", account, effective)
|
|
38
|
+
VALUES (core_id, account_number, '2019-09-01');
|
|
39
|
+
ELSE
|
|
40
|
+
UPDATE public.core_accounts SET account = account_number, effective = '2019-09-01'
|
|
41
|
+
WHERE "coreId" = core_id AND effective = (SELECT MAX(effective)
|
|
42
|
+
FROM public.core_accounts WHERE "coreId" = core_id);
|
|
43
|
+
END IF;
|
|
44
|
+
|
|
45
|
+
-- there are unique constraints on users.userId and user_cores.(coreId + userId)
|
|
46
|
+
INSERT INTO public.users ("userId") VALUES ('c8ae172ea6c8779b64d563086510aeea')
|
|
47
|
+
ON CONFLICT DO NOTHING;
|
|
48
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
49
|
+
WHERE "userId" = 'c8ae172ea6c8779b64d563086510aeea';
|
|
50
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
51
|
+
ON CONFLICT DO NOTHING;
|
|
52
|
+
|
|
53
|
+
INSERT INTO public.users ("userId") VALUES ('72f3ee7aa427b0fef432f2658def0270')
|
|
54
|
+
ON CONFLICT DO NOTHING;
|
|
55
|
+
SELECT id INTO STRICT user_id FROM public.users
|
|
56
|
+
WHERE "userId" = '72f3ee7aa427b0fef432f2658def0270';
|
|
57
|
+
INSERT INTO public.user_cores ("coreId", "userId", email) VALUES (core_id, user_id, TRUE)
|
|
58
|
+
ON CONFLICT DO NOTHING;
|
|
59
|
+
END $$ ;
|
|
60
|
+
COMMIT;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
BEGIN TRANSACTION;
|
|
2
|
+
|
|
3
|
+
-- Update procedure to set NULL when alt_bank values are missing, but would
|
|
4
|
+
-- otherwise be used to determine IDT status. Now FALSE definitively means
|
|
5
|
+
-- "force AR"; when NULL, the billing code will look at the budget_support_account
|
|
6
|
+
-- and/or the parent account.
|
|
7
|
+
CREATE OR REPLACE FUNCTION update_idt_allowed() RETURNS boolean
|
|
8
|
+
AS $$
|
|
9
|
+
DECLARE
|
|
10
|
+
row record;
|
|
11
|
+
allowed BOOLEAN := NULL;
|
|
12
|
+
BEGIN
|
|
13
|
+
FOR row IN SELECT uid, a.campus_code, default_bank, bank_override, alt_bank1, alt_bank2,
|
|
14
|
+
alt_bank3, alt_bank4, alt_bank5
|
|
15
|
+
FROM accounts a LEFT JOIN alt_bank ab ON a.campus_code = ab.campus_code AND a.account = ab.account
|
|
16
|
+
AND a.support_account = ab.support_account AND a.fiscal_year = ab.fiscal_year
|
|
17
|
+
LOOP
|
|
18
|
+
-- part 09 (TEEX) doesn't use FAMIS directly and is thus always forced AR
|
|
19
|
+
if row.campus_code = '09' then
|
|
20
|
+
allowed = FALSE;
|
|
21
|
+
elsif bank_idt(row.default_bank) then
|
|
22
|
+
allowed = TRUE;
|
|
23
|
+
elsif row.bank_override = TRUE then
|
|
24
|
+
if row.alt_bank1 IS NULL then
|
|
25
|
+
allowed = NULL;
|
|
26
|
+
elsif bank_idt(row.alt_bank1) OR bank_idt(row.alt_bank2)
|
|
27
|
+
OR bank_idt(row.alt_bank3) OR bank_idt(row.alt_bank4)
|
|
28
|
+
OR bank_idt(row.alt_bank5) then
|
|
29
|
+
allowed = TRUE;
|
|
30
|
+
else
|
|
31
|
+
allowed = FALSE;
|
|
32
|
+
end if;
|
|
33
|
+
else
|
|
34
|
+
allowed = FALSE;
|
|
35
|
+
end if;
|
|
36
|
+
|
|
37
|
+
UPDATE accounts SET idt_allowed = allowed WHERE uid = row.uid;
|
|
38
|
+
END LOOP;
|
|
39
|
+
RETURN TRUE;
|
|
40
|
+
END;
|
|
41
|
+
$$ LANGUAGE plpgsql;
|
|
42
|
+
|
|
43
|
+
-- update the table accordingly
|
|
44
|
+
SELECT update_idt_allowed();
|
|
45
|
+
|
|
46
|
+
COMMIT;
|