Skip to content

Commit

Permalink
chore: style sql
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Nov 13, 2023
1 parent 0602fc0 commit c0e01dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion migrations/1664117744_init.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE SCHEMA IF NOT EXISTS public;
CREATE SCHEMA IF NOT EXISTS public;
13 changes: 6 additions & 7 deletions migrations/1664117746_create-clients.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
CREATE TYPE public.provider AS ENUM ('fcm', 'apns', 'noop');

CREATE TABLE IF NOT EXISTS public.clients
(
id varchar(255) primary key default gen_random_uuid(),
CREATE TABLE public.clients (
id varchar(255) PRIMARY KEY DEFAULT gen_random_uuid(),

push_type public.provider not null,
device_token text not null,
push_type public.provider NOT NULL,
device_token text NOT NULL,

created_at timestamptz not null default now()
);
created_at timestamptz NOT NULL DEFAULT now()
);
17 changes: 8 additions & 9 deletions migrations/1664117751_create-notifications.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
CREATE TABLE IF NOT EXISTS public.notifications
(
id varchar(255) primary key,
client_id varchar(255) not null,
CREATE TABLE public.notifications (
id varchar(255) PRIMARY KEY,
client_id varchar(255) NOT NULL,

last_payload jsonb not null default '{}'::jsonb,
previous_payloads jsonb[] not null default array []::jsonb[],
last_payload jsonb NOT NULL DEFAULT '{}'::jsonb,
previous_payloads jsonb[] NOT NULL DEFAULT ARRAY[]::jsonb[],

last_received_at timestamptz not null default now(),
created_at timestamptz not null default now(),
last_received_at timestamptz NOT NULL DEFAULT now(),
created_at timestamptz NOT NULL DEFAULT now(),

CONSTRAINT fk_notifications_client_id FOREIGN KEY (client_id)
REFERENCES public.clients (id)
);
);
8 changes: 4 additions & 4 deletions migrations/1667510128_add-tenant-id.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
alter table public.clients
add tenant_id varchar(255) not null default '0000-0000-0000-0000';
ALTER TABLE public.clients
ADD tenant_id varchar(255) NOT NULL DEFAULT '0000-0000-0000-0000';

alter table public.notifications
add tenant_id varchar(255) not null default '0000-0000-0000-0000';
ALTER table public.notifications
ADD tenant_id varchar(255) NOT NULL DEFAULT '0000-0000-0000-0000';
8 changes: 4 additions & 4 deletions migrations/1695631804_add-unique-device-tokens.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
DELETE FROM public.clients
WHERE (device_token, created_at) NOT IN
(
WHERE (device_token, created_at) NOT IN (
SELECT device_token, MAX(created_at)
FROM public.clients
GROUP BY device_token
);
ALTER TABLE public.clients
ADD CONSTRAINT device_token_unique UNIQUE(device_token);

ALTER TABLE public.clients
ADD CONSTRAINT device_token_unique UNIQUE (device_token);

0 comments on commit c0e01dd

Please sign in to comment.