-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
66 lines (57 loc) · 2.36 KB
/
init.sql
File metadata and controls
66 lines (57 loc) · 2.36 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
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
64
65
66
-- Monix schema bootstrap for local Postgres.
-- Apply this file to a fresh database to create all Monix tables.
create extension if not exists "pgcrypto";
create table if not exists public.monix_users (
id uuid primary key,
email text,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now(),
first_name text not null default '',
last_name text not null default '',
password_hash text,
avatar_url text not null default '',
reset_token_hash text,
reset_token_expires_at timestamptz,
google_sub text unique
);
-- Migration for existing databases:
-- alter table public.monix_users add column if not exists google_sub text unique;
create table if not exists public.monix_targets (
id uuid primary key default gen_random_uuid(),
owner_id uuid not null references public.monix_users (id) on delete cascade,
url text not null,
environment text not null default '',
gsc_property_url text not null default '',
gsc_analytics jsonb,
gsc_synced_at timestamptz,
gsc_sync_error text not null default '',
created_at timestamptz not null default now()
);
create index if not exists monix_targets_owner_idx on public.monix_targets (owner_id);
create table if not exists public.monix_scans (
id bigserial primary key,
target_id uuid references public.monix_targets (id) on delete set null,
report_id uuid not null unique,
url text not null,
score smallint not null check (score >= 0 and score <= 100),
results jsonb not null,
is_expired boolean not null default false,
expires_at timestamptz not null,
created_at timestamptz not null default now()
);
create index if not exists monix_scans_report_id_idx on public.monix_scans (report_id);
create table if not exists public.monix_gsc_credentials (
user_id uuid primary key references public.monix_users (id) on delete cascade,
refresh_token_encrypted text not null,
access_token text not null default '',
access_token_expires_at timestamptz,
updated_at timestamptz not null default now()
);
create table if not exists public.monix_cloudflare_credentials (
user_id uuid primary key references public.monix_users (id) on delete cascade,
api_token_encrypted text not null,
account_id text not null default '',
account_name text not null default '',
zones_count integer not null default 0 check (zones_count >= 0),
updated_at timestamptz not null default now()
);