Commit Graph

18 Commits

Author SHA1 Message Date
Alphaeus Mote bb5d1f0f5d Fix CSV import to use absolute paths and proper error checking
CSV IMPORT FIXES:

- Convert CSV file paths to absolute paths before import

- PostgreSQL \COPY command requires absolute paths for reliability

- Fixed exit code checking (was checking subshell, not psql)

- Capture exit code immediately after psql command

- Show absolute path in error messages for debugging

PROBLEM SOLVED:

- CSV files were being created successfully

- Import was failing silently due to relative path issues

- 0 rows imported because \COPY couldn't find files

- Now converts relative paths to absolute before import

TESTING:

- Tested on Linux server where CSV files exist in data/csv/

- Import should now work correctly with proper row counts

Also includes Windows Python installation improvements from previous commit
2025-10-24 12:57:35 -04:00
Alphaeus Mote a7e2fea1ba Add Python installation detection and Windows-specific instructions
DEPLOY SCRIPT IMPROVEMENTS:

- Added explicit Python availability check before CSV generation

- Supports both python3 and python commands (Windows uses 'python')

- Clear error message if Python is not installed

- Windows-specific installation instructions with Microsoft Store option

- Linux/macOS instructions to run dependency installer

- Prevents silent failures when Python is missing

DEPENDENCY INSTALLER ENHANCEMENTS:

- Enhanced Windows section with detailed installation steps

- Added Microsoft Store option (easiest for Windows users)

- Added official Python installer option with PATH checkbox reminder

- Clear verification command: python --version

- Instructions to close/reopen PowerShell after installation

PROBLEM SOLVED:

- CSV import was showing 0 rows because Python script never ran

- Python not installed on Windows by default

- Script failed silently without clear error message

- Users now get clear instructions on how to install Python

NEXT STEPS FOR USERS:

1. Install Python 3 from Microsoft Store or python.org

2. Close and reopen PowerShell

3. Run ./deploy.sh again

4. CSV generation will work and data will persist
2025-10-24 12:55:28 -04:00
Alphaeus Mote 23b7afb33e Complete CSV-based data generation and bulk import system
CSV GENERATION SCRIPT (COMPLETE):

- Completed scripts/generate_csv_data.py

- Generates 100K customers, 150K accounts, 50K merchants

- Generates 200K cards, 75K devices

- Generates 5M transactions with 7% fraud rate

- Generates alerts, fraud cases, customer segments, CLV data

- All data has proper relationships and realistic values

- Generates in 2-5 minutes (vs 15-30 minutes with bash)

CSV BULK IMPORT SCRIPT (NEW):

- Created scripts/import_csv_data.sh

- Uses PostgreSQL COPY command for fast bulk loading

- 10-100x faster than INSERT statements

- Imports in correct order respecting foreign keys

- Clears existing data before import (idempotent)

- Shows import statistics and duration

- Verifies data integrity after import

- Checks for orphaned records

DEPLOY SCRIPT INTEGRATION:

- Updated deploy.sh to use CSV-based approach

- Step 7: Generate CSV files with Python

- Step 7: Import CSV files with bulk COPY

- Reduced time estimate from 15-30 min to 2-5 min

- Added error checking for both generation and import

- Exits on failure with clear error messages

BENEFITS:

-  Data persists correctly (no more 0 rows after generation)

-  5-10x faster than bash-based generation

-  Uses PostgreSQL best practices (COPY command)

-  Atomic operations - all or nothing

-  Easy to debug - can inspect CSV files

-  Idempotent - safe to run multiple times

-  Scalable - can generate millions of rows quickly

FILES CHANGED:

- scripts/generate_csv_data.py (completed)

- scripts/import_csv_data.sh (new)

- deploy.sh (updated to use CSV approach)

FIXES:

- Solves the data persistence issue (0 rows after generation)

- Transaction commit problems eliminated

- Much more reliable and production-ready
2025-10-24 12:46:31 -04:00
Alphaeus Mote e2090cc6ad Add Python dependency and start CSV-based data generation
DEPENDENCY INSTALLER UPDATES:

- Added Python 3 installation check and installer

- Python is required for fast CSV data generation

- Updated step numbers from [1/4] to [1/5]

- Python installed before PostgreSQL client

- Supports Ubuntu, Debian, CentOS, RHEL, Fedora, Arch, macOS

