Initial commit
This commit is contained in:
9
packages/db/schema/_table.ts
Normal file
9
packages/db/schema/_table.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { mysqlTableCreator } from "drizzle-orm/mysql-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 mySqlTable = mysqlTableCreator((name) => `t3turbo_${name}`);
|
||||
84
packages/db/schema/auth.ts
Normal file
84
packages/db/schema/auth.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import type { AdapterAccount } from "@auth/core/adapters";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import {
|
||||
index,
|
||||
int,
|
||||
primaryKey,
|
||||
text,
|
||||
timestamp,
|
||||
varchar,
|
||||
} from "drizzle-orm/mysql-core";
|
||||
|
||||
import { mySqlTable } from "./_table";
|
||||
|
||||
export const users = mySqlTable("user", {
|
||||
id: varchar("id", { length: 255 }).notNull().primaryKey(),
|
||||
name: varchar("name", { length: 255 }),
|
||||
email: varchar("email", { length: 255 }).notNull(),
|
||||
emailVerified: timestamp("emailVerified", {
|
||||
mode: "date",
|
||||
fsp: 3,
|
||||
}).default(sql`CURRENT_TIMESTAMP(3)`),
|
||||
image: varchar("image", { length: 255 }),
|
||||
});
|
||||
|
||||
export const usersRelations = relations(users, ({ many }) => ({
|
||||
accounts: many(accounts),
|
||||
}));
|
||||
|
||||
export const accounts = mySqlTable(
|
||||
"account",
|
||||
{
|
||||
userId: varchar("userId", { length: 255 }).notNull(),
|
||||
type: varchar("type", { length: 255 })
|
||||
.$type<AdapterAccount["type"]>()
|
||||
.notNull(),
|
||||
provider: varchar("provider", { length: 255 }).notNull(),
|
||||
providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
||||
refresh_token: varchar("refresh_token", { length: 255 }),
|
||||
access_token: varchar("access_token", { length: 255 }),
|
||||
expires_at: int("expires_at"),
|
||||
token_type: varchar("token_type", { length: 255 }),
|
||||
scope: varchar("scope", { length: 255 }),
|
||||
id_token: text("id_token"),
|
||||
session_state: varchar("session_state", { length: 255 }),
|
||||
},
|
||||
(account) => ({
|
||||
compoundKey: primaryKey(account.provider, account.providerAccountId),
|
||||
userIdIdx: index("userId_idx").on(account.userId),
|
||||
}),
|
||||
);
|
||||
|
||||
export const accountsRelations = relations(accounts, ({ one }) => ({
|
||||
user: one(users, { fields: [accounts.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const sessions = mySqlTable(
|
||||
"session",
|
||||
{
|
||||
sessionToken: varchar("sessionToken", { length: 255 })
|
||||
.notNull()
|
||||
.primaryKey(),
|
||||
userId: varchar("userId", { length: 255 }).notNull(),
|
||||
expires: timestamp("expires", { mode: "date" }).notNull(),
|
||||
},
|
||||
(session) => ({
|
||||
userIdIdx: index("userId_idx").on(session.userId),
|
||||
}),
|
||||
);
|
||||
|
||||
export const sessionsRelations = relations(sessions, ({ one }) => ({
|
||||
user: one(users, { fields: [sessions.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const verificationTokens = mySqlTable(
|
||||
"verificationToken",
|
||||
{
|
||||
identifier: varchar("identifier", { length: 255 }).notNull(),
|
||||
token: varchar("token", { length: 255 }).notNull(),
|
||||
expires: timestamp("expires", { mode: "date" }).notNull(),
|
||||
},
|
||||
(vt) => ({
|
||||
compoundKey: primaryKey(vt.identifier, vt.token),
|
||||
}),
|
||||
);
|
||||
14
packages/db/schema/post.ts
Normal file
14
packages/db/schema/post.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { serial, timestamp, varchar } from "drizzle-orm/mysql-core";
|
||||
|
||||
import { mySqlTable } from "./_table";
|
||||
|
||||
export const post = mySqlTable("post", {
|
||||
id: serial("id").primaryKey(),
|
||||
title: varchar("name", { length: 256 }).notNull(),
|
||||
content: varchar("content", { length: 256 }).notNull(),
|
||||
createdAt: timestamp("created_at")
|
||||
.default(sql`CURRENT_TIMESTAMP`)
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updatedAt").onUpdateNow(),
|
||||
});
|
||||
Reference in New Issue
Block a user