add pg vector and embed
This commit is contained in:
32
docker/postgres/init/01-init.sql
Normal file
32
docker/postgres/init/01-init.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- =====================================================
|
||||
-- Claim Guard Database Initialization Script
|
||||
-- =====================================================
|
||||
|
||||
-- Create database if it doesn't exist (handled by POSTGRES_DB env var)
|
||||
-- But we can create additional databases if needed
|
||||
|
||||
-- Enable pgvector extension
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
|
||||
-- Enable other useful extensions
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
CREATE EXTENSION IF NOT EXISTS "pg_trgm";
|
||||
CREATE EXTENSION IF NOT EXISTS "btree_gin";
|
||||
CREATE EXTENSION IF NOT EXISTS "btree_gist";
|
||||
|
||||
-- Create application user if needed (optional)
|
||||
-- The main user is already created via POSTGRES_USER
|
||||
|
||||
-- Set up database permissions
|
||||
GRANT ALL PRIVILEGES ON DATABASE claim_guard TO postgres;
|
||||
|
||||
-- Create schema for application (optional, Prisma will use public by default)
|
||||
-- CREATE SCHEMA IF NOT EXISTS claim_guard;
|
||||
|
||||
-- Log successful initialization
|
||||
DO $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'Claim Guard database initialized successfully';
|
||||
RAISE NOTICE 'pgvector extension: %', (SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'vector'));
|
||||
RAISE NOTICE 'Database ready for Prisma migrations';
|
||||
END $$;
|
||||
43
docker/scripts/reset-db.bat
Normal file
43
docker/scripts/reset-db.bat
Normal file
@@ -0,0 +1,43 @@
|
||||
@echo off
|
||||
REM =====================================================
|
||||
REM Reset PostgreSQL Database (Windows)
|
||||
REM =====================================================
|
||||
|
||||
echo 🗑️ Resetting PostgreSQL database...
|
||||
|
||||
REM Stop services
|
||||
docker-compose down
|
||||
|
||||
REM Remove volumes (this will delete all data!)
|
||||
echo ⚠️ WARNING: This will delete ALL database data!
|
||||
set /p confirm=Are you sure? (y/N):
|
||||
if /i not "%confirm%"=="y" (
|
||||
echo ❌ Operation cancelled
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
docker-compose down -v
|
||||
docker volume rm claim-guard-be_postgres_data 2>nul
|
||||
docker volume rm claim-guard-be_pgadmin_data 2>nul
|
||||
|
||||
echo ✅ Database reset complete!
|
||||
echo 🐳 Starting fresh database...
|
||||
|
||||
REM Start database again
|
||||
docker-compose up -d postgres
|
||||
|
||||
echo ⏳ Waiting for PostgreSQL to be ready...
|
||||
|
||||
REM Wait for PostgreSQL to be healthy
|
||||
:wait_loop
|
||||
docker-compose exec postgres pg_isready -U postgres -d claim_guard >nul 2>&1
|
||||
if %errorlevel% neq 0 (
|
||||
echo ⏳ PostgreSQL is unavailable - sleeping
|
||||
timeout /t 2 /nobreak >nul
|
||||
goto wait_loop
|
||||
)
|
||||
|
||||
echo ✅ Fresh database is ready!
|
||||
echo 📊 Run 'npx prisma migrate deploy' to setup schema
|
||||
|
||||
pause
|
||||
29
docker/scripts/start-db.bat
Normal file
29
docker/scripts/start-db.bat
Normal file
@@ -0,0 +1,29 @@
|
||||
@echo off
|
||||
REM =====================================================
|
||||
REM Start PostgreSQL Database Only (Windows)
|
||||
REM =====================================================
|
||||
|
||||
echo 🐳 Starting PostgreSQL with pgvector...
|
||||
|
||||
REM Start only the database service
|
||||
docker-compose up -d postgres
|
||||
|
||||
echo ⏳ Waiting for PostgreSQL to be ready...
|
||||
|
||||
REM Wait for PostgreSQL to be healthy
|
||||
:wait_loop
|
||||
docker-compose exec postgres pg_isready -U postgres -d claim_guard >nul 2>&1
|
||||
if %errorlevel% neq 0 (
|
||||
echo ⏳ PostgreSQL is unavailable - sleeping
|
||||
timeout /t 2 /nobreak >nul
|
||||
goto wait_loop
|
||||
)
|
||||
|
||||
echo ✅ PostgreSQL is ready!
|
||||
echo 📊 Database URL: postgresql://postgres:postgres123@localhost:5432/claim_guard
|
||||
|
||||
REM Show logs
|
||||
echo 📋 Database logs:
|
||||
docker-compose logs postgres
|
||||
|
||||
pause
|
||||
25
docker/scripts/start-db.sh
Normal file
25
docker/scripts/start-db.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =====================================================
|
||||
# Start PostgreSQL Database Only
|
||||
# =====================================================
|
||||
|
||||
echo "🐳 Starting PostgreSQL with pgvector..."
|
||||
|
||||
# Start only the database service
|
||||
docker-compose up -d postgres
|
||||
|
||||
echo "⏳ Waiting for PostgreSQL to be ready..."
|
||||
|
||||
# Wait for PostgreSQL to be healthy
|
||||
until docker-compose exec postgres pg_isready -U postgres -d claim_guard; do
|
||||
echo "⏳ PostgreSQL is unavailable - sleeping"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "✅ PostgreSQL is ready!"
|
||||
echo "📊 Database URL: postgresql://postgres:postgres123@localhost:5432/claim_guard"
|
||||
|
||||
# Show logs
|
||||
echo "📋 Database logs:"
|
||||
docker-compose logs postgres
|
||||
Reference in New Issue
Block a user