DEPLOY SCRIPT UPDATES:

- Added automatic dependency checking (Step 3/8)

- Checks for python3, psql, and docker

- Automatically runs install-dependencies.sh if missing

- Updated all step numbers to reflect 8 total steps

- Step 3: Check dependencies (NEW)

- Step 4: Fix permissions (was Step 3)

- Step 5: Start containers (was Step 4)

- Step 6: Initialize schema (was Step 5)

- Step 7: Generate data (was Step 6)

- Step 8: Verify deployment (was Step 7)

CSV DATA GENERATION (IN PROGRESS):

- Created scripts/generate_csv_data.py

- Python-based CSV generator for bulk import

- Much faster than SQL INSERT statements

- Generates realistic data with proper relationships

- Partial implementation (customers, accounts, merchants, cards)

- Next: Complete transactions and analytics data

RATIONALE:

- Current bash-based data generation has transaction commit issues

- Data shows as generated but doesn't persist (0 rows after completion)

- CSV + COPY command is PostgreSQL best practice for bulk loading

- 10-100x faster than INSERT statements

- More reliable - atomic COPY operations

- Easier to debug - can inspect CSV files
2025-10-24 12:43:39 -04:00
Alphaeus Mote 77d5600ce0 Fix customer_segments query column names in verification
CUSTOMER SEGMENTS QUERY FIX:

- Fixed column names in verification query [5/5]

- Changed from segment_code to segment_name

- Changed from description to segment_description

- Matches actual table schema in 01-create-tables.sql

TABLE SCHEMA:

CREATE TABLE customer_segments (

    segment_id SERIAL PRIMARY KEY,

    segment_name VARCHAR(100) NOT NULL UNIQUE,

    segment_description TEXT,

    ...

);

IMPACT:

- All 5 verification queries now work correctly

- No more column does not exist errors

- Setup script completes successfully
2025-10-24 12:28:00 -04:00
Alphaeus Mote 730553bffd Fix merchant categories duplicate key and fraud_types query column names
MERCHANT CATEGORIES FIX:

- Fixed duplicate category_code '7995' (Gambling vs Online Gambling)

- Changed Online Gambling code from '7995' to '7996'

- Fixed duplicate 'Direct Marketing' names to be unique

- Changed to 'Direct Marketing Inbound' and 'Direct Marketing Outbound'

- This was causing UNIQUE constraint violation preventing merchant_categories from loading

FRAUD TYPES QUERY FIX:

- Fixed column names in verification query

- Changed from fraud_type_code to fraud_code

- Changed from fraud_type_name to fraud_name

- Matches actual table schema in 01-create-tables.sql

IMPACT:

- Merchant categories will now load correctly (33 categories)

- Fraud types verification query will work without errors

- Setup script will complete all 5 verification queries successfully
2025-10-24 12:25:43 -04:00
Alphaeus Mote 75fa7e0159 Fix container startup timing and pgAdmin health check issues
DEPLOY SCRIPT IMPROVEMENTS:

- Start PostgreSQL first with --no-deps flag

- Wait for PostgreSQL to be healthy (increased to 120 seconds)

- Start pgAdmin separately after PostgreSQL is ready

- Added note that pgAdmin takes 30-60 seconds to initialize

- pgAdmin startup no longer blocks database operations

DOCKER COMPOSE FIX:

- Removed health check condition from pgAdmin depends_on

- Changed from 'condition: service_healthy' to simple dependency

- pgAdmin can start independently without waiting for PostgreSQL health

- Prevents 'Container is unhealthy' errors during startup

TROUBLESHOOTING SECTION:

- Added troubleshooting tips to deploy.sh output

- Command to check pgAdmin status: docker logs business_analytics_ui

- Instructions to wait for pgAdmin initialization

- Look for 'Listening at: http://[::]:80' in logs

BENEFITS:

- No more 'Container is unhealthy' errors

- Database operations can proceed while pgAdmin initializes

- Clear user expectations about pgAdmin startup time

- Better error handling and troubleshooting guidance
2025-10-24 12:22:35 -04:00
Alphaeus Mote 3e927fc5a8 Add master deployment script for one-command setup
NEW SCRIPT: deploy.sh - Master deployment automation

- Tears down existing containers and volumes

- Fixes file permissions automatically

- Starts fresh containers

- Initializes database schema

- Generates test data

