Skip to content

Schema

The schema data is location in server/_/database/schema.ts.

By default, Nuxt Saas kit includes predefined tables for users, organizations, organization memberships, organization membership invitations, plans, plan feature sets and subscriptions.

Example

Let's take a look at the users table, where we store information about our users.

ts
const baseColumns = {
  id: uuid('id').primaryKey().notNull().defaultRandom(),
  createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
  updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' })
    .notNull()
    .defaultNow()
    .$onUpdateFn((): SQL => sql`now()`),
}

export const UserRole = ['User', 'Admin'] as const
export const userRoleEnum = pgEnum('user_role', UserRole)
export const UserRoleEnum = createEnumObject(UserRole)

export const users = pgTable(
  'users',
  {
    ...baseColumns,
    email: varchar('email').unique(),
    firstName: varchar('first_name'),
    lastName: varchar('last_name'),
    gender: varchar('gender'),
    role: userRoleEnum('role'),
  },
)