refactor(API): ✨ Relspect integration
This commit is contained in:
11
sql/postgres/001_init_schema.down.sql
Normal file
11
sql/postgres/001_init_schema.down.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Rollback migration for initial schema
|
||||
-- This drops all tables created in 001_init_schema.up.sql
|
||||
|
||||
-- Drop tables in reverse order (to handle foreign key constraints)
|
||||
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.hooks CASCADE;
|
||||
DROP TABLE IF EXISTS public.api_keys CASCADE;
|
||||
DROP TABLE IF EXISTS public.users CASCADE;
|
||||
1556
sql/postgres/001_init_schema.up.sql
Normal file
1556
sql/postgres/001_init_schema.up.sql
Normal file
File diff suppressed because it is too large
Load Diff
147
sql/schema.dbml
Normal file
147
sql/schema.dbml
Normal file
@@ -0,0 +1,147 @@
|
||||
// WhatsHooked Database Schema
|
||||
// This file defines the database schema for WhatsHooked Phase 2
|
||||
|
||||
Table users {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
username varchar(255) [unique, not null]
|
||||
email varchar(255) [unique, not null]
|
||||
password varchar(255) [not null, note: 'Bcrypt hashed password']
|
||||
full_name varchar(255)
|
||||
role varchar(50) [not null, default: 'user', note: 'admin, user, viewer']
|
||||
active boolean [not null, default: true]
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
updated_at timestamp [not null, default: `now()`]
|
||||
deleted_at timestamp [null, note: 'Soft delete']
|
||||
|
||||
indexes {
|
||||
(deleted_at) [name: 'idx_users_deleted_at']
|
||||
}
|
||||
}
|
||||
|
||||
Table api_keys {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
user_id varchar(36) [not null, ref: > users.id]
|
||||
name varchar(255) [not null, note: 'Friendly name for the API key']
|
||||
key varchar(255) [unique, not null, note: 'Hashed API key']
|
||||
key_prefix varchar(20) [note: 'First few characters for display']
|
||||
permissions text [note: 'JSON array of permissions']
|
||||
last_used_at timestamp [null]
|
||||
expires_at timestamp [null]
|
||||
active boolean [not null, default: true]
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
updated_at timestamp [not null, default: `now()`]
|
||||
deleted_at timestamp [null]
|
||||
|
||||
indexes {
|
||||
(user_id) [name: 'idx_api_keys_user_id']
|
||||
(deleted_at) [name: 'idx_api_keys_deleted_at']
|
||||
}
|
||||
}
|
||||
|
||||
Table hooks {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
user_id varchar(36) [not null, ref: > users.id]
|
||||
name varchar(255) [not null]
|
||||
url text [not null]
|
||||
method varchar(10) [not null, default: 'POST', note: 'HTTP method']
|
||||
headers text [note: 'JSON encoded headers']
|
||||
events text [note: 'JSON array of event types']
|
||||
active boolean [not null, default: true]
|
||||
description text
|
||||
secret varchar(255) [note: 'HMAC signature secret']
|
||||
retry_count int [not null, default: 3]
|
||||
timeout int [not null, default: 30, note: 'Timeout in seconds']
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
updated_at timestamp [not null, default: `now()`]
|
||||
deleted_at timestamp [null]
|
||||
|
||||
indexes {
|
||||
(user_id) [name: 'idx_hooks_user_id']
|
||||
(deleted_at) [name: 'idx_hooks_deleted_at']
|
||||
}
|
||||
}
|
||||
|
||||
Table whatsapp_accounts {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
user_id varchar(36) [not null, ref: > users.id]
|
||||
account_type varchar(50) [not null, note: 'whatsmeow or business-api']
|
||||
phone_number varchar(50) [unique, not null]
|
||||
display_name varchar(255)
|
||||
session_path text
|
||||
status varchar(50) [not null, default: 'disconnected', note: 'connected, disconnected, pairing']
|
||||
last_connected_at timestamp [null]
|
||||
active boolean [not null, default: true]
|
||||
config text [note: 'JSON encoded additional config']
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
updated_at timestamp [not null, default: `now()`]
|
||||
deleted_at timestamp [null]
|
||||
|
||||
indexes {
|
||||
(user_id) [name: 'idx_whatsapp_accounts_user_id']
|
||||
(deleted_at) [name: 'idx_whatsapp_accounts_deleted_at']
|
||||
}
|
||||
}
|
||||
|
||||
Table event_logs {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
user_id varchar(36) [ref: > users.id, note: 'Optional user reference']
|
||||
event_type varchar(100) [not null]
|
||||
entity_type varchar(100) [note: 'user, hook, account, etc.']
|
||||
entity_id varchar(36)
|
||||
action varchar(50) [note: 'create, update, delete, read']
|
||||
data text [note: 'JSON encoded event data']
|
||||
ip_address varchar(50)
|
||||
user_agent text
|
||||
success boolean [not null, default: true]
|
||||
error text
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
|
||||
indexes {
|
||||
(user_id) [name: 'idx_event_logs_user_id']
|
||||
(event_type) [name: 'idx_event_logs_event_type']
|
||||
(entity_type) [name: 'idx_event_logs_entity_type']
|
||||
(entity_id) [name: 'idx_event_logs_entity_id']
|
||||
(created_at) [name: 'idx_event_logs_created_at']
|
||||
}
|
||||
}
|
||||
|
||||
Table sessions {
|
||||
id varchar(36) [primary key, note: 'UUID']
|
||||
user_id varchar(36) [not null, ref: > users.id]
|
||||
token varchar(255) [unique, not null, note: 'Session token hash']
|
||||
ip_address varchar(50)
|
||||
user_agent text
|
||||
expires_at timestamp [not null]
|
||||
created_at timestamp [not null, default: `now()`]
|
||||
updated_at timestamp [not null, default: `now()`]
|
||||
|
||||
indexes {
|
||||
(user_id) [name: 'idx_sessions_user_id']
|
||||
(expires_at) [name: 'idx_sessions_expires_at']
|
||||
}
|
||||
}
|
||||
|
||||
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']
|
||||
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']
|
||||
}
|
||||
}
|
||||
|
||||
// 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: sessions.user_id > users.id [delete: cascade]
|
||||
Reference in New Issue
Block a user