-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqattend.sql
More file actions
145 lines (130 loc) · 4.8 KB
/
qattend.sql
File metadata and controls
145 lines (130 loc) · 4.8 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-- RESET
DROP TABLE IF EXISTS attendance, ticket, event, membership, users, organization;
-- STRUCTURE
CREATE TABLE organization
(
id serial NOT NULL,
username character varying(100) NOT NULL,
password character varying(100) NOT NULL,
name character varying(100) NOT NULL,
email character varying(100) NOT NULL,
photo character varying(255),
about character varying(255),
created_at timestamp NOT NULL,
last_login timestamp NOT NULL,
member_count integer NOT NULL DEFAULT 0,
CONSTRAINT organization_pkey PRIMARY KEY (id ),
CONSTRAINT organization_username_key UNIQUE (username )
);
CREATE TABLE users
(
id serial NOT NULL,
username character varying(100) NOT NULL,
password character varying(100) NOT NULL,
name character varying(100) NOT NULL,
email character varying(100),
photo character varying(255),
about character varying(255),
phone character varying(20),
created_at timestamp NOT NULL,
CONSTRAINT users_pkey PRIMARY KEY (id ),
CONSTRAINT users_username_key UNIQUE (username )
);
CREATE TABLE membership
(
org_id serial NOT NULL,
user_id serial NOT NULL,
approved boolean NOT NULL DEFAULT false,
joined_at timestamp NOT NULL,
qrcode character varying(255),
CONSTRAINT membership_pkey PRIMARY KEY (org_id , user_id ),
CONSTRAINT membership_org_id_fkey FOREIGN KEY (org_id)
REFERENCES organization (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT membership_user_id_fkey FOREIGN KEY (user_id)
REFERENCES users (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE event
(
id serial NOT NULL,
title character varying(255) NOT NULL,
photo character varying(255),
org_id serial NOT NULL,
created_at timestamp NOT NULL,
start_time timestamp,
end_time timestamp,
location character varying(255),
description character varying(255),
public boolean NOT NULL DEFAULT false,
ticket_count integer NOT NULL DEFAULT 0,
CONSTRAINT event_pkey PRIMARY KEY (id ),
CONSTRAINT event_org_id_fkey FOREIGN KEY (org_id)
REFERENCES organization (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE ticket
(
user_id serial NOT NULL,
event_id serial NOT NULL,
id serial NOT NULL,
CONSTRAINT ticket_pkey PRIMARY KEY (id ),
CONSTRAINT ticket_event_id_fkey FOREIGN KEY (event_id)
REFERENCES event (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT ticket_user_id_fkey FOREIGN KEY (user_id)
REFERENCES users (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE attendance
(
id serial NOT NULL,
ticket_id serial NOT NULL,
verified_at timestamp NOT NULL,
CONSTRAINT attendance_pkey PRIMARY KEY (id ),
CONSTRAINT attendance_ticket_id_fkey FOREIGN KEY (ticket_id)
REFERENCES ticket (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- DATA
INSERT INTO organization (username, password, name, email, created_at, last_login) VALUES
('mpc', 'mpc', 'Mikroskil Programming Club', 'mpc@gmail.com', now(), now());
INSERT INTO users (username, password, name, created_at) VALUES
('erwin', 'erwin', 'Erwin', now()),
('alpintaisei', 'alpintaisei', 'Alpin Taisei', now()),
('herrygozali', 'herrygozali', 'Herry Gozali', now());
INSERT INTO membership (org_id, user_id, approved, joined_at) VALUES
(1, 1, true, now()),
(1, 2, true, now()),
(1, 3, false, now());
UPDATE organization SET member_count=3 where id=1;
INSERT INTO event (title, org_id, created_at, start_time, end_time, photo, location, description) VALUES
('Hello World Meetup', 1, now(), now(), now(), 'resources/event_1.jpg', 'T2/L3 Kampus B, STMIK-STIE Mikroskil', 'This is the description'),
('Basecamp & Hackathon', 1, now(), now(), now(), 'resources/event_1.jpg', 'STMIK-STIE Mikroskil', 'This is the description'),
('Algorithm Basic Class', 1, now(), now(), now(), 'resources/event_1.jpg', 'Lab. 2 Kampus A, STMIK-STIE Mikroskil', 'This is the description'),
('Algorithm Intermediate Class', 1, now(), now(), now(), 'resources/event_1.jpg', 'Lab. 2 Kampus A, STMIK-STIE Mikroskil', 'This is the description'),
('Algorithm Advance Class', 1, now(), now(), now(), 'resources/event_1.jpg', 'Lab. 2 Kampus A, STMIK-STIE Mikroskil', 'This is the description'),
('TechSpeak: The State of Indonesia''s mobile landspace', 1, now(), now(), now(), 'resources/event_1.jpg', 'T2/L3 Kampus B, STMIK-STIE Mikroskil', 'This is the description');
INSERT INTO ticket (user_id, event_id) VALUES
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(2, 1),
(2, 2),
(2, 4),
(3, 1),
(3, 4);
UPDATE event SET ticket_count=3 where id=1;
UPDATE event SET ticket_count=2 where id=2;
UPDATE event SET ticket_count=1 where id=3;
UPDATE event SET ticket_count=3 where id=4;
INSERT INTO attendance (ticket_id, verified_at) VALUES
(1, now()),
(2, now()),
(3, now()),
(4, now()),
(5, now()),
(6, now()),
(7, now()),
(8, now());