Docs/Data & Authentication/Database Migrations

Database Migrations CLI

Complete database migration lifecycle management with transactional safety and batch rollbacks.

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
bash
goks db make:migration create_users_table

2. Edit Migration File

Write standard SQL definitions separated by-- +goks Upand-- +goks Downblocks:

migrations/20260914_create_users_table.sql
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
bash
goks db migrate

4. Rollback and Status

Revert the most recent migration batch or view current database version:

Terminal
bash
goks db rollback
Terminal
bash
goks db status
Powered byGoKS WASM16 topics