Add env variables & auth.js

This commit is contained in:
2024-07-19 09:10:46 -05:00
commit 950fa3967a
20 changed files with 5036 additions and 0 deletions

18
src/server/db/index.ts Normal file
View File

@ -0,0 +1,18 @@
import { drizzle } from "drizzle-orm/mysql2";
import { createPool, type Pool } from "mysql2/promise";
import { env } from "~/env";
import * as schema from "./schema";
/**
* Cache the database connection in development. This avoids creating a new connection on every HMR
* update.
*/
const globalForDb = globalThis as unknown as {
conn: Pool | undefined;
};
const conn = globalForDb.conn ?? createPool({ uri: env.DATABASE_URL });
if (env.NODE_ENV !== "production") globalForDb.conn = conn;
export const db = drizzle(conn, { schema, mode: "default" });

34
src/server/db/schema.ts Normal file
View File

@ -0,0 +1,34 @@
// Example model schema from the Drizzle docs
// https://orm.drizzle.team/docs/sql-schema-declaration
import { sql } from "drizzle-orm";
import {
bigint,
index,
mysqlTableCreator,
timestamp,
varchar,
} 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 createTable = mysqlTableCreator((name) => `tech_tracker_web_${name}`);
export const posts = createTable(
"post",
{
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
name: varchar("name", { length: 256 }),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updated_at").onUpdateNow(),
},
(example) => ({
nameIndex: index("name_idx").on(example.name),
})
);