-
Notifications
You must be signed in to change notification settings - Fork 3
/
schema.js
44 lines (38 loc) · 931 Bytes
/
schema.js
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
import { DB } from "https://deno.land/x/sqlite/mod.ts";
try {
await Deno.remove("wbd-db.db");
} catch {
// nothing to remove
}
const db = new DB("./wbd-db.db");
await db.query(
`CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
salt TEXT NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
)`
);
await db.query(
`CREATE TABLE sessions (
uuid TEXT PRIMARY KEY,
created_at DATETIME NOT NULL,
user_id INTEGER,
FOREIGN KEY(user_id) REFERENCES users(id)
)`
);
await db.query(
`CREATE TABLE searches (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_at DATETIME NOT NULL,
country TEXT NOT NULL,
indicator TEXT,
start_year INTEGER NOT NULL,
end_year INTEGER NOT NULL,
user_id INTEGER REFERENCES users(id)
)`
);
//run using
// deno run --allow-net --allow-read --allow-write schema.js