refactor: move into monorepo

This commit is contained in:
Max Koon
2025-11-08 13:37:55 -05:00
parent 63670ff3b0
commit 058f2bb94f
50 changed files with 1550 additions and 1523 deletions

View File

@@ -0,0 +1,10 @@
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as schema from "./schema";
export const getDb = ({ connectionString }: { connectionString: string }) => {
const pool = new Pool({ connectionString, max: 5 });
return drizzle(pool, {
schema,
});
};

View File

@@ -0,0 +1,6 @@
import * as drizzleSchema from "./schema";
export * from "./schema";
export * from "./client";
export { drizzleSchema };

View File

@@ -0,0 +1,2 @@
export * from "./public";
export * from "./private";

View File

@@ -0,0 +1,95 @@
import { relations } from "drizzle-orm";
import {
index,
pgTable,
text,
timestamp,
uniqueIndex,
} from "drizzle-orm/pg-core";
import { users } from "./public";
export const accounts = pgTable(
"account",
{
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
idToken: text("id_token"),
password: text("password"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
},
(table) => [
uniqueIndex("account_provider_account_unique").on(
table.providerId,
table.accountId,
),
index("account_user_id_idx").on(table.userId),
],
);
export const accountRelations = relations(accounts, ({ one }) => ({
user: one(users, {
fields: [accounts.userId],
references: [users.id],
}),
}));
export const sessions = pgTable(
"session",
{
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
token: text("token").notNull(),
expiresAt: timestamp("expires_at").notNull(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
},
(table) => [
uniqueIndex("session_token_unique").on(table.token),
index("session_user_id_idx").on(table.userId),
],
);
export const sessionRelations = relations(sessions, ({ one }) => ({
user: one(users, {
fields: [sessions.userId],
references: [users.id],
}),
}));
export const verifications = pgTable(
"verification",
{
id: text("id").primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
},
(table) => [index("verification_identifier_idx").on(table.identifier)],
);
export const auditLogs = pgTable("audit_log", {
id: text("id").primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
action: text("action").notNull(),
});

View File

@@ -0,0 +1,57 @@
import { pgTable, text, boolean, timestamp, uniqueIndex, decimal } from "drizzle-orm/pg-core";
export const users = pgTable(
"user",
{
id: text("id").primaryKey(),
name: text("name"),
email: text("email").notNull(),
emailVerified: boolean("email_verified").notNull().default(false),
image: text("image"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
},
(table) => [uniqueIndex("user_email_unique").on(table.email)],
);
export const transaction = pgTable("transaction", {
id: text("id").primaryKey(),
user_id: text("user_id").notNull(),
plaid_id: text("plaid_id").notNull().unique(),
account_id: text("account_id").notNull(),
name: text("name").notNull(),
amount: decimal("amount").notNull(),
datetime: timestamp("datetime"),
authorized_datetime: timestamp("authorized_datetime"),
json: text("json"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const plaidLink = pgTable("plaidLink", {
id: text("id").primaryKey(),
user_id: text("user_id").notNull(),
link: text("link").notNull(),
token: text("token").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});
export const balance = pgTable("balance", {
id: text("id").primaryKey(),
user_id: text("userId").notNull(),
plaid_id: text("plaidId").notNull().unique(),
avaliable: decimal("avaliable").notNull(),
current: decimal("current").notNull(),
name: text("name").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const plaidAccessTokens = pgTable("plaidAccessToken", {
id: text("id").primaryKey(),
name: text("name").notNull(),
logoUrl: text("logoUrl").notNull(),
userId: text("user_id").notNull(),
token: text("token").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});