- Verifies deployment

- IDEMPOTENT: Safe to run multiple times

FEATURES:

- Beautiful colored output with progress indicators

- Confirmation prompt before destructive operations

- Waits for PostgreSQL to be healthy before proceeding

- Comprehensive access information at completion

- Useful commands reference

DOCUMENTATION:

- Updated README.md with Option A (one-command) and Option B (manual)

- Updated QUICKSTART.md with super quick start section

- Manual steps now in collapsible section

USER EXPERIENCE:

- Clone repo + run deploy.sh = DONE

- No more complex multi-step setup

- Perfect for demos and quick testing

- Rebuilds from scratch every time (no stale data)
2025-10-24 12:18:06 -04:00
Alphaeus Mote dc5e9f8597 Fix pgAdmin email validation and add SQL verification queries
PGADMIN FIX:

- Changed email from admin@businessanalytics.local to admin@example.com

- pgAdmin rejects .local domains as invalid email addresses

- Updated all documentation with correct email

SETUP VERIFICATION:

- Added 5 SQL verification queries to setup-database.sh

- Query 1: Sample countries (top 5)

- Query 2: Sample merchant categories (top 5)

- Query 3: All transaction types with descriptions

- Query 4: All fraud types ordered by severity

- Query 5: All customer segments with descriptions

BENEFITS:

- Users can immediately see that data was loaded correctly

- Provides visual confirmation of schema setup

- Shows sample data structure before generating full dataset

- Helps troubleshoot setup issues early
2025-10-24 12:13:46 -04:00
Alphaeus Mote 770927459f Replace db-ui with pgAdmin 4 for better cross-platform compatibility
DOCKER COMPOSE:

- Replaced ghcr.io/n7olkachev/db-ui with dpage/pgadmin4:latest

- Added pgadmin_data volume for persistent configuration

- Configured pgAdmin with default credentials

- Port mapping: 3000:80 (pgAdmin runs on port 80 internally)

DOCUMENTATION:

- Updated README.md with pgAdmin login instructions and first-time setup

- Updated QUICKSTART.md with detailed pgAdmin configuration steps

- Added server connection details for easy setup

BENEFITS:

- pgAdmin has proper multi-platform support (linux/amd64, linux/arm64, etc.)

- Industry-standard PostgreSQL management tool

- More features: query builder, schema visualization, data import/export

- Better documentation and community support
2025-10-24 12:03:17 -04:00
Alphaeus Mote fe5c698577 Set db-ui platform to unknown/unknown for proper image compatibility 2025-10-23 20:43:02 -04:00
Alphaeus Mote e4e04f5c43 Add platform specification for db-ui to support Linux amd64
Explicitly set platform: linux/amd64 for db-ui service

Fixes: no matching manifest for linux/amd64 error

The db-ui image has limited platform support, forcing amd64 ensures compatibility on x86_64 Linux systems
2025-10-23 20:41:49 -04:00
Alphaeus Mote 7058a96519 Add comprehensive permissions management for Docker bind mounts
NEW SCRIPT: Created scripts/fix-permissions.sh - automated permission fixer

Takes ownership of repository files, makes scripts executable, sets proper permissions

Verifies permissions are correct before proceeding

DOCKER COMPOSE: Added header comments explaining permission requirements

DOCUMENTATION: Updated README.md and QUICKSTART.md with permission setup steps

WHY CRITICAL: Docker bind mounts require proper file ownership to work correctly

USER EXPERIENCE: Single command ./scripts/fix-permissions.sh handles everything
2025-10-23 16:45:19 -04:00
Alphaeus Mote bf70fba516 Fix Docker Compose version warning and improve script permissions
DOCKER COMPOSE:
- Removed obsolete 'version' attribute from docker-compose.yml
- Keeps db-ui image as ghcr.io/n7olkachev/db-ui:latest

SCRIPT PERMISSIONS:
- Updated README.md with recursive chmod command: find . -name '*.sh' -exec chmod +x {} \;
- Updated QUICKSTART.md with Step 0: Make Scripts Executable
- Removed individual chmod commands from each step
- Single command makes all .sh files executable at once

DOCUMENTATION:
- Renumbered steps in QUICKSTART.md for clarity
- Step 0: Make Scripts Executable
- Step 1: Install Dependencies (Optional)
- Step 2: Start Docker Containers
- Step 3: Initialize Database Schema
- Step 4: Generate Test Data

