feat(ui): add message cache management page and dashboard enhancements
- Introduced MessageCachePage for browsing and managing cached webhook events. - Enhanced DashboardPage to display runtime stats and message cache information. - Added new API types for message cache events and system stats. - Integrated SwaggerPage for API documentation and live request testing.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
DROP TABLE IF EXISTS public.message_cache CASCADE;
|
||||
DROP TABLE IF EXISTS public.sessions CASCADE;
|
||||
DROP TABLE IF EXISTS public.event_logs CASCADE;
|
||||
DROP TABLE IF EXISTS public.whatsapp_accounts CASCADE;
|
||||
DROP TABLE IF EXISTS public.whatsapp_account CASCADE;
|
||||
DROP TABLE IF EXISTS public.hooks CASCADE;
|
||||
DROP TABLE IF EXISTS public.api_keys CASCADE;
|
||||
DROP TABLE IF EXISTS public.users CASCADE;
|
||||
|
||||
+169
-147
@@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS public.hooks (
|
||||
user_id varchar(36) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.whatsapp_accounts (
|
||||
CREATE TABLE IF NOT EXISTS public.whatsapp_account (
|
||||
account_type varchar(50) NOT NULL,
|
||||
active boolean NOT NULL DEFAULT true,
|
||||
config text,
|
||||
@@ -94,15 +94,18 @@ CREATE TABLE IF NOT EXISTS public.sessions (
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.message_cache (
|
||||
account_id varchar(36) NOT NULL,
|
||||
chat_id varchar(255) NOT NULL,
|
||||
content text NOT NULL,
|
||||
created_at timestamp NOT NULL DEFAULT now(),
|
||||
from_me boolean NOT NULL,
|
||||
id varchar(36) NOT NULL,
|
||||
message_id varchar(255) NOT NULL,
|
||||
message_type varchar(50) NOT NULL,
|
||||
timestamp timestamp NOT NULL
|
||||
id varchar(128) NOT NULL,
|
||||
account_id varchar(64) NOT NULL DEFAULT '',
|
||||
event_type varchar(100) NOT NULL,
|
||||
event_data jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||
message_id varchar(255) NOT NULL DEFAULT '',
|
||||
from_number varchar(64) NOT NULL DEFAULT '',
|
||||
to_number varchar(64) NOT NULL DEFAULT '',
|
||||
reason text NOT NULL DEFAULT '',
|
||||
attempts integer NOT NULL DEFAULT 0,
|
||||
timestamp timestamptz NOT NULL DEFAULT now(),
|
||||
last_attempt timestamptz,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Add missing columns for schema: public
|
||||
@@ -592,10 +595,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'account_type'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN account_type varchar(50) NOT NULL;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN account_type varchar(50) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -605,10 +608,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'active'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN active boolean NOT NULL DEFAULT true;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN active boolean NOT NULL DEFAULT true;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -618,10 +621,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'config'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN config text;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN config text;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -631,10 +634,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'created_at'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN created_at timestamp NOT NULL DEFAULT now();
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN created_at timestamp NOT NULL DEFAULT now();
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -644,10 +647,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'deleted_at'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN deleted_at timestamp;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN deleted_at timestamp;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -657,10 +660,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'display_name'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN display_name varchar(255);
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN display_name varchar(255);
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -670,10 +673,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'id'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN id varchar(36) NOT NULL;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN id varchar(36) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -683,10 +686,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'last_connected_at'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN last_connected_at timestamp;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN last_connected_at timestamp;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -696,10 +699,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'phone_number'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN phone_number varchar(50) NOT NULL;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN phone_number varchar(50) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -709,10 +712,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'session_path'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN session_path text;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN session_path text;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -722,10 +725,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'status'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN status varchar(50) NOT NULL DEFAULT 'disconnected';
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN status varchar(50) NOT NULL DEFAULT 'disconnected';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -735,10 +738,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'updated_at'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN updated_at timestamp NOT NULL DEFAULT now();
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN updated_at timestamp NOT NULL DEFAULT now();
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -748,10 +751,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND column_name = 'user_id'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD COLUMN user_id varchar(36) NOT NULL;
|
||||
ALTER TABLE public.whatsapp_account ADD COLUMN user_id varchar(36) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1016,71 +1019,6 @@ BEGIN
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'account_id'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN account_id varchar(36) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'chat_id'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN chat_id varchar(255) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'content'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN content text NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'created_at'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN created_at timestamp NOT NULL DEFAULT now();
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'from_me'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN from_me boolean NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
@@ -1089,7 +1027,46 @@ BEGIN
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'id'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN id varchar(36) NOT NULL;
|
||||
ALTER TABLE public.message_cache ADD COLUMN id varchar(128) NOT NULL;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'account_id'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN account_id varchar(64) NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'event_type'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN event_type varchar(100) NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'event_data'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN event_data jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1102,7 +1079,7 @@ BEGIN
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'message_id'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN message_id varchar(255) NOT NULL;
|
||||
ALTER TABLE public.message_cache ADD COLUMN message_id varchar(255) NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1113,9 +1090,48 @@ BEGIN
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'message_type'
|
||||
AND column_name = 'from_number'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN message_type varchar(50) NOT NULL;
|
||||
ALTER TABLE public.message_cache ADD COLUMN from_number varchar(64) NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'to_number'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN to_number varchar(64) NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'reason'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN reason text NOT NULL DEFAULT '';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'attempts'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN attempts integer NOT NULL DEFAULT 0;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1128,7 +1144,33 @@ BEGIN
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'timestamp'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN timestamp timestamp NOT NULL;
|
||||
ALTER TABLE public.message_cache ADD COLUMN timestamp timestamptz NOT NULL DEFAULT now();
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'last_attempt'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN last_attempt timestamptz;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND column_name = 'created_at'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD COLUMN created_at timestamptz NOT NULL DEFAULT now();
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1226,22 +1268,22 @@ BEGIN
|
||||
SELECT constraint_name INTO auto_pk_name
|
||||
FROM information_schema.table_constraints
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND constraint_type = 'PRIMARY KEY'
|
||||
AND constraint_name IN ('whatsapp_accounts_pkey', 'public_whatsapp_accounts_pkey');
|
||||
AND constraint_name IN ('whatsapp_account_pkey', 'public_whatsapp_account_pkey');
|
||||
|
||||
IF auto_pk_name IS NOT NULL THEN
|
||||
EXECUTE 'ALTER TABLE public.whatsapp_accounts DROP CONSTRAINT ' || quote_ident(auto_pk_name);
|
||||
EXECUTE 'ALTER TABLE public.whatsapp_account DROP CONSTRAINT ' || quote_ident(auto_pk_name);
|
||||
END IF;
|
||||
|
||||
-- Add named primary key if it doesn't exist
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND constraint_name = 'pk_public_whatsapp_accounts'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND constraint_name = 'pk_public_whatsapp_account'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD CONSTRAINT pk_public_whatsapp_accounts PRIMARY KEY (id);
|
||||
ALTER TABLE public.whatsapp_account ADD CONSTRAINT pk_public_whatsapp_account PRIMARY KEY (id);
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1346,11 +1388,11 @@ CREATE INDEX IF NOT EXISTS idx_hooks_deleted_at
|
||||
CREATE INDEX IF NOT EXISTS idx_hooks_user_id
|
||||
ON public.hooks USING btree (user_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_accounts_deleted_at
|
||||
ON public.whatsapp_accounts USING btree (deleted_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_account_deleted_at
|
||||
ON public.whatsapp_account USING btree (deleted_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_accounts_user_id
|
||||
ON public.whatsapp_accounts USING btree (user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_account_user_id
|
||||
ON public.whatsapp_account USING btree (user_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_event_logs_created_at
|
||||
ON public.event_logs USING btree (created_at);
|
||||
@@ -1373,17 +1415,11 @@ CREATE INDEX IF NOT EXISTS idx_sessions_expires_at
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_user_id
|
||||
ON public.sessions USING btree (user_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_account_id
|
||||
ON public.message_cache USING btree (account_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_chat_id
|
||||
ON public.message_cache USING btree (chat_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_from_me
|
||||
ON public.message_cache USING btree (from_me);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_timestamp
|
||||
ON public.message_cache USING btree (timestamp);
|
||||
ON public.message_cache USING btree (timestamp DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_event_type
|
||||
ON public.message_cache USING btree (event_type);
|
||||
|
||||
-- Unique constraints for schema: public
|
||||
DO $$
|
||||
@@ -1430,10 +1466,10 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND constraint_name = 'ukey_whatsapp_accounts_phone_number'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND constraint_name = 'ukey_whatsapp_account_phone_number'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts ADD CONSTRAINT ukey_whatsapp_accounts_phone_number UNIQUE (phone_number);
|
||||
ALTER TABLE public.whatsapp_account ADD CONSTRAINT ukey_whatsapp_account_phone_number UNIQUE (phone_number);
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
@@ -1451,19 +1487,6 @@ BEGIN
|
||||
END;
|
||||
$$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'message_cache'
|
||||
AND constraint_name = 'ukey_message_cache_message_id'
|
||||
) THEN
|
||||
ALTER TABLE public.message_cache ADD CONSTRAINT ukey_message_cache_message_id UNIQUE (message_id);
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
-- Check constraints for schema: public
|
||||
-- Foreign keys for schema: public
|
||||
DO $$
|
||||
@@ -1503,11 +1526,11 @@ BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'whatsapp_accounts'
|
||||
AND constraint_name = 'fk_whatsapp_accounts_user_id'
|
||||
AND table_name = 'whatsapp_account'
|
||||
AND constraint_name = 'fk_whatsapp_account_user_id'
|
||||
) THEN
|
||||
ALTER TABLE public.whatsapp_accounts
|
||||
ADD CONSTRAINT fk_whatsapp_accounts_user_id
|
||||
ALTER TABLE public.whatsapp_account
|
||||
ADD CONSTRAINT fk_whatsapp_account_user_id
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES public.users (id)
|
||||
ON DELETE NO ACTION
|
||||
@@ -1554,4 +1577,3 @@ $$;-- Set sequence values for schema: public
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+15
-14
@@ -78,8 +78,8 @@ Table whatsapp_account {
|
||||
deleted_at timestamp [null]
|
||||
|
||||
indexes {
|
||||
(user_id) [name: 'idx_whatsapp_accounts_user_id']
|
||||
(deleted_at) [name: 'idx_whatsapp_accounts_deleted_at']
|
||||
(user_id) [name: 'idx_whatsapp_account_user_id']
|
||||
(deleted_at) [name: 'idx_whatsapp_account_deleted_at']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,26 +123,27 @@ Table session {
|
||||
}
|
||||
|
||||
Table message_cache {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
account_id varchar(36) [not null]
|
||||
message_id varchar(255) [unique, not null]
|
||||
chat_id varchar(255) [not null]
|
||||
from_me boolean [not null]
|
||||
timestamp timestamp [not null]
|
||||
message_type varchar(50) [not null, note: 'text, image, video, etc.']
|
||||
content text [not null, note: 'JSON encoded message content']
|
||||
id varchar(128) [primary key]
|
||||
account_id varchar(64) [not null, default: '']
|
||||
event_type varchar(100) [not null]
|
||||
event_data text [not null, note: 'JSON encoded event payload']
|
||||
message_id varchar(255) [not null, default: '']
|
||||
from_number varchar(64) [not null, default: '']
|
||||
to_number varchar(64) [not null, default: '']
|
||||
reason text [not null, default: '']
|
||||
attempts integer [not null, default: 0]
|
||||
timestamp timestamp [not null, default: `now()`]
|
||||
last_attempt timestamp [null]
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
|
||||
indexes {
|
||||
(account_id) [name: 'idx_message_cache_account_id']
|
||||
(chat_id) [name: 'idx_message_cache_chat_id']
|
||||
(from_me) [name: 'idx_message_cache_from_me']
|
||||
(timestamp) [name: 'idx_message_cache_timestamp']
|
||||
(event_type) [name: 'idx_message_cache_event_type']
|
||||
}
|
||||
}
|
||||
|
||||
// Reference documentation
|
||||
Ref: api_keys.user_id > users.id [delete: cascade]
|
||||
Ref: hooks.user_id > users.id [delete: cascade]
|
||||
Ref: whatsapp_accounts.user_id > users.id [delete: cascade]
|
||||
Ref: whatsapp_account.user_id > users.id [delete: cascade]
|
||||
Ref: sessions.user_id > users.id [delete: cascade]
|
||||
|
||||
@@ -62,10 +62,9 @@ CREATE INDEX IF NOT EXISTS idx_hooks_user_id ON hooks(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_hooks_deleted_at ON hooks(deleted_at);
|
||||
|
||||
-- WhatsApp Accounts table
|
||||
CREATE TABLE IF NOT EXISTS whatsapp_accounts (
|
||||
CREATE TABLE IF NOT EXISTS whatsapp_account (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
user_id VARCHAR(36) NOT NULL,
|
||||
account_id VARCHAR(100) UNIQUE,
|
||||
phone_number VARCHAR(50) NOT NULL UNIQUE,
|
||||
display_name VARCHAR(255),
|
||||
account_type VARCHAR(50) NOT NULL DEFAULT 'whatsmeow',
|
||||
@@ -80,9 +79,8 @@ CREATE TABLE IF NOT EXISTS whatsapp_accounts (
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_accounts_user_id ON whatsapp_accounts(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_accounts_deleted_at ON whatsapp_accounts(deleted_at);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_whatsapp_accounts_account_id ON whatsapp_accounts(account_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_account_user_id ON whatsapp_account(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_whatsapp_account_deleted_at ON whatsapp_account(deleted_at);
|
||||
|
||||
-- Event Logs table
|
||||
CREATE TABLE IF NOT EXISTS event_logs (
|
||||
@@ -125,18 +123,19 @@ CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON sessions(expires_at);
|
||||
|
||||
-- Message Cache table
|
||||
CREATE TABLE IF NOT EXISTS message_cache (
|
||||
id VARCHAR(36) PRIMARY KEY,
|
||||
account_id VARCHAR(36) NOT NULL,
|
||||
message_id VARCHAR(255) NOT NULL UNIQUE,
|
||||
chat_id VARCHAR(255) NOT NULL,
|
||||
message_type VARCHAR(50) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
from_me BOOLEAN NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL,
|
||||
id VARCHAR(128) PRIMARY KEY,
|
||||
account_id VARCHAR(64) NOT NULL DEFAULT '',
|
||||
event_type VARCHAR(100) NOT NULL,
|
||||
event_data TEXT NOT NULL,
|
||||
message_id VARCHAR(255) NOT NULL DEFAULT '',
|
||||
from_number VARCHAR(64) NOT NULL DEFAULT '',
|
||||
to_number VARCHAR(64) NOT NULL DEFAULT '',
|
||||
reason TEXT NOT NULL DEFAULT '',
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_attempt TIMESTAMP,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_account_id ON message_cache(account_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_chat_id ON message_cache(chat_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_from_me ON message_cache(from_me);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_timestamp ON message_cache(timestamp);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_timestamp ON message_cache(timestamp DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_cache_event_type ON message_cache(event_type);
|
||||
|
||||
Reference in New Issue
Block a user