-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobly-schema.sql
34 lines (31 loc) · 880 Bytes
/
jobly-schema.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
CREATE TABLE companies (
handle VARCHAR(25) PRIMARY KEY CHECK (handle = lower(handle)),
name TEXT UNIQUE NOT NULL,
num_employees INTEGER CHECK (num_employees >= 0),
description TEXT NOT NULL,
logo_url TEXT
);
CREATE TABLE users (
username VARCHAR(25) PRIMARY KEY,
password TEXT NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT NOT NULL
CHECK (position('@' IN email) > 1),
is_admin BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE jobs (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
salary INTEGER CHECK (salary >= 0),
equity NUMERIC CHECK (equity <= 1.0),
company_handle VARCHAR(25) NOT NULL
REFERENCES companies ON DELETE CASCADE
);
CREATE TABLE applications (
username VARCHAR(25)
REFERENCES users ON DELETE CASCADE,
job_id INTEGER
REFERENCES jobs ON DELETE CASCADE,
PRIMARY KEY (username, job_id)
);