Skip to content

Your First Schema

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();
Terminal window
alab new create_users

This creates a timestamped migration file in migrations/.

Terminal window
alab migrate --dry
CREATE 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()
);
Terminal window
alab migrate

Generate TypeScript types for your application:

Terminal window
alab export -f typescript
types/auth/user.ts
export 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.