-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
29 lines (27 loc) · 1.02 KB
/
Copy pathschema.sql
File metadata and controls
29 lines (27 loc) · 1.02 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
CREATE TABLE IF NOT EXISTS companies (
external_id TEXT PRIMARY KEY,
name TEXT NOT NULL,
category TEXT NOT NULL,
city TEXT NOT NULL,
address TEXT NOT NULL,
rating NUMERIC(2, 1),
reviews_count INTEGER NOT NULL,
site TEXT,
phone TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT companies_rating_range CHECK (rating IS NULL OR rating BETWEEN 0 AND 5),
CONSTRAINT companies_reviews_nonnegative CHECK (reviews_count >= 0)
);
CREATE TABLE IF NOT EXISTS import_rejects (
id BIGSERIAL PRIMARY KEY,
source_file TEXT NOT NULL,
row_number INTEGER NOT NULL,
reason TEXT NOT NULL,
payload JSONB NOT NULL,
rejected_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT import_rejects_source_row_unique UNIQUE (source_file, row_number)
);
CREATE INDEX IF NOT EXISTS companies_city_idx ON companies (city);
CREATE INDEX IF NOT EXISTS companies_category_idx ON companies (category);
CREATE INDEX IF NOT EXISTS companies_name_lower_idx ON companies (lower(name));