-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.sql
63 lines (55 loc) · 2.04 KB
/
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
DROP TABLE IF EXISTS companies CASCADE;
DROP TABLE IF EXISTS jobs CASCADE;
DROP TABLE IF EXISTS users CASCADE;
DROP TABLE IF EXISTS applications CASCADE;
DROP TYPE IF EXISTS enum;
DROP TABLE IF EXISTS technologies CASCADE;
DROP TABLE IF EXISTS job_technologies CASCADE;
DROP TABLE IF EXISTS user_technologies CASCADE;
CREATE TABLE companies (
handle TEXT PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
num_employees INTEGER,
description TEXT,
logo_url TEXT
);
CREATE TABLE jobs (
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
title TEXT NOT NULL,
salary FLOAT NOT NULL,
equity FLOAT NOT NULL,
company_handle TEXT NOT NULL REFERENCES companies ON DELETE CASCADE,
date_posted TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
CONSTRAINT max_equity_check CHECK ((equity < 1))
);
CREATE TABLE users (
username TEXT PRIMARY KEY,
password TEXT NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
photo_url TEXT DEFAULT 'https://cdn3.vectorstock.com/i/1000x1000/21/62/human-icon-in-circle-vector-25482162.jp',
is_admin BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TYPE enum AS ENUM ('interested', 'applied', 'accepted', 'rejected');
CREATE TABLE applications (
username TEXT NOT NULL REFERENCES users ON DELETE CASCADE,
job_id INTEGER NOT NULL REFERENCES jobs ON DELETE CASCADE,
state enum NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
CONSTRAINT app_pk PRIMARY KEY(username,job_id)
);
CREATE TABLE technologies (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
technology TEXT NOT NULL
);
CREATE TABLE job_technologies (
job_id INTEGER NOT NULL REFERENCES jobs ON DELETE CASCADE,
technologies_id INTEGER NOT NULL REFERENCES technologies ON DELETE CASCADE,
PRIMARY KEY(job_id, technologies_id)
);
CREATE TABLE user_technologies (
username TEXT NOT NULL REFERENCES users ON DELETE CASCADE,
technologies_id INTEGER NOT NULL REFERENCES technologies ON DELETE CASCADE,
PRIMARY KEY(username, technologies_id)
);