Taskfile Commands Guide
This guide provides documentation for the Taskfile commands available in the Gojang framework. Task is a cross-platform task runner and build tool that replaces Make.
Prerequisites
Install Task (if not already installed):
macOS/Linux:
go install github.com/go-task/task/v3/cmd/task@latest
Or using Homebrew:
brew install go-task
Windows:
go install github.com/go-task/task/v3/cmd/task@latest
Or using Chocolatey:
choco install go-task
Available Commands
Run task --list to see all available tasks.
Database Migration Commands
task migrate
Applies all pending database migrations.
Usage:
task migrate
Output:
✅ All migrations applied successfully- All pending migrations were applied✅ No pending migrations- Database is already up to date
Example:
$ task migrate
task: [migrate] go run ./app/cmd/migrate/main.go up
✅ All migrations applied successfully
task migrate-down
Rolls back the last applied migration.
Usage:
task migrate-down
Output:
✅ Last migration rolled back successfully- Migration was rolled back⚠️ No migrations to rollback- No migrations to rollback⚠️ No migrations to rollback (database is empty)- Database has no migration history
Example:
$ task migrate-down
task: [migrate-down] go run ./app/cmd/migrate/main.go down
✅ Last migration rolled back successfully
Warning: Use with caution in production environments. This will drop tables and lose data.
task migrate-create
Creates a new migration file pair (up and down).
Usage:
task migrate-create name=<migration_name>
Parameters:
name- Name for the migration (e.g.,add_products_table,add_user_status_field)
Output:
Creates two files in app/gojang/models/migrations/:
NNNNNN_<name>.up.sql- Migration to apply changesNNNNNN_<name>.down.sql- Migration to rollback changes
Example:
$ task migrate-create name=add_products_table
task: [migrate-create] migrate create -ext sql -dir app/gojang/models/migrations -seq add_products_table
/home/runner/work/gojang-dev/gojang-dev/app/gojang/models/migrations/000002_add_products_table.up.sql
/home/runner/work/gojang-dev/gojang-dev/app/gojang/models/migrations/000002_add_products_table.down.sql
Next Steps:
- Edit the
.up.sqlfile to add your schema changes - Edit the
.down.sqlfile to add the rollback logic - Run
task migrateto apply the new migration
Example Migration Files:
000002_add_products_table.up.sql:
CREATE TABLE IF NOT EXISTS products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
price REAL NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_products_name ON products(name);
000002_add_products_table.down.sql:
DROP TABLE IF EXISTS products;
Other Development Commands
task dev
Run server with live reload (requires Air).
task dev
task build
Build the web binary.
task build
task test
Run tests.
task test
task seed
Seed database with initial admin login.
task seed
task schema-gen
Generate Ent code after schema changes.
task schema-gen
task clean
Clean build artifacts and generated files.
task clean
task run
Build and run the server.
task run
Migration Workflow
1. Creating a New Migration
When you need to add or modify database schema:
# Create migration files
task migrate-create name=add_email_verification
# Edit the generated files
# - app/gojang/models/migrations/NNNNNN_add_email_verification.up.sql
# - app/gojang/models/migrations/NNNNNN_add_email_verification.down.sql
# Apply the migration
task migrate
2. Rolling Back a Migration
If something goes wrong or you need to undo changes:
# Rollback the last migration
task migrate-down
# Fix the migration files if needed
# Then reapply
task migrate
3. Development to Production
Development:
- Use
task migrateto apply migrations - Test thoroughly
- Commit migration files to version control
Production:
- Pull latest code with migration files
- Run
task migrateto apply new migrations - Backup database before running migrations!
Tips and Best Practices
Migration Best Practices
Always create both up and down migrations - This allows you to rollback if needed
Use IF EXISTS / IF NOT EXISTS - Makes migrations idempotent and safer to rerun
Test migrations locally first - Always test on a development database before production
Backup before migrating - Especially in production environments
# SQLite backup
sqlite3 app.db ".backup backup.db"
# PostgreSQL backup
pg_dump -U gojang gojang > backup.sqlNever modify existing migrations - Once a migration is applied, create a new one to make changes
Use sequential naming - The
migrate-createcommand automatically creates sequential numbersKeep migrations small and focused - One logical change per migration
Troubleshooting
Problem: migrate command not found when running task migrate-create
Solution: Install golang-migrate CLI:
go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
Problem: Migration fails with "dirty database"
Solution: This happens when a migration partially fails. You can force the version:
# Check current version
migrate -path app/gojang/models/migrations -database "sqlite://app.db" version
# Force to a specific version (use with caution!)
migrate -path app/gojang/models/migrations -database "sqlite://app.db" force VERSION
Problem: Need to see migration status
Solution: You can use the migrate CLI directly:
migrate -path app/gojang/models/migrations -database "sqlite://app.db" version
Related Documentation
For more information about Task, visit taskfile.dev.