-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path06-create_dummy_data.sql
68 lines (52 loc) · 2.25 KB
/
06-create_dummy_data.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Deploy website:06-create_dummy_data to pg
-- requires: 05-create_filesystem_table
BEGIN;
-- XXX Add DDLs here.
SET timezone = 'Australia/Sydney';
/* Create default groups */
INSERT INTO groups (Name, Permission) VALUES ('admin', 'delete');
INSERT INTO groups (name, Permission) VALUES ('user', 'write');
/* Setup FS table and modify constraints */
/* Insert root directory and then add our constraints */
DO $$
DECLARE
randomGroup groups.UID%type;
rootID filesystem.EntityID%type;
BEGIN
SELECT groups.UID INTO randomGroup FROM groups WHERE Name = 'admin'::VARCHAR;
/* Insert the root directory */
INSERT INTO filesystem (EntityID, LogicalName, OwnedBy)
VALUES (uuid_nil(), 'root', randomGroup);
SELECT filesystem.EntityID INTO rootID FROM filesystem WHERE LogicalName = 'root'::VARCHAR;
/* Set parent to uuid_nil() because postgres driver has issue supporting NULL values */
UPDATE filesystem SET Parent = uuid_nil() WHERE EntityID = rootID;
/* insert "has parent" constraint*/
EXECUTE 'ALTER TABLE filesystem
ADD CONSTRAINT has_parent CHECK (Parent != NULL)';
END $$;
/* create a dummy frontend */
INSERT INTO frontend (FrontendURL) VALUES ('http://localhost:8080'::VARCHAR);
/* Insert dummy data */
DO $$
DECLARE
rootID filesystem.EntityID%type;
newEntity filesystem.EntityID%type;
wasPopping filesystem.EntityID%type;
oldEntity filesystem.EntityID%type;
BEGIN
SELECT filesystem.EntityID INTO rootID FROM filesystem WHERE EntityID = uuid_nil();
newEntity := (SELECT new_entity(rootID, 'downloads'::VARCHAR, 1, false));
oldEntity := (SELECT new_entity(rootID, 'documents'::VARCHAR, 1, false));
wasPopping := (SELECT new_entity(oldEntity, 'cool_document'::VARCHAR, 1, true));
wasPopping := (SELECT new_entity(oldEntity, 'cool_document_round_2'::VARCHAR, 1, true));
PERFORM delete_entity(wasPopping);
wasPopping := (SELECT new_entity(oldEntity, 'cool_document_round_2'::VARCHAR, 1, true));
END $$;
/* inserting two accounts into db */
DO LANGUAGE plpgsql $$
BEGIN
EXECUTE create_normal_user('[email protected]', 'adam', 'password', 1);
EXECUTE create_normal_user('[email protected]', 'john', 'password', 1);
EXECUTE create_normal_user('[email protected]', 'jane', 'password', 1);
END $$;
COMMIT;