diff --git a/backend/.env.example b/backend/.env.example index 7467bfa..46a1a05 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -17,7 +17,8 @@ REWARD_TOKEN_ID= PRIVATE_KEY= # Location of the Database. See prisma/schema.prisma -DATABASE_URL="file:./dev.db" +TURSO_DATABASE_URL= +TURSO_AUTH_TOKEN= # CORS allowed origins, comma delimited ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001,https://wordle-staging.vercel.app,https://wordle.openformat.tech \ No newline at end of file diff --git a/backend/fly.toml b/backend/fly.toml index be17589..e4820ec 100644 --- a/backend/fly.toml +++ b/backend/fly.toml @@ -20,7 +20,3 @@ primary_region = 'lhr' memory = '1gb' cpu_kind = 'shared' cpus = 1 - -[[mounts]] - source = 'data' - destination = '/data' diff --git a/backend/package.json b/backend/package.json index 2381e7c..fa40572 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,7 +5,9 @@ "start": "bun run src/index.ts" }, "dependencies": { + "@libsql/client": "^0.9.0", "@openformat/sdk": "^1.4.0", + "@prisma/adapter-libsql": "^5.18.0", "@prisma/client": "^5.7.1", "@privy-io/server-auth": "^1.9.6", "@types/validator": "^13.11.7", diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 1c3c02e..f1a3fa3 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -1,11 +1,11 @@ generator client { - provider = "prisma-client-js" - binaryTargets = ["native", "linux-musl-arm64-openssl-3.0.x", "linux-musl-openssl-3.0.x"] + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] } datasource db { provider = "sqlite" - url = env("DATABASE_URL") + url = "file:./dev.db" } model User { diff --git a/backend/src/middlewares/privyAuth.ts b/backend/src/middlewares/privyAuth.ts index 13488aa..e8e9051 100644 --- a/backend/src/middlewares/privyAuth.ts +++ b/backend/src/middlewares/privyAuth.ts @@ -1,14 +1,12 @@ -import { PrismaClient } from "@prisma/client"; import { PrivyClient, User } from "@privy-io/server-auth"; import { Context, Next } from "hono"; +import { prisma } from "../services/db"; const privy = new PrivyClient( process.env.PRIVY_APP_ID!, process.env.PRIVY_APP_SECRET! ); -const prisma = new PrismaClient(); - export const privyAuthMiddleware = async (c: Context, next: Next) => { const authToken = c.req .header("Authorization") diff --git a/backend/src/routes/api/v1/leaderboard.ts b/backend/src/routes/api/v1/leaderboard.ts index 13cae6d..0eacc9e 100644 --- a/backend/src/routes/api/v1/leaderboard.ts +++ b/backend/src/routes/api/v1/leaderboard.ts @@ -1,8 +1,8 @@ -import { PrismaClient } from "@prisma/client"; import dayjs from "dayjs"; import { Hono } from "hono"; import { leaderboardData } from "../../../queries/leaderboard"; import { sdk } from "../../../services/SDK"; +import { prisma } from "../../../services/db"; import { convertToTimestamps, generateLeaderboard, @@ -14,7 +14,6 @@ enum Status { } const leaderboard = new Hono(); -const prisma = new PrismaClient(); leaderboard.onError((err, c) => { console.error(`${err}`); diff --git a/backend/src/routes/api/v1/profile.ts b/backend/src/routes/api/v1/profile.ts index 334783b..cb7daa1 100644 --- a/backend/src/routes/api/v1/profile.ts +++ b/backend/src/routes/api/v1/profile.ts @@ -1,6 +1,6 @@ -import { PrismaClient } from "@prisma/client"; import { User } from "@privy-io/server-auth"; import { Hono } from "hono"; +import { prisma } from "../../../services/db"; import { getOnChainProfile } from "../../../utils/profile"; enum Status { @@ -9,7 +9,6 @@ enum Status { } const profile = new Hono<{ Variables: { user: User } }>(); -const prisma = new PrismaClient(); profile.onError((err, c) => { console.error(`${err}`); diff --git a/backend/src/services/db.ts b/backend/src/services/db.ts new file mode 100644 index 0000000..ec5546b --- /dev/null +++ b/backend/src/services/db.ts @@ -0,0 +1,11 @@ +import { createClient } from "@libsql/client"; +import { PrismaLibSQL } from "@prisma/adapter-libsql"; +import { PrismaClient } from "@prisma/client"; + +const libsql = createClient({ + url: process.env.TURSO_DATABASE_URL!, + authToken: process.env.TURSO_AUTH_TOKEN, +}); + +const adapter = new PrismaLibSQL(libsql); +export const prisma = new PrismaClient({ adapter }); diff --git a/bun.lockb b/bun.lockb index 9638e48..90202c4 100755 Binary files a/bun.lockb and b/bun.lockb differ