Skip to content

Commit

Permalink
chore: Revert "chore: style sql (#277)"
Browse files Browse the repository at this point in the history
This reverts commit 70dad11.
  • Loading branch information
chris13524 committed Nov 15, 2023
1 parent 70dad11 commit ea1401e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 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: 7 additions & 6 deletions migrations/1664117746_create-clients.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
CREATE TYPE public.provider AS ENUM ('fcm', 'apns', 'noop');

CREATE TABLE public.clients (
id varchar(255) PRIMARY KEY DEFAULT gen_random_uuid(),
CREATE TABLE IF NOT EXISTS 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: 9 additions & 8 deletions migrations/1664117751_create-notifications.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
CREATE TABLE public.notifications (
id varchar(255) PRIMARY KEY,
client_id varchar(255) NOT NULL,
CREATE TABLE IF NOT EXISTS 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';
16 changes: 8 additions & 8 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 (
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);
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);

0 comments on commit ea1401e

Please sign in to comment.