# Fresh Database Setup Guide ## ๐ŸŽฏ Overview This guide walks you through setting up a **completely fresh database** for the Royal Enfield Workflow Management System. **Use this when:** - First-time installation - Major schema changes require full rebuild - Moving to production environment - Resetting development database --- ## โšก Quick Start (Automated) ### Linux/Mac: ```bash cd Re_Backend chmod +x scripts/fresh-database-setup.sh ./scripts/fresh-database-setup.sh ``` ### Windows: ```cmd cd Re_Backend scripts\fresh-database-setup.bat ``` **The automated script will:** 1. โœ… Drop existing database (with confirmation) 2. โœ… Create fresh database 3. โœ… Install PostgreSQL extensions 4. โœ… Run all migrations in order 5. โœ… Seed admin configuration 6. โœ… Verify database structure --- ## ๐Ÿ“‹ Manual Setup (Step-by-Step) ### Prerequisites ```bash # Check PostgreSQL psql --version # Required: PostgreSQL 16.x # Check Redis redis-cli ping # Expected: PONG # Check Node.js node --version # Required: 18.x or higher # Configure environment cp env.example .env # Edit .env with your settings ``` --- ### Step 1: Drop Existing Database ```bash # Connect to PostgreSQL psql -U postgres # Drop database if exists DROP DATABASE IF EXISTS royal_enfield_workflow; # Exit psql \q ``` --- ### Step 2: Create Fresh Database ```bash # Create new database psql -U postgres -c "CREATE DATABASE royal_enfield_workflow OWNER postgres;" # Verify psql -U postgres -l | grep royal_enfield ``` --- ### Step 3: Install Extensions ```bash psql -U postgres -d royal_enfield_workflow <