Instead of putting all your tables in a single file, it's best practice to organize them into separate files within a server/database/schema/ directory.
Create a directory at server/database/schema/.
Create a file server/database/schema/users.ts:
// server/database/schema/users.ts
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
export const users = sqliteTable('users', {
id: integer('id').primaryKey({ autoIncrement: true }),
name: text('name').notNull(),
email: text('email').notNull().unique(),
password: text('password').notNull(),
avatar: text('avatar').notNull(),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})
To add a new table, simply create a new file. For example, server/database/schema/posts.ts:
// server/database/schema/posts.ts
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
import { users } from './users'
export const posts = sqliteTable('posts', {
id: integer('id').primaryKey({ autoIncrement: true }),
title: text('title').notNull(),
content: text('content').notNull(),
authorId: integer('author_id').references(() => users.id),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})
You must export all your schema files in server/database/schema/index.ts so Drizzle can find them.
// server/database/schema/index.ts
export * from './users'
export * from './posts'
After defining your schemas, run the generation script to create the database migrations:
pnpm db:generate
yarn db:generate
npm run db:generate
bun db:generate
Your API endpoints (e.g., /api/users, /api/posts) will be automatically available.
statusNuxt Auto CRUD includes built-in logic for the status field to simplify content visibility.
status, the module will automatically filter list results. By default, only records with status = 'active' are returned to non-admin users.status, ensure that 'active' and 'inactive' are among its options.state, payment_status, or stage to avoid triggering this automatic filtering behavior.