-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabaseExampleQueries.sql
81 lines (70 loc) · 1.78 KB
/
databaseExampleQueries.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
69
70
71
72
73
74
75
76
77
78
79
80
81
-- This file is only my notes, changing
-- this file doesn't change anything in
-- the database
-- Create isers table
CREATE TABLE users(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
username varchar(90) NOT NULL,
password_hash varchar(70) NOT NULL,
account_id integer,
role_name varchar(40),
email varchar(90),
is_email_validated boolean,
registration_token varchar,
);
-- Insert some animals (C in CRUD - Create)
INSERT INTO users
(username, password_hash, account_id, role_name, email, is_email_validated, registration_token)
VALUES
/* ('Ralph', 'Tiger', 'Gold chain'),
('Evelina', 'Hedgehog', 'Comb'),
('Otto', 'Otter', 'Stone'),
('Mayo', 'Dog', 'Sweater'),
('Kaaaarl', 'Llama', 'Toque'); */
-- Read some users (R in CRUD - Read)
SELECT * FROM users;
/* incidents */
export async function up(sql) {
await sql`
CREATE TABLE incidents (
id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
category varchar(50) NOT NULL,
coordinates json(110) NOT NULL
)
`;
}
export async function down(sql) {
await sql`
DROP TABLE incidents
`;
}
/* drones */
export async function up(sql) {
await sql`
CREATE TABLE drones (
id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
registration_data varchar(110) NOT NULL,
origin json(110) NOT NULL
)
`;
}
export async function down(sql) {
await sql`
DROP TABLE drones
`;
}
/* incidents with drones (many-to-many) */
export async function up(sql) {
await sql`
CREATE TABLE drones_incidents (
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
incident_id integer REFERENCES incidents (id),
drone_id integer REFERENCES drones (id)
)
`;
}
export async function down(sql) {
await sql`
DROP TABLE drones_incidents
`;
}