Spaces:
Runtime error
Runtime error
Download database/schema.sql from dazat-knight/nexa-server: direct link, hf CLI and curl.
- Browser
- Download file 4.38 kB
-
https://huggingface.co/spaces/dazat-knight/nexa-server/resolve/main/database/schema.sql
- Command line
-
hf download hf://spaces/dazat-knight/nexa-server/database/schema.sql
-
curl -L -o schema.sql https://huggingface.co/spaces/dazat-knight/nexa-server/resolve/main/database/schema.sql
4.38 kB
| -- ========================================== | |
| -- SCHEMA DATABASE N.E.X.A (Supabase PostgreSQL) | |
| -- Arsitektur 5 Tabel: Enterprise Vectorized Memory | |
| -- ========================================== | |
| -- 1. Table untuk Memori Kontekstual (Agar AI bisa mengingat chat sebelumnya) | |
| CREATE TABLE IF NOT EXISTS nexa_chat_memories ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| role TEXT NOT NULL, -- Berisi 'user' (Anda) atau 'nexa' | |
| content TEXT NOT NULL, | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| -- 2. Table untuk Sistem Deduplikasi Keuangan (Mencegah Pencatatan Ganda dari Tasker/Telegram) | |
| CREATE TABLE IF NOT EXISTS nexa_finance_dedup ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| composite_key TEXT NOT NULL, -- Format rahasia: "Nominal_Merchant" | |
| transaction_time TIMESTAMP WITH TIME ZONE NOT NULL, | |
| source TEXT NOT NULL, -- Jalur masuk: 'TELEGRAM_MANUAL' atau 'TASKER_LIVIN' | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| CREATE INDEX IF NOT EXISTS idx_finance_dedup_time ON nexa_finance_dedup(transaction_time); | |
| CREATE INDEX IF NOT EXISTS idx_finance_dedup_key ON nexa_finance_dedup(composite_key); | |
| -- 3. Table Profil Pengguna (Fakta Permanen tentang Tuan Faqih) | |
| CREATE TABLE IF NOT EXISTS nexa_user_profile ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| content TEXT NOT NULL, | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| -- 4. Table Identitas Inti AI (Pengetahuan tentang N.E.X.A) | |
| CREATE TABLE IF NOT EXISTS nexa_core_identity ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| content TEXT NOT NULL, | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| -- 5. Table Gudang Ide Mentah (2nd Brain, sinkron dengan Google Docs) | |
| CREATE TABLE IF NOT EXISTS nexa_2nd_brain ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| content TEXT NOT NULL, | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| -- 6. Table Vault Arsip (Metadata dokumen/foto penting yang disimpan di Google Drive) | |
| -- Menyimpan indeks + teks OCR agar bisa dicari secara natural via N.E.X.A | |
| CREATE TABLE IF NOT EXISTS nexa_vault_items ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| drive_file_id TEXT NOT NULL, | |
| drive_web_view_link TEXT, | |
| file_name TEXT, | |
| mime_type TEXT, | |
| category TEXT, | |
| telegram_file_id TEXT, | |
| source TEXT DEFAULT 'TELEGRAM', | |
| status TEXT DEFAULT 'DRAFT', -- DRAFT | CONFIRMED | SKIPPED | |
| metadata_json JSONB, | |
| ocr_text TEXT, | |
| confirmed_at TIMESTAMP WITH TIME ZONE, | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| CREATE INDEX IF NOT EXISTS idx_vault_items_created_at ON nexa_vault_items(created_at); | |
| CREATE INDEX IF NOT EXISTS idx_vault_items_drive_file_id ON nexa_vault_items(drive_file_id); | |
| -- NOTE (Jika tabel sudah terlanjur dibuat tanpa kolom di atas, jalankan ALTER berikut di Supabase SQL Editor): | |
| -- ALTER TABLE public.nexa_vault_items | |
| -- ADD COLUMN IF NOT EXISTS status TEXT DEFAULT 'DRAFT', | |
| -- ADD COLUMN IF NOT EXISTS metadata_json JSONB, | |
| -- ADD COLUMN IF NOT EXISTS confirmed_at TIMESTAMP WITH TIME ZONE; | |
| -- ========================================== | |
| -- [PHASE 6 — Pilar 8.2] BEHAVIORAL PATTERN ENGINE | |
| -- ========================================== | |
| -- 7. Table Transaksi Tertunda (Digunakan saat server restart untuk recovery) | |
| CREATE TABLE IF NOT EXISTS nexa_pending_transactions ( | |
| id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
| composite_key TEXT NOT NULL UNIQUE, | |
| tx_data JSONB NOT NULL, | |
| telegram_sent BOOLEAN DEFAULT FALSE, | |
| created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() | |
| ); | |
| -- 8. Table Log Perilaku (Melacak rutinitas harian untuk insight proaktif) | |
| -- Jalankan SQL ini di Supabase SQL Editor sebelum deploy. | |
| CREATE TABLE IF NOT EXISTS nexa_behavior_log ( | |
| id BIGSERIAL PRIMARY KEY, | |
| event_type TEXT NOT NULL, -- 'WAKE_UP' | 'MOOD_DETECTED' | 'FINANCE_RECORD' | dll | |
| event_data JSONB DEFAULT '{}', -- Payload konteks spesifik per event_type | |
| day_of_week INT, -- 0=Minggu ... 6=Sabtu (waktu Jakarta) | |
| hour_of_day INT, -- 0-23 (waktu Jakarta) | |
| created_at TIMESTAMPTZ DEFAULT NOW() | |
| ); | |
| CREATE INDEX IF NOT EXISTS idx_behavior_log_type ON nexa_behavior_log(event_type); | |
| CREATE INDEX IF NOT EXISTS idx_behavior_log_created ON nexa_behavior_log(created_at); | |
| CREATE INDEX IF NOT EXISTS idx_behavior_log_day_hour ON nexa_behavior_log(day_of_week, hour_of_day); | |