- Created main application entry point in `main.go`. - Added configuration management in `config/config.go` and tests in `config/config_test.go`. - Implemented handlers for book and stationery uploads in `handlers/book.go` and `handlers/stationery.go`, including validation logic. - Established database connection and services in `services/database.go` and `services/book_service.go`. - Defined models for books and stationery in `models/book.go` and `models/stationery.go`. - Set up Firebase integration for image uploads in `services/firebase.go`. - Created migration scripts for database schema in `migrations/001_create_tables.sql` and subsequent updates. - Added CORS and error handling middleware. - Included comprehensive tests for handlers, services, and utilities. - Documented API endpoints and usage in `README.md` and migration instructions in `migrations/README.md`. - Introduced `.gitignore` to exclude unnecessary files and directories. - Added Go module support with `go.mod` and `go.sum` files. - Implemented utility functions for slug generation and validation in `utils/slug.go` and `utils/validation.go`.
42 lines
880 B
Markdown
42 lines
880 B
Markdown
# Database Migrations
|
|
|
|
## Running Migrations
|
|
|
|
### Prerequisites
|
|
1. Ensure PostgreSQL is running
|
|
2. Create the database if it doesn't exist:
|
|
```bash
|
|
psql -U postgres -c "CREATE DATABASE jd_book_uploader;"
|
|
```
|
|
3. Ensure your `.env` or `.env.local` file in the backend directory has the correct database credentials
|
|
|
|
### Run Migration
|
|
|
|
```bash
|
|
cd backend
|
|
./scripts/run_migration.sh
|
|
```
|
|
|
|
Or manually:
|
|
```bash
|
|
cd backend
|
|
export $(grep -v '^#' .env.local | grep -v '^$' | xargs)
|
|
PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f migrations/001_create_tables.sql
|
|
```
|
|
|
|
### Verify Schema
|
|
|
|
```bash
|
|
cd backend
|
|
./scripts/verify_schema.sh
|
|
```
|
|
|
|
This will show:
|
|
- Table structures for `books` and `stationery`
|
|
- All indexes created on both tables
|
|
|
|
## Migration Files
|
|
|
|
- `001_create_tables.sql` - Creates books and stationery tables with indexes
|
|
|