GoKS provides a first-class database migration CLI tool (goks db) inspired by tools like Laravel and Goose. It maintains schema history, tracks applied batches, and prevents race conditions with transactional atomicity.
1. Create a New Migration
Generate a new timestamped migration file insidemigrations/:
Terminal
goks db make:migration create_users_table2. Edit Migration File
Write standard SQL definitions separated by-- +goks Upand-- +goks Downblocks:
migrations/20260914_create_users_table.sql
-- +goks Up
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- +goks Down
DROP TABLE IF EXISTS users;3. Apply Pending Migrations
Execute all unapplied migrations in a single database transaction:
Terminal
goks db migrate4. Rollback and Status
Revert the most recent migration batch or view current database version:
Terminal
goks db rollbackTerminal
goks db status