Skip to Content

<resource>.table.ts

Each <resource>.table.ts file declares one table in the app’s own SQLite database, written with Drizzle, and manh.run creates it on deploy.

app/orders/ ├── orders.table.ts # the orders table ├── repository.ts # import { orders } from "./orders.table" ├── get.ts └── post.ts

What it does

One file per table, next to that resource’s handlers. On deploy manh.run reads the .table.ts files and brings the database in line: new tables are created, new columns added.

Exports

One table made with sqliteTable. Column and index builders come from app/db: sqliteTable, integer, text, real, blob, index, uniqueIndex, primaryKey, foreignKey, unique.

Example

app/orders/orders.table.ts
import { sqliteTable, integer, text, index } from "app/db"; import { customers } from "../customers/customers.table"; export const orders = sqliteTable("orders", { id: integer("id").primaryKey({ autoIncrement: true }), customerId: integer("customer_id").notNull().references(() => customers.id, { onDelete: "restrict" }), total: integer("total").notNull(), status: text("status").notNull().default("new"), note: text("note"), // nullable createdAt: integer("created_at").notNull(), }, (t) => [ index("orders_created_at_idx").on(t.createdAt), // the list's default sort index("orders_status_idx").on(t.status), // a filter column ]);

Good to know

  • Every column a list sorts by needs an index, or check warns perf.order-unindexed.
  • Changes are additive: columns and tables are never dropped or retyped for you. Renaming a column means adding a new one and copying the data.
  • A new .notNull() column without .default() is added as nullable. Give new required columns a default.
  • Foreign keys are enforced: deleting a customer who still has orders fails with FOREIGN KEY constraint failed. Pick onDelete on purpose.
  • SQLite has no boolean type: use integer 0/1.
  • At most 100 columns per table. Files don’t go in columns: use file storage, manh/blob.
  • With app/auth.ts, manh.run generates app/users/users.table.ts. See Generated files.

Next steps

  • repository.ts — write the queries and business rules on the table you just declared.
  • Database — indexes, schema changes and database limits.
Last updated