This resolves the Docker Compose warning and simplifies the setup process with a single chmod command.
2025-10-23 16:40:43 -04:00
Alphaeus Mote 3dde2997f6 Add automatic dependency installer and package checks
DEPENDENCY MANAGEMENT:
- Created scripts/install-dependencies.sh - automatic installer for all required packages
- Detects OS (Ubuntu, Debian, CentOS, RHEL, Fedora, Arch, macOS)
- Installs PostgreSQL client (psql) automatically
- Installs Docker & Docker Compose if missing
- Installs utility packages (curl, wget, git)

SCRIPT ENHANCEMENTS:
- Updated setup-database.sh with dependency checking
- Updated generate_data.sh with dependency checking
- Updated verify-setup.sh with dependency checking
- All scripts now prompt to run installer if dependencies are missing
- Interactive prompts guide users through installation

DOCUMENTATION:
- Updated README.md with dependency installation instructions
- Updated QUICKSTART.md with Step 0: Install Dependencies
- Added supported OS list
- Added automatic dependency check notes

USER EXPERIENCE:
- No more manual package installation required
- Scripts fail gracefully with helpful error messages
- One-command installation: ./scripts/install-dependencies.sh
- Automatic detection and installation on Linux/macOS
- Clear instructions for Windows users

This ensures users can get started immediately without hunting for package installation commands.
2025-10-23 14:34:11 -04:00
Alphaeus Mote aa803bd3bd Expand to Business Analytics: Add Customer, Sales, and KPI models
Major expansion from fraud detection to comprehensive business analytics:

DATABASE CHANGES:
- Renamed database from 'fraud_detection' to 'business_analytics'
- Renamed user from 'fraud_analyst' to 'data_analyst'
- Expanded from 20 to 39 tables across 4 business models

NEW MODELS (19 tables):
1. Customer Analytics (5 tables):
   - customer_segments, customer_lifetime_value, churn_predictions
   - customer_satisfaction, engagement_metrics

2. Sales & Revenue Analytics (6 tables):
   - product_catalog, sales_transactions, sales_targets
   - sales_performance, revenue_forecasts

3. KPI & Metrics (8 tables):
   - kpi_definitions, daily_metrics, monthly_summaries
   - trend_analysis, dashboard_snapshots
   - report_definitions, report_executions, data_quality_checks

DATA GENERATION:
- Extended generate_data.sh with 6 new steps (now 15 total)
- Added CLV calculations for all customers
- Added churn predictions based on transaction recency
- Added 30K customer satisfaction surveys
- Added 1M sales transactions linked to 24 products
- Added 90 days of daily KPI metrics
- Added 24 months of business summaries

SQL EXERCISES (3 new levels):
- Level 2: Customer Analytics (10 exercises + 3 challenges)
- Level 3: Sales & Revenue Analysis (12 exercises + 3 challenges)
- Level 4: KPI Dashboards & Metrics (12 exercises + 3 challenges)

DOCUMENTATION:
- Updated README.md with business analytics focus
- Updated QUICKSTART.md with new data generation steps
- Updated SETUP_COMPLETE.md with 39-table architecture
- Added DATA_MODELS.md with complete model specifications
- Added WHATS_NEW.md with migration guide

SEED DATA:
- Added 8 customer segments (VIP, High Value, etc.)
- Added 24 products across 5 categories
- Added 16 KPI definitions across 4 categories
- Added 8 standard report definitions

All changes maintain idempotency and backward compatibility with existing fraud detection functionality.
2025-10-23 14:17:12 -04:00
Alphaeus Mote b30733ccad Add complete financial fraud detection database with Docker, schema, data generation, and SQL exercises
- Docker setup with PostgreSQL 16 and DB-UI web interface
- Comprehensive 20+ table schema with fraud detection patterns
- Idempotent shell scripts for data generation (no Python dependency)
- Realistic geographic data (100 US cities, 210 world cities)
- 5M+ transactions with embedded fraud patterns (velocity, geographic, structuring, etc.)
- Progressive SQL exercises from beginner to advanced fraud detection
- Complete documentation and quick start guide
- Setup and verification scripts
2025-10-23 13:53:30 -04:00
freedbygrace 9d9104a4fe Initial commit 2025-10-23 12:51:02 -04:00