Your First Schema
Define a User Table
Section titled “Define a User Table”Create schemas/auth/user.js:
export default table({ id: col.id(), email: col.email().unique(), username: col.username().unique(), password: col.password_hash(), is_active: col.flag(true),}).timestamps();Generate Migration
Section titled “Generate Migration”alab new create_usersThis creates a timestamped migration file in migrations/.
Preview the SQL
Section titled “Preview the SQL”alab migrate --dryCREATE TABLE auth_users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), email VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, is_active BOOLEAN NOT NULL DEFAULT true, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), updated_at TIMESTAMPTZ NOT NULL DEFAULT now());Apply Migration
Section titled “Apply Migration”alab migrateExport Types
Section titled “Export Types”Generate TypeScript types for your application:
alab export -f typescriptexport interface User { id: string; email: string; username: string; is_active: boolean; created_at: Date; updated_at: Date;}Note: The password field is automatically excluded from type exports because col.password_hash() is marked as hidden. This prevents sensitive credentials from appearing in client-side code or API documentation.