Migrations
Keep the schema in your repo and apply it with the CLI.
Migrations are SQL files in clouzark/migrations/, named <UTC timestamp>_<name>.sql. They're applied in order, and Clouzark records which ones ran inside the database itself (clouzark_migrations.schema_migrations).
Create and apply
clouzark migration new add_orders
# write the SQL in clouzark/migrations/20261028093000_add_orders.sql
clouzark db push --dry-run # list what would run
clouzark db push # apply pending migrations
clouzark migration ls # compare local files with what's appliedcreate table orders (
id bigint generated always as identity primary key,
user_id uuid not null,
total_cents integer not null,
created_at timestamptz not null default now()
);
alter table orders enable row level security;
create policy "own orders" on orders
for select using (user_id = auth.uid());Rules
- Each migration runs in one transaction, together with its record. Don't add
BEGINorCOMMIT, and don't use statements that can't run in a transaction, such asCREATE INDEX CONCURRENTLY. - Never edit an applied migration. Clouzark stores a checksum and refuses a changed file. Add a new migration instead.
- Commit the migration files, so every environment and teammate applies the same history.
After changing the schema, regenerate your types.