Skip to content

Dev Scripts

The merq-backend/scripts/ directory contains helper scripts for local development. All scripts must be run from the merq-backend/ directory.

ScriptPurpose
scripts/migrate.shRun goose SQL migrations
scripts/seed.shRun database seeders
scripts/dev.shStart the backend server locally
scripts/test_coverage.shRun tests and generate coverage report

Wrapper around the cmd/goose binary for running SQL migrations.

Terminal window
./scripts/migrate.sh [--env=FILE] [--dir=DIR] <command> [args]
FlagDescriptionDefault
--env=FILEPath to env file.env
--dir=DIRPath to migrations directory./migrations
CommandDescription
upRun all pending migrations (default)
downRollback the last migration
down-to NRollback all migrations to version N (use 0 to reset all)
statusShow migration status
redoRollback and re-apply last migration
create NAMECreate new blank SQL migration file
versionShow current applied version
Terminal window
# Run pending migrations with default .env
./scripts/migrate.sh
# Check status
./scripts/migrate.sh status
# Use a different env file
./scripts/migrate.sh --env=.env.development up
# Rollback last migration
./scripts/migrate.sh down
# Create a new migration
./scripts/migrate.sh create add_outlet_category

Wrapper for the cmd/seederv2 binary. Seeders are idempotent — safe to run multiple times, already-run seeders are skipped.

Terminal window
./scripts/seed.sh [--env=FILE] [options]
FlagDescription
--env=FILEPath to env file (default: .env)
--listList all registered seeders and their status
--run=NAMERun a specific seeder by name (skipped if already run)
--force=NAMEForce run a specific seeder (even if already run)
Terminal window
# Run all pending seeders
./scripts/seed.sh
# Use a different env file
./scripts/seed.sh --env=.env.development
# List seeder status
./scripts/seed.sh --list
# Run a specific seeder
./scripts/seed.sh --run=001_workspace
# Force re-run a seeder
./scripts/seed.sh --force=003_permissions

Start the backend server for local development. Optionally runs migrations and seeders before starting.

Terminal window
./scripts/dev.sh [--env=FILE] [--watch] [--port=PORT] [--migrate] [--seed]
FlagDescription
--env=FILEPath to env file (default: .env)
--watchEnable hot-reload using air (requires: go install github.com/air-verse/air@latest)
--port=PORTOverride SERVER_PORT from env file
--migrateRun goose migrations before starting server
--seedRun seeders before starting server
Terminal window
# Start server with default .env
./scripts/dev.sh
# Use a specific env file
./scripts/dev.sh --env=.env.development
# Hot-reload mode
./scripts/dev.sh --watch
# Full setup: migrate + seed + start
./scripts/dev.sh --migrate --seed
# Development env + watch + custom port
./scripts/dev.sh --env=.env.development --watch --port=9090

Run the test suite and print a coverage summary. Exits with code 1 if internal/service coverage is below 80%.

Terminal window
./scripts/test_coverage.sh

No flags — reads the environment from the local Go toolchain. Always runs against internal/service (primary target) and all internal/* packages (excluding config, domain, platform).

==========================================
🧪 MERQ BACKEND TEST COVERAGE REPORT
==========================================
📦 Running tests for internal/service package...
📦 Running tests for all internal packages...
==========================================
📊 COVERAGE SUMMARY
==========================================
📁 internal/service: 82.5% ✅ (Target met!)
📁 internal/* overall: 71.3% ✅
==========================================
📋 DETAILED SERVICE COVERAGE TABLE
==========================================
| File:Line | Function | Coverage | Status |
---------------------------------------------------------------------------------------
...
✅ SUCCESS: Service coverage is 82.5% (target: 80%)

All scripts support --env=FILE to point to any env file in the merq-backend/ directory:

Terminal window
# Local default database
./scripts/dev.sh --env=.env
# Remote development database
./scripts/dev.sh --env=.env.development
# Test database
./scripts/migrate.sh --env=.env.test status

The ENV_FILE variable is also read by the Go binaries directly, so you can also set it manually:

Terminal window
ENV_FILE=.env.development go run cmd/goose/main.go -dir migrations status