From 70dad115bd1a5ce3448c829c291e9159da7f2baa Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:07:47 -0500 Subject: [PATCH 1/2] chore: style sql (#277) --- migrations/1664117744_init.sql | 2 +- migrations/1664117746_create-clients.sql | 13 ++++++------- migrations/1664117751_create-notifications.sql | 17 ++++++++--------- migrations/1667510128_add-tenant-id.sql | 8 ++++---- .../1695631804_add-unique-device-tokens.sql | 16 ++++++++-------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/migrations/1664117744_init.sql b/migrations/1664117744_init.sql index 698881b8..9eea712c 100644 --- a/migrations/1664117744_init.sql +++ b/migrations/1664117744_init.sql @@ -1 +1 @@ -CREATE SCHEMA IF NOT EXISTS public; \ No newline at end of file +CREATE SCHEMA IF NOT EXISTS public; diff --git a/migrations/1664117746_create-clients.sql b/migrations/1664117746_create-clients.sql index 3c024e80..7cc45f94 100644 --- a/migrations/1664117746_create-clients.sql +++ b/migrations/1664117746_create-clients.sql @@ -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() -); \ No newline at end of file + created_at timestamptz NOT NULL DEFAULT now() +); diff --git a/migrations/1664117751_create-notifications.sql b/migrations/1664117751_create-notifications.sql index 3638c60a..9aef1a18 100644 --- a/migrations/1664117751_create-notifications.sql +++ b/migrations/1664117751_create-notifications.sql @@ -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) -); \ No newline at end of file +); diff --git a/migrations/1667510128_add-tenant-id.sql b/migrations/1667510128_add-tenant-id.sql index d1f42129..e89c3d11 100644 --- a/migrations/1667510128_add-tenant-id.sql +++ b/migrations/1667510128_add-tenant-id.sql @@ -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'; diff --git a/migrations/1695631804_add-unique-device-tokens.sql b/migrations/1695631804_add-unique-device-tokens.sql index 95481167..cc114a50 100644 --- a/migrations/1695631804_add-unique-device-tokens.sql +++ b/migrations/1695631804_add-unique-device-tokens.sql @@ -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); From ea1401e818aae6cf7ab0b0819cf4358f2469608b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 15 Nov 2023 15:47:50 -0500 Subject: [PATCH 2/2] chore: Revert "chore: style sql (#277)" This reverts commit 70dad115bd1a5ce3448c829c291e9159da7f2baa. --- migrations/1664117744_init.sql | 2 +- migrations/1664117746_create-clients.sql | 13 +++++++------ migrations/1664117751_create-notifications.sql | 17 +++++++++-------- migrations/1667510128_add-tenant-id.sql | 8 ++++---- .../1695631804_add-unique-device-tokens.sql | 16 ++++++++-------- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/migrations/1664117744_init.sql b/migrations/1664117744_init.sql index 9eea712c..698881b8 100644 --- a/migrations/1664117744_init.sql +++ b/migrations/1664117744_init.sql @@ -1 +1 @@ -CREATE SCHEMA IF NOT EXISTS public; +CREATE SCHEMA IF NOT EXISTS public; \ No newline at end of file diff --git a/migrations/1664117746_create-clients.sql b/migrations/1664117746_create-clients.sql index 7cc45f94..3c024e80 100644 --- a/migrations/1664117746_create-clients.sql +++ b/migrations/1664117746_create-clients.sql @@ -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() +); \ No newline at end of file diff --git a/migrations/1664117751_create-notifications.sql b/migrations/1664117751_create-notifications.sql index 9aef1a18..3638c60a 100644 --- a/migrations/1664117751_create-notifications.sql +++ b/migrations/1664117751_create-notifications.sql @@ -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) -); +); \ No newline at end of file diff --git a/migrations/1667510128_add-tenant-id.sql b/migrations/1667510128_add-tenant-id.sql index e89c3d11..d1f42129 100644 --- a/migrations/1667510128_add-tenant-id.sql +++ b/migrations/1667510128_add-tenant-id.sql @@ -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'; diff --git a/migrations/1695631804_add-unique-device-tokens.sql b/migrations/1695631804_add-unique-device-tokens.sql index cc114a50..95481167 100644 --- a/migrations/1695631804_add-unique-device-tokens.sql +++ b/migrations/1695631804_add-unique-device-tokens.sql @@ -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);