# Step-by-step: Create PostgreSQL database and user (voicebot / vmc)

Use **one** of the options below. Then run `python manage.py migrate` from the `backend` folder to create all tables.

---

## If the script says "PostgreSQL psql not found"

- **Use the correct PATH:** The PATH must point to the folder that contains **psql.exe** (the **bin** folder), for example:
  - `C:\Program Files\PostgreSQL\18\bin`
  Do **not** use the Start Menu path (`C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PostgreSQL 18`) — that folder has shortcuts only, not the real `psql.exe`. Edit your system Environment Variables and set PostgreSQL path to `C:\Program Files\PostgreSQL\18\bin` (adjust version if needed), then **close and reopen PowerShell** and run the script again.
- **Install PostgreSQL** from https://www.postgresql.org/download/windows/ (use the installer so `psql` is in a standard path), then run the script again.
- **Or use pgAdmin** (installed with PostgreSQL): connect as `postgres` → Tools → Query Tool → paste the contents of `create_db_voicebot.sql` → run (F5). Then create the database `voicebot` with owner `voicebot` if the script only created the user.
- **Or find your psql path**: look for `psql.exe` in `C:\Program Files\PostgreSQL\` (check each version folder, e.g. 18, 16, 15). Edit `create_db_voicebot.ps1` and near the top set: `$psql = "C:\Program Files\PostgreSQL\18\bin\psql.exe"` (uncomment/fix the line that sets `$psql`).

---

## Option 1 — PowerShell script (recommended on Windows)

1. Open **PowerShell**.
2. Go to the backend folder:
   ```
   cd "C:\Users\Bhavya sree\Downloads\livekit-master\backend"
   ```
   (Use your real path to `livekit-master\backend`.)
3. Run:
   ```
   .\scripts\create_db_voicebot.ps1
   ```
4. Enter the **postgres** user password when prompted (once or twice).
5. If you see "User may already exist" or "Database may already exist", that’s OK.
6. Set `backend\.env`: copy `.env.example` to `.env` and ensure it has:
   ```
   DATABASE_URL=postgresql://voicebot:vmc@localhost:5432/voicebot
   ```
7. Create tables:
   ```
   python manage.py migrate
   ```

---

## Option 2 — SQL file with psql

1. Open **PowerShell**.
2. Go to the scripts folder:
   ```
   cd "C:\Users\Bhavya sree\Downloads\livekit-master\backend\scripts"
   ```
3. Run (change `16` to your PostgreSQL version if different, e.g. 15 or 17):
   ```
   & "C:\Program Files\PostgreSQL\16\bin\psql.exe" -U postgres -f create_db_voicebot.sql
   ```
4. Enter the **postgres** password when prompted.
5. If you get "already exists", reset the password:
   ```
   & "C:\Program Files\PostgreSQL\16\bin\psql.exe" -U postgres -c "ALTER USER voicebot WITH PASSWORD 'vmc';"
   ```
6. Set `backend\.env` and run `python manage.py migrate` as in Option 1 steps 6–7.

---

## Option 3 — Two commands in PowerShell

1. Open **PowerShell**.
2. Create user (change `16` to your PostgreSQL version):
   ```
   & "C:\Program Files\PostgreSQL\16\bin\psql.exe" -U postgres -c "CREATE USER voicebot WITH PASSWORD 'vmc';"
   ```
   Enter postgres password.
3. Create database:
   ```
   & "C:\Program Files\PostgreSQL\16\bin\psql.exe" -U postgres -c "CREATE DATABASE voicebot OWNER voicebot;"
   ```
   Enter postgres password if asked.
4. Set `backend\.env` and run `python manage.py migrate` as in Option 1 steps 6–7.

---

## If psql is in your PATH

If you added PostgreSQL’s `bin` folder to PATH, you can use:

```
psql -U postgres -c "CREATE USER voicebot WITH PASSWORD 'vmc';"
psql -U postgres -c "CREATE DATABASE voicebot OWNER voicebot;"
```

Then set `.env` and run `python manage.py migrate`.
