---
name: recreate-test-db
description: Recreate the Redmine test database from scratch (delete db/schema.rb and db/redmine.sqlite3_test, then run core and plugin migrations with RAILS_ENV=test). Use when the test DB is out of sync, migrations changed, or the user asks to rebuild/reset the test database.
---

# Recreate Test Database

Rebuild the SQLite test database of the Redmine instance at `/usr/local/redmine`.

> **IMPORTANT: Never run `rails test`.** Only run the steps below, and only when the user asks to rebuild the test DB. Never migrate the test DB on your own initiative.

## Workflow

Run from `/usr/local/redmine`.

### Step 1: Delete the generated schema

`db/schema.rb` is git-ignored and regenerated by migrations. It may be absent; that is fine.

```bash
rm -f /usr/local/redmine/db/schema.rb
```

### Step 2: Delete the test database

```bash
rm -f /usr/local/redmine/db/redmine.sqlite3_test
```

Do NOT touch `db/redmine.sqlite3` (the development DB).

### Step 3: Run core migrations

```bash
cd /usr/local/redmine && bundle exec rake db:migrate RAILS_ENV=test 2>&1 | tail -30
```

### Step 4: Run plugin migrations

Core `db:migrate` does not run plugin migrations.

```bash
cd /usr/local/redmine && bundle exec rake redmine:plugins:migrate RAILS_ENV=test 2>&1 | tail -30
```

### Step 5: Report

State whether both migrations finished without errors and name the last migration applied in each. Do not run tests unless asked.
