neolix_backend / init-db /01-schema.sql
athuldev743's picture
edit llm models
997d5eb
Raw History Blame Contribute Delete
1.71 kB
-- Auto-run by the Postgres container on first startup (docker-entrypoint-initdb.d)
-- Mirrors the schema created by ensure_table() in leads.py, so local dev has
-- the table + full-text search index ready immediately instead of waiting
-- for the first /leads/upload call.
CREATE TABLE IF NOT EXISTS leads (
id BIGSERIAL PRIMARY KEY,
email VARCHAR(255),
contact_name VARCHAR(255),
company_name VARCHAR(255),
phone VARCHAR(30),
city VARCHAR(100),
state VARCHAR(100),
country VARCHAR(100),
business_type VARCHAR(150),
business_details TEXT,
address TEXT,
website VARCHAR(255),
source VARCHAR(50) DEFAULT 'manual',
search_vector tsvector GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce(company_name, '')), 'A') ||
setweight(to_tsvector('english', coalesce(business_type, '')), 'B')
) STORED,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_leads_email_unique
ON leads (email) WHERE email IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_leads_fts
ON leads USING GIN (search_vector);
-- A couple of sample rows so /leads/search has something to return on a fresh env
INSERT INTO leads (email, contact_name, company_name, phone, city, state, business_type, source)
VALUES
('demo1@example.com', 'Demo Lead One', 'Acme AI Solutions', '919876543210', 'Kochi', 'Kerala', 'Technology', 'seed'),
('demo2@example.com', 'Demo Lead Two', 'Bright Automobiles', '919876543211', 'Bangalore', 'Karnataka', 'Automobiles', 'seed')
ON CONFLICT (email) DO NOTHING;