· 8 years ago · Feb 20, 2018, 06:20 AM
1create extension if not exists "uuid-ossp";
2
3create table business (
4 id uuid default uuid_generate_v4() primary key,
5 name character varying not null
6);
7
8create table customer (
9 id uuid default uuid_generate_v4() primary key,
10 business_id uuid references business(id),
11 name character varying not null,
12 profile_data jsonb default '{}'::jsonb not null,
13 created_at timestamp without time zone not null,
14 updated_at timestamp without time zone not null,
15 deleted_at timestamp without time zone
16);
17
18create table email (
19 id uuid default uuid_generate_v4() primary key,
20 customer_id uuid references customer(id),
21 email_address character varying not null,
22 created_at timestamp without time zone not null,
23 updated_at timestamp without time zone not null,
24 deleted_at timestamp without time zone
25);
26
27create index idx_deleted_at_on_email on email using btree (deleted_at);
28create index idx_customer_id_on_email on email using btree (customer_id);
29
30
31create table phone (
32 id uuid default uuid_generate_v4() primary key,
33 customer_id uuid references customer(id),
34 phone_number character varying not null,
35 national_format character varying not null,
36 created_at timestamp without time zone not null,
37 updated_at timestamp without time zone not null,
38 deleted_at timestamp without time zone
39);
40
41create index idx_deleted_at_on_phone on phone using btree (deleted_at);
42create index idx_customer_id_on_phone on phone using btree (customer_id);