KAIU Natural Living uses PostgreSQL as its primary database with the pgvector extension for AI-powered semantic search (RAG - Retrieval Augmented Generation).
# Connect to PostgreSQL as superusersudo -u postgres psql
-- Create databaseCREATE DATABASE kaiu_db;-- Create user (optional, for security)CREATE USER kaiu_user WITH PASSWORD 'secure_password';-- Grant privilegesGRANT ALL PRIVILEGES ON DATABASE kaiu_db TO kaiu_user;-- Exit\q
2
Enable pgvector Extension
The pgvector extension must be enabled before running Prisma migrations.
Option 1: Using SQL
# Connect to your databasepsql -U kaiu_user -d kaiu_db
-- Enable pgvector extensionCREATE EXTENSION IF NOT EXISTS vector;-- Verify installationSELECT * FROM pg_extension WHERE extname = 'vector';
Option 2: Install pgvector manually (if not available)
# Clone pgvector repositorygit clone --branch v0.5.0 https://github.com/pgvector/pgvector.gitcd pgvector# Build and installmakesudo make install# Enable in your databasepsql -U kaiu_user -d kaiu_db -c "CREATE EXTENSION vector;"
3
Configure Environment Variable
Update your .env.local with the database connection string:
# Generate Prisma Clientnpx prisma generate# Push schema to database (creates tables)npx prisma db push
You should see output like:
Environment variables loaded from .env.localPrisma schema loaded from prisma/schema.prismaDatasource "db": PostgreSQL database "kaiu_db"🚀 Your database is now in sync with your Prisma schema.
5
Seed Initial Data
Populate the database with initial data:
npm run seed
This will create:
Admin users with different roles (ADMIN, WAREHOUSE, SUPPORT)
model User { id String @id @default(uuid()) email String @unique password String // Bcrypt hash name String? role Role @default(CUSTOMER) bsuid String? @unique // WhatsApp Business-Scoped User ID orders Order[] addresses Address[] whatsappSession WhatsAppSession?}enum Role { CUSTOMER // End customer ADMIN // Full access WAREHOUSE // Logistics and inventory SUPPORT // Chat support and knowledge base}
model Order { id String @id @default(uuid()) readableId Int @default(autoincrement()) externalId String? @unique // Venndelo or Wompi ID status OrderStatus @default(PENDING) paymentMethod PaymentMethod @default(COD) subtotal Int shippingCost Int total Int // Customer info customerName String customerEmail String customerPhone String customerId String? // ID number for logistics // Addresses (stored as JSON snapshots) shippingAddress Json billingAddress Json? // Logistics carrier String? trackingNumber String? trackingUrl String? items OrderItem[]}enum OrderStatus { PENDING CONFIRMED PROCESSING READY_TO_SHIP PICKUP_REQUESTED SHIPPED DELIVERED CANCELLED RETURNED}
Prisma schema loaded from prisma/schema.prismaDatasource "db": PostgreSQL database "kaiu_db"Introspecting based on datasource...✔ Introspected 8 models
2
Verify pgvector
psql -U kaiu_user -d kaiu_db -c "SELECT * FROM pg_extension WHERE extname = 'vector';"
If you get ERROR: extension "vector" is not available:
Check PostgreSQL version (must be 11+):
psql --version
Install pgvector manually:
git clone https://github.com/pgvector/pgvector.gitcd pgvectormakesudo make install
Restart PostgreSQL:
sudo systemctl restart postgresql
Connection Refused
If you get Connection refused errors:
# Check PostgreSQL is runningsudo systemctl status postgresql# Check PostgreSQL is listening on port 5432sudo netstat -plunt | grep 5432# Verify connection stringecho $DATABASE_URL
Update postgresql.conf to allow connections:
listen_addresses = '*'
Update pg_hba.conf to allow authentication:
host all all 0.0.0.0/0 md5
Prisma Client Out of Sync
If you get errors about Prisma Client being out of sync: