Skip to content

Commit

Permalink
upgrade drizzle version
Browse files Browse the repository at this point in the history
  • Loading branch information
djsisson committed Nov 2, 2024
1 parent 9a7493c commit c24d822
Show file tree
Hide file tree
Showing 28 changed files with 3,266 additions and 4,271 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# misc
.DS_Store
*.pem

.cache_ggshield
# debug
npm-debug.log*
yarn-debug.log*
Expand Down
24 changes: 18 additions & 6 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ import { loadEnvConfig } from "@next/env";

loadEnvConfig(process.cwd(), true);

const base = "./src/db/";

export default defineConfig({
schema: [
"./src/db/asteroidz/schema.ts",
"./src/db/genshin/schema.ts",
"./src/db/todos/schema.ts",
"./src/db/tilez/schema.ts",
"./src/db/forum/schema.ts",
`${base}asteroidz/schema.ts`,
`${base}genshin/schema.ts`,
`${base}todos/schema.ts`,
`${base}tilez/schema.ts`,
`${base}forum/schema.ts`,
],
out: "./src/db/migrations",
out: `${base}migrations`,
dialect: "postgresql",
schemaFilter: "public",
casing: "snake_case",
migrations: {
prefix: "timestamp"
},
entities:{
roles: {
provider: "supabase",
exclude: ["supabase_Auth_admin"]
}
},
verbose: true,
strict: true,
dbCredentials: {
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@next/mdx": "15.0.0-rc.1",
"@next/mdx": "^15.0.0",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
Expand All @@ -25,16 +25,14 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@types/mdx": "^2.0.13",
"babel-plugin-react-compiler": "0.0.0-experimental-696af53-20240625",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.33.0",
"drizzle-orm": "^0.36.0",
"jose": "^5.6.3",
"lucide-react": "^0.427.0",
"next": "15.0.0-rc.1",
"next": "^15.0.0",
"next-themes": "^0.3.0",
"postgres": "^3.4.4",
"postgres": "^3.4.5",
"react": "19.0.0-rc-cd22717c-20241013",
"react-dom": "19.0.0-rc-cd22717c-20241013",
"server-only": "^0.0.1",
Expand All @@ -44,16 +42,19 @@
"devDependencies": {
"@faker-js/faker": "^9.0.0",
"@tailwindcss/postcss": "^4.0.0-alpha.17",
"@types/mdx": "^2.0.13",
"@types/node": "^20",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"drizzle-kit": "^0.24.1",
"babel-plugin-react-compiler": "19.0.0-beta-8a03594-20241020",
"drizzle-kit": "^0.27.0",
"eslint": "^9.12.0",
"eslint-config-next": "15.0.0-rc.1",
"eslint-config-next": "^15.0.0",
"eslint-plugin-react-compiler": "19.0.0-beta-8a03594-20241020",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^4.0.0-alpha.17",
"tsx": "^4.16.2",
"tsx": "^4.19.2",
"typescript": "^5.5.3"
},
"packageManager": "[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export default function RootLayout({
return (
<html lang="en" suppressHydrationWarning>
<body className={`${inter.variable} font-sans`}>
{/*<Script
{<Script
strategy="afterInteractive"
src="./data.js"
data-cf-beacon='{"token": "d7471a6eb8864867b7e120a5d7046876"}'
></Script>*/}
data-cf-beacon={`'{"token": "${process.env.NEXT_PUBLIC_ANALYTICS}"}'`}
></Script>}
<ThemeProvider enableSystem={true} attribute="class">
{children}
</ThemeProvider>
Expand Down
15 changes: 10 additions & 5 deletions src/app/redirect/[[...redirect]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { NextResponse } from "next/server";
import { exchangeCodeForSession } from "@/lib/auth";
// The client you created from the Server-Side Auth instructions

export async function GET(request: Request, props: { params: Promise<{ redirect?: string[] }> }) {
export async function GET(
request: Request,
props: { params: Promise<{ redirect?: string[] }> },
) {
const params = await props.params;
const { searchParams, origin } = new URL(request.url);
const { searchParams, hostname, protocol } = new URL(request.url);
const code = searchParams.get("code");

const redirectUrl = `/${params.redirect?.join("/") ?? ""}`;
Expand All @@ -16,14 +19,16 @@ export async function GET(request: Request, props: { params: Promise<{ redirect?
const isLocalEnv = process.env.NODE_ENV === "development";
if (isLocalEnv) {
// we can be sure that there is no load balancer in between, so no need to watch for X-Forwarded-Host
return NextResponse.redirect(`${origin}${redirectUrl}`);
return NextResponse.redirect(`${protocol}//${hostname}${redirectUrl}`);
} else if (forwardedHost) {
return NextResponse.redirect(`https://${forwardedHost}${redirectUrl}`);
} else {
return NextResponse.redirect(`${origin}${redirectUrl}`);
return NextResponse.redirect(`${protocol}//${hostname}${redirectUrl}`);
}
}
}
// return the user to an error page with instructions
return NextResponse.redirect(`${origin}${redirectUrl}?error=invalid_code`);
return NextResponse.redirect(
`${protocol}//${hostname}${redirectUrl}?error=invalid_code`,
);
}
31 changes: 17 additions & 14 deletions src/app/tilez/lib/GameLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { all_words } from "../data/all_words";
import { words } from "../data/words";
import { filter } from "../data/filter";
import { GameState, GameRow, GameTile } from "./GameTypes";
import { getdb as db } from "@/db/tilez/db";
import { dbClient } from "@/db/tilez/db";
import { tilez_games, tilez_words } from "@/db/tilez/schema";
import { avg, count, eq } from "drizzle-orm";
import { revalidatePath } from "next/cache";
Expand Down Expand Up @@ -49,14 +49,17 @@ export async function NewGame(): Promise<GameState> {
do {
rows = words.map(
(x) =>
(({
({
position: Math.floor(Math.random() * x.length) - 1,

tiles: x.map((y) => (({
letter: y,
found: false
}) as GameTile))
}) as GameRow),
tiles: x.map(
(y) =>
({
letter: y,
found: false,
}) as GameTile,
),
}) as GameRow,
);
} while (
all_words.includes(rows.map((x) => x.tiles[x.position + 1].letter).join(""))
Expand Down Expand Up @@ -107,7 +110,7 @@ export async function uploadScore(game: GameState): Promise<boolean> {
if (!jwt) {
return false;
}
const result = await db(jwt as JWTPayload).transaction(async (tx) => {
const result = await dbClient(jwt as JWTPayload).rls(async (tx) => {
const newGame = await tx
.insert(tilez_games)
.values({
Expand All @@ -129,7 +132,7 @@ export async function uploadScore(game: GameState): Promise<boolean> {
async function getScore() {
const jwt = await getUser();
if (!jwt) return { games: 0, average: 0 };
const result = await db(jwt as JWTPayload).transaction(async (tx) => {
const result = await dbClient(jwt as JWTPayload).rls(async (tx) => {
const scores = await tx
.select({
games: count(),
Expand All @@ -142,8 +145,8 @@ async function getScore() {
}

export async function getWordDefinition(word: string): Promise<string> {
const inDb = await db()
.select()
const inDb = await dbClient()
.db.select()
.from(tilez_words)
.where(eq(tilez_words.word, word))
.limit(1);
Expand All @@ -167,12 +170,12 @@ export async function getWordDefinition(word: string): Promise<string> {
} catch (error) {
} finally {
if (inDb.length > 0) {
await db()
.update(tilez_words)
await dbClient()
.db.update(tilez_words)
.set({ last_checked: new Date().toISOString(), definition: definition })
.where(eq(tilez_words.word, word));
} else {
await db().insert(tilez_words).values({
await dbClient().db.insert(tilez_words).values({
word: word,
definition: definition,
last_checked: new Date().toISOString(),
Expand Down
12 changes: 5 additions & 7 deletions src/app/todos/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use server";
import { getdb as db } from "@/db/todos/db";
import { dbClient } from "@/db/todos/db";
import { getUser } from "@/lib/auth-client";
import { JWTPayload } from "jose";
import { todos } from "@/db/todos/schema";
Expand All @@ -12,7 +12,7 @@ export async function addTodo(FormData: FormData) {
if (!jwt) {
return null;
}
const result = await db(jwt as JWTPayload).transaction(async (tx) => {
const result = await dbClient(jwt as JWTPayload).rls(async (tx) => {
const todoList = await tx
.insert(todos)
.values({ title: todo, userId: jwt.sub as string })
Expand All @@ -28,8 +28,7 @@ export async function toggleTodo(id: string) {
if (!jwt) {
return null;
}

const result = await db(jwt as JWTPayload).transaction(async (tx) => {
const result = await dbClient(jwt as JWTPayload).rls(async (tx) => {
const todoList = await tx
.update(todos)
.set({ completed: not(todos.completed) })
Expand All @@ -45,8 +44,7 @@ export async function deleteTodo(id: string) {
if (!jwt) {
return null;
}

const result = await db(jwt as JWTPayload).transaction(async (tx) => {
const result = await dbClient(jwt as JWTPayload).rls(async (tx) => {
await tx.delete(todos).where(eq(todos.id, id)).execute();
});

Expand All @@ -58,7 +56,7 @@ export async function listTodos() {
if (!jwt) {
return [] as (typeof todos.$inferSelect)[];
}
const result = await db(jwt as JWTPayload).transaction(async (tx) => {
const result = await dbClient(jwt as JWTPayload).rls(async (tx) => {
const todoList = await tx
.select()
.from(todos)
Expand Down
7 changes: 5 additions & 2 deletions src/components/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ export default async function Auth({ app }: { app: string }) {
{user ? (
<div className="h-10 w-10 cursor-pointer">
<DropdownMenu>
<DropdownMenuTrigger className="focus:outline-0">
<DropdownMenuTrigger className="focus:outline-0" name="user">
<Avatar className="cursor-pointer">
<AvatarImage src={user?.user_metadata?.avatar_url as string} />
<AvatarImage
src={user?.user_metadata?.avatar_url as string}
alt="icon"
/>
<AvatarFallback>
{getInitials((user?.user_metadata?.name as string) || "U")}
</AvatarFallback>
Expand Down
Loading

0 comments on commit c24d822

Please sign in to comment.