aboutsummaryrefslogtreecommitdiff
path: root/packages/web/src/server/db/schema.ts
blob: 6b3965ab72f6d389fabb3cb70a45d094609e23b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { index, pgTableCreator } from "drizzle-orm/pg-core";

/**
 * This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
 * database instance for multiple projects.
 *
 * @see https://orm.drizzle.team/docs/goodies#multi-project-schema
 */
export const createTable = pgTableCreator((name) => `web_${name}`);
export const posts = createTable(
	"post",
	(columnBuilder) => ({
		id: columnBuilder.integer().primaryKey().generatedByDefaultAsIdentity(),
		name: columnBuilder.varchar({ length: 256 }),
		createdById: columnBuilder.varchar({ length: 255 }).notNull(),
		createdAt: columnBuilder
			.timestamp({ withTimezone: true })
			.$defaultFn(() => new Date())
			.notNull(),
		updatedAt: columnBuilder
			.timestamp({ withTimezone: true })
			.$onUpdate(() => new Date()),
	}),
	(t) => [
		index("created_by_idx").on(t.createdById),
		index("name_idx").on(t.name),
	],
);