Project import from github
This commit is contained in:
commit
0add58254d
179 changed files with 23756 additions and 0 deletions
106
shared/utils/db/schema/auth.ts
Normal file
106
shared/utils/db/schema/auth.ts
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import { v7 as uuidv7 } from "uuid";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import { boolean, index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: uuid()
|
||||
.primaryKey()
|
||||
.default(sql`uuid_v7()`)
|
||||
.$defaultFn(() => uuidv7()),
|
||||
name: text().notNull(),
|
||||
email: text().notNull().unique(),
|
||||
emailVerified: boolean().default(false).notNull(),
|
||||
image: text(),
|
||||
createdAt: timestamp().defaultNow().notNull(),
|
||||
updatedAt: timestamp()
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
export const session = pgTable(
|
||||
"session",
|
||||
{
|
||||
id: uuid()
|
||||
.primaryKey()
|
||||
.default(sql`uuid_v7()`)
|
||||
.$defaultFn(() => uuidv7()),
|
||||
expiresAt: timestamp().notNull(),
|
||||
token: text().notNull().unique(),
|
||||
createdAt: timestamp().defaultNow().notNull(),
|
||||
updatedAt: timestamp()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
ipAddress: text(),
|
||||
userAgent: text(),
|
||||
userId: uuid()
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(table) => [index("session_userId_idx").on(table.userId)]
|
||||
);
|
||||
|
||||
export const account = pgTable(
|
||||
"account",
|
||||
{
|
||||
id: uuid()
|
||||
.primaryKey()
|
||||
.default(sql`uuid_v7()`)
|
||||
.$defaultFn(() => uuidv7()),
|
||||
accountId: text().notNull(),
|
||||
providerId: text().notNull(),
|
||||
userId: uuid()
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
accessToken: text(),
|
||||
refreshToken: text(),
|
||||
idToken: text(),
|
||||
accessTokenExpiresAt: timestamp(),
|
||||
refreshTokenExpiresAt: timestamp(),
|
||||
scope: text(),
|
||||
password: text(),
|
||||
createdAt: timestamp().defaultNow().notNull(),
|
||||
updatedAt: timestamp()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
},
|
||||
(table) => [index("account_userId_idx").on(table.userId)]
|
||||
);
|
||||
|
||||
export const verification = pgTable(
|
||||
"verification",
|
||||
{
|
||||
id: uuid()
|
||||
.primaryKey()
|
||||
.default(sql`uuid_v7()`)
|
||||
.$defaultFn(() => uuidv7()),
|
||||
identifier: text().notNull(),
|
||||
value: text().notNull(),
|
||||
expiresAt: timestamp().notNull(),
|
||||
createdAt: timestamp().defaultNow().notNull(),
|
||||
updatedAt: timestamp()
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
},
|
||||
(table) => [index("verification_identifier_idx").on(table.identifier)]
|
||||
);
|
||||
|
||||
export const userRelations = relations(user, ({ many }) => ({
|
||||
sessions: many(session),
|
||||
accounts: many(account),
|
||||
}));
|
||||
|
||||
export const sessionRelations = relations(session, ({ one }) => ({
|
||||
user: one(user, {
|
||||
fields: [session.userId],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const accountRelations = relations(account, ({ one }) => ({
|
||||
user: one(user, {
|
||||
fields: [account.userId],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
2
shared/utils/db/schema/index.ts
Normal file
2
shared/utils/db/schema/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./auth";
|
||||
export * from "./memberData";
|
||||
21
shared/utils/db/schema/memberData.ts
Normal file
21
shared/utils/db/schema/memberData.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { relations } from "drizzle-orm";
|
||||
import { jsonb, pgTable, text, uuid } from "drizzle-orm/pg-core";
|
||||
|
||||
import { user } from "./auth";
|
||||
|
||||
export const memberData = pgTable("member_data", {
|
||||
id: uuid()
|
||||
.primaryKey()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
country: text(),
|
||||
info: jsonb(),
|
||||
address: jsonb(),
|
||||
billing: jsonb(),
|
||||
});
|
||||
|
||||
export const memberDataRelations = relations(memberData, ({ one }) => ({
|
||||
user: one(user, {
|
||||
fields: [memberData.id],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
Loading…
Add table
Add a link
Reference in a new issue