diff --git a/README.md b/README.md index 29d1bdf1..a14b1052 100644 --- a/README.md +++ b/README.md @@ -226,11 +226,11 @@ Usamos `drizzle` y `drizzle-kit` para manejar conexiones a la BDD, que genera au > AKA. Crea o edita Tablas, Columnas, Indices, etc. -Primero, necesitas actualizar el archivo del esquema en `./src/datasources/db/schema/tables.ts`. (o ) +Primero, necesitas actualizar el archivo del esquema en `./src/workers/db_service/schema/tables.ts`. (o ) Este archivo define la estructura de las tablas en la BDD. -> Las relaciones entre tablas, se definen en `./src/datasources/db/schema/relations.ts`. -> Los esquemas de query/update se definen en `./src/datasources/db/schema/CRUD.ts`. +> Las relaciones entre tablas, se definen en `./src/workers/db_service/schema/relations.ts`. +> Los esquemas de query/update se definen en `./src/workers/db_service/schema/CRUD.ts`. Para definir una tabla, utilizas la función `pgTable()`, donde el primer argumento es el nombre de la tabla y el segundo es un objeto que define los campos de la tabla. diff --git a/drizzle.config.ts b/drizzle.config.ts index 53f501e1..78950d31 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -12,7 +12,7 @@ if (!process.env.NEON_URL) { export default defineConfig({ dialect: "postgresql", - schema: "./src/datasources/db/schema.ts", + schema: "./src/workers/db_service/schema.ts", out: "./drizzle/migrations", breakpoints: true, strict: true, diff --git a/drizzle/dbml.ts b/drizzle/dbml.ts index 2a96a82b..327ef520 100644 --- a/drizzle/dbml.ts +++ b/drizzle/dbml.ts @@ -2,7 +2,7 @@ import { resolve } from "node:path"; import { pgGenerate } from "drizzle-dbml-generator"; -import * as schema from "~/datasources/db/schema"; +import * as schema from "~workers/db_service/db/schema"; const out = resolve(__dirname, "./schema.dbml"); const relational = true; diff --git a/emails/templates/iacamp/postulation-with-team.tsx b/emails/templates/iacamp/postulation-with-team.tsx index 312aa089..a5ef7a58 100644 --- a/emails/templates/iacamp/postulation-with-team.tsx +++ b/emails/templates/iacamp/postulation-with-team.tsx @@ -40,9 +40,7 @@ export const AIHackathonPostulationWithTeamEmail = ({ name }: Props) => { selección. - - ¡Éxitos en la postulación! - + ¡Éxitos en la postulación! Un saludo, diff --git a/emails/templates/iacamp/waitlist.tsx b/emails/templates/iacamp/waitlist.tsx index 28abe6a3..b19f0b4f 100644 --- a/emails/templates/iacamp/waitlist.tsx +++ b/emails/templates/iacamp/waitlist.tsx @@ -44,13 +44,13 @@ export const IACampWaitlist = ({ nombre }: AddedToWaitlist) => { - + @@ -61,7 +61,10 @@ export const IACampWaitlist = ({ nombre }: AddedToWaitlist) => { para no olvidarlo. - Un saludo,
Equipo CommunityOS
+ + Un saludo, +
Equipo CommunityOS +

diff --git a/migrate.ts b/migrate.ts index 80fbdee0..785faf36 100644 --- a/migrate.ts +++ b/migrate.ts @@ -2,7 +2,7 @@ import { neon } from "@neondatabase/serverless"; import { config } from "dotenv"; -import { runMigration } from "~/datasources/db/runMigrations"; +import { runMigration } from "~workers/db_service/runMigrations"; import { defaultLogger } from "~/logging"; config({ path: process.cwd() + "/.dev.vars", override: true }); diff --git a/package-lock.json b/package-lock.json index 4b1f7e92..b0d2700e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "@sanity/client": "^6.7.0", "@tsndr/cloudflare-worker-jwt": "^2.5.3", "@types/react": "^18.2.22", + "concurrently": "^8.2.2", "cookie": "^0.5.0", "dataloader": "^2.2.2", "date-fns": "^3.6.0", @@ -36,10 +37,10 @@ "hono": "^3.9.0", "mercadopago": "^2.0.9", "p-map": "^6.0.0", - "pg": "^8.11.5", + "pg": "^8.12.0", "pino": "^9.2.0", "pino-pretty": "^11.2.1", - "postgres": "^3.4.3", + "postgres": "^3.4.4", "react": "^18.2.0", "resend": "^3.3.0", "slugify": "^1.6.6", @@ -10231,7 +10232,6 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", - "dev": true, "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", @@ -10245,7 +10245,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -10321,6 +10320,61 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/concurrently": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.2.tgz", + "integrity": "sha512-1dP4gpXFhei8IOtlXRE/T/4H88ElHgTiUzh71YUmtjTEHMSRS2Z/fgOxHSxxusGHogsRfxNq1vyAwxSC+EVyDg==", + "dependencies": { + "chalk": "^4.1.2", + "date-fns": "^2.30.0", + "lodash": "^4.17.21", + "rxjs": "^7.8.1", + "shell-quote": "^1.8.1", + "spawn-command": "0.0.2", + "supports-color": "^8.1.1", + "tree-kill": "^1.2.2", + "yargs": "^17.7.2" + }, + "bin": { + "conc": "dist/bin/concurrently.js", + "concurrently": "dist/bin/concurrently.js" + }, + "engines": { + "node": "^14.13.0 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/date-fns": { + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", + "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", + "dependencies": { + "@babel/runtime": "^7.21.0" + }, + "engines": { + "node": ">=0.11" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/date-fns" + } + }, + "node_modules/concurrently/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/config-chain": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", @@ -12109,7 +12163,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true, "engines": { "node": ">=6" } @@ -13227,7 +13280,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true, "engines": { "node": "6.* || 8.* || >= 10.*" } @@ -16464,9 +16516,9 @@ } }, "node_modules/pg": { - "version": "8.11.5", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.11.5.tgz", - "integrity": "sha512-jqgNHSKL5cbDjFlHyYsCXmQDrfIX/3RsNwYqpd4N0Kt8niLuNoRNH+aazv6cOd43gPh9Y4DjQCtb+X0MH0Hvnw==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", + "integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", "dependencies": { "pg-connection-string": "^2.6.4", "pg-pool": "^3.6.2", @@ -16913,9 +16965,9 @@ "dev": true }, "node_modules/postgres": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/postgres/-/postgres-3.4.3.tgz", - "integrity": "sha512-iHJn4+M9vbTdHSdDzNkC0crHq+1CUdFhx+YqCE+SqWxPjm+Zu63jq7yZborOBF64c8pc58O5uMudyL1FQcHacA==", + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/postgres/-/postgres-3.4.4.tgz", + "integrity": "sha512-IbyN+9KslkqcXa8AO9fxpk97PA4pzewvpi2B3Dwy9u4zpV32QicaEdgmF3eSQUzdRk7ttDHQejNgAEr4XoeH4A==", "engines": { "node": ">=12" }, @@ -18088,7 +18140,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -18594,7 +18645,6 @@ "version": "1.8.1", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -18830,6 +18880,11 @@ "deprecated": "Please use @jridgewell/sourcemap-codec instead", "dev": true }, + "node_modules/spawn-command": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", + "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==" + }, "node_modules/speedometer": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/speedometer/-/speedometer-1.0.0.tgz", @@ -19555,6 +19610,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", @@ -21061,7 +21124,6 @@ "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, "engines": { "node": ">=10" } @@ -21091,7 +21153,6 @@ "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", - "dev": true, "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", @@ -21109,7 +21170,6 @@ "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", - "dev": true, "engines": { "node": ">=12" } diff --git a/package.json b/package.json index 7c0dcf01..05354010 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ "prettier:ci": "prettier ./src --cache --check", "prettier:fix": "prettier ./src --cache --write", "typecheck": "tsc", - "dev": "wrangler dev --log-level info", + "dev:api": "wrangler dev --log-level info", + "dev:db": "wrangler dev --log-level info --config ./workers/db_service/wrangler.toml", + "dev": "concurrently --kill-others-on-fail \"npm run dev:api\" \"npm run dev:db\"", "dev:wall-of-fame": "wrangler dev --test-scheduled --config ./workers/wall_of_fame_cron/wrangler.toml", "dev:sanity": "wrangler dev --test-scheduled --config ./workers/sanity_asset_importer/wrangler.toml", "dev:auth": "wrangler dev --test-scheduled --config ./workers/auth_tokens/wrangler.toml", @@ -86,6 +88,7 @@ "@sanity/client": "^6.7.0", "@tsndr/cloudflare-worker-jwt": "^2.5.3", "@types/react": "^18.2.22", + "concurrently": "^8.2.2", "cookie": "^0.5.0", "dataloader": "^2.2.2", "date-fns": "^3.6.0", @@ -100,10 +103,10 @@ "hono": "^3.9.0", "mercadopago": "^2.0.9", "p-map": "^6.0.0", - "pg": "^8.11.5", + "pg": "^8.12.0", "pino": "^9.2.0", "pino-pretty": "^11.2.1", - "postgres": "^3.4.3", + "postgres": "^3.4.4", "react": "^18.2.0", "resend": "^3.3.0", "slugify": "^1.6.6", diff --git a/src/authn/index.ts b/src/authn/index.ts index 5fcc2105..0b61af38 100644 --- a/src/authn/index.ts +++ b/src/authn/index.ts @@ -2,14 +2,14 @@ import { decode, verify } from "@tsndr/cloudflare-worker-jwt"; import { Logger } from "pino"; import { TokenPayload } from "~/authn/types"; -import { ORM_TYPE } from "~/datasources/db"; -import { insertUsersSchema, USER } from "~/datasources/db/schema"; import { findUserByID, updateUserProfileInfo, } from "~/datasources/queries/users"; import { getUsername } from "~/datasources/queries/utils/createUsername"; import { unauthorizedError } from "~/errors"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { insertUserTeamsSchema, USER } from "~workers/db_service/db/schema"; // Obtener el token de autorización de la solicitud, ya sea del encabezado de // autorización o de la cookie "community-os-access-token" @@ -124,7 +124,7 @@ export const upsertUserFromRequest = async ({ const { avatar_url, name, user_name, email_verified, sub, picture } = payload.user_metadata; - const profileInfo = insertUsersSchema.safeParse({ + const profileInfo = insertUserTeamsSchema.safeParse({ email: payload.email.toLowerCase(), isEmailVerified: email_verified, imageUrl: avatar_url ? avatar_url : picture ? picture : "", diff --git a/src/authz/helpers.ts b/src/authz/helpers.ts index 1bc2f126..091e54c4 100644 --- a/src/authz/helpers.ts +++ b/src/authz/helpers.ts @@ -1,5 +1,5 @@ -import { ORM_TYPE } from "~/datasources/db"; -import { USER } from "~/datasources/db/schema"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { USER } from "~workers/db_service/db/schema"; import { Context } from "~/types"; const isCommuntiyAdmin = async ({ diff --git a/src/context.ts b/src/context.ts index 05e310c3..f39baa19 100644 --- a/src/context.ts +++ b/src/context.ts @@ -5,7 +5,6 @@ import { Resend } from "resend"; import { Env } from "worker-configuration"; import { getUserFromRequest, upsertUserFromRequest } from "~/authn"; -import { getDb } from "~/datasources/db"; import { getMercadoPagoFetch } from "~/datasources/mercadopago"; import { getSanityClient } from "~/datasources/sanity/client"; import { getStripeClient } from "~/datasources/stripe/client"; @@ -15,7 +14,6 @@ import { Context } from "~/types"; // export const createGraphqlContext = async ({ request, - NEON_URL, PURCHASE_CALLBACK_URL, MAIL_QUEUE, GOOGLE_PHOTOS_IMPORT_QUEUE, @@ -26,9 +24,9 @@ export const createGraphqlContext = async ({ SANITY_SECRET_TOKEN, SUPABASE_JWT_DECODER, STRIPE_KEY, - HYPERDRIVE, MERCADOPAGO_KEY, RPC_SERVICE_EMAIL, + RPC_SERVICE_DB, logger, }: YogaInitialContext & Env & { @@ -46,10 +44,6 @@ export const createGraphqlContext = async ({ throw new Error("Missing GOOGLE_PHOTOS_IMPORT_QUEUE"); } - if (!NEON_URL) { - throw new Error("Missing NEON_URL"); - } - if (!SUPABASE_JWT_DECODER) { throw new Error("Missing SUPABASE_JWT_DECODER"); } @@ -79,12 +73,6 @@ export const createGraphqlContext = async ({ throw new Error("Missing Sanity Configuration"); } - const DB_URL = - HYPERDRIVE?.connectionString?.startsWith("postgresql://fake-user:fake") && - APP_ENV === "development" - ? NEON_URL - : HYPERDRIVE.connectionString; - const GET_SANITY_CLIENT = () => getSanityClient({ projectId: SANITY_PROJECT_ID, @@ -96,10 +84,8 @@ export const createGraphqlContext = async ({ const GET_STRIPE_CLIENT = () => getStripeClient(STRIPE_KEY); const GET_MERCADOPAGO_CLIENT = getMercadoPagoFetch(MERCADOPAGO_KEY, logger); - const DB = await getDb({ - neonUrl: DB_URL, - logger, - }); + const DB = RPC_SERVICE_DB.getConnection(); + const RESEND = new Resend(RESEND_API_KEY); const ORIGINAL_USER = await upsertUserFromRequest({ request, @@ -134,5 +120,6 @@ export const createGraphqlContext = async ({ GET_MERCADOPAGO_CLIENT, logger, RPC_SERVICE_EMAIL, + RPC_SERVICE_DB, } satisfies Context; }; diff --git a/src/datasources/db/schema.ts b/src/datasources/db/schema.ts deleted file mode 100644 index 72f72f98..00000000 --- a/src/datasources/db/schema.ts +++ /dev/null @@ -1,31 +0,0 @@ -// TABLES/RELATIONS/CRUD -export * from "~/datasources/db/allowedCurrencies"; -export * from "~/datasources/db/communities"; -export * from "~/datasources/db/companies"; -export * from "~/datasources/db/confirmationToken"; -export * from "~/datasources/db/events"; -export * from "~/datasources/db/eventsCommunities"; -export * from "~/datasources/db/eventsTags"; -export * from "~/datasources/db/eventsUsers"; -export * from "~/datasources/db/paymentLogs"; -export * from "~/datasources/db/prices"; -export * from "~/datasources/db/purchaseOrders"; -export * from "~/datasources/db/salaries"; -export * from "~/datasources/db/schedule"; -export * from "~/datasources/db/sessions"; -export * from "~/datasources/db/sessionsToSpeakers"; -export * from "~/datasources/db/speaker"; -export * from "~/datasources/db/tags"; -export * from "~/datasources/db/tagsCommunities"; -export * from "~/datasources/db/teams"; -export * from "~/datasources/db/ticketPrice"; -export * from "~/datasources/db/tickets"; -export * from "~/datasources/db/users"; -export * from "~/datasources/db/usersCommunities"; -export * from "~/datasources/db/usersTags"; -export * from "~/datasources/db/userTeams"; -export * from "~/datasources/db/userTickets"; -export * from "~/datasources/db/workEmail"; -export * from "~/datasources/db/workRole"; -export * from "~/datasources/db/workSeniority"; -export * from "~/datasources/db/workSeniorityAndRole"; diff --git a/src/datasources/helpers/paginationQuery.ts b/src/datasources/helpers/paginationQuery.ts index 834f5714..a63a55ed 100644 --- a/src/datasources/helpers/paginationQuery.ts +++ b/src/datasources/helpers/paginationQuery.ts @@ -2,7 +2,7 @@ import { sql } from "drizzle-orm"; import { PgSelect } from "drizzle-orm/pg-core"; -import { ORM_TYPE } from "~/datasources/db"; +import { ORM_TYPE } from "~workers/db_service/db"; export type PaginationOptionsType = { page: number; diff --git a/src/datasources/mercadopago/index.ts b/src/datasources/mercadopago/index.ts index 4c3f9208..bab298ab 100644 --- a/src/datasources/mercadopago/index.ts +++ b/src/datasources/mercadopago/index.ts @@ -7,7 +7,7 @@ import { Logger } from "pino"; import { puchaseOrderPaymentStatusEnum, purchaseOrderStatusEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { someMinutesIntoTheFuture, toISOStringWithTimezone, diff --git a/src/datasources/queries/users.ts b/src/datasources/queries/users.ts index d051718c..d87693d0 100644 --- a/src/datasources/queries/users.ts +++ b/src/datasources/queries/users.ts @@ -2,15 +2,15 @@ import { eq } from "drizzle-orm"; import { Logger } from "pino"; import { z } from "zod"; -import { ORM_TYPE } from "~/datasources/db"; +import { getUsername } from "~/datasources/queries/utils/createUsername"; +import { ORM_TYPE } from "~workers/db_service/db"; import { allowedUserUpdateForAuth, insertUsersSchema, selectUsersSchema, usersSchema, UserStatusEnum, -} from "~/datasources/db/schema"; -import { getUsername } from "~/datasources/queries/utils/createUsername"; +} from "~workers/db_service/db/schema"; export const findUserByID = async (db: ORM_TYPE, id: string) => { const result = await db.query.usersSchema.findFirst({ diff --git a/src/datasources/stripe/index.ts b/src/datasources/stripe/index.ts index 5a30e606..81bf6a09 100644 --- a/src/datasources/stripe/index.ts +++ b/src/datasources/stripe/index.ts @@ -3,7 +3,7 @@ import Stripe from "stripe"; import { puchaseOrderPaymentStatusEnum, purchaseOrderStatusEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { someMinutesIntoTheFuture } from "~/datasources/helpers"; const getPaymentStatusFromStripeSession = ( diff --git a/src/schema/allowedCurrency/types.ts b/src/schema/allowedCurrency/types.ts index 9b57a7d5..96cdf650 100644 --- a/src/schema/allowedCurrency/types.ts +++ b/src/schema/allowedCurrency/types.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { validPaymentMethodsEnum } from "~/datasources/db/schema"; +import { validPaymentMethodsEnum } from "~workers/db_service/db/schema"; import { AllowedCurrencyRef } from "~/schema/shared/refs"; const ValidPaymentMethodsEnumType = builder.enumType("ValidPaymentMethods", { diff --git a/src/schema/community/communityFetcher.ts b/src/schema/community/communityFetcher.ts index 7c82b9a5..ba47910e 100644 --- a/src/schema/community/communityFetcher.ts +++ b/src/schema/community/communityFetcher.ts @@ -1,7 +1,7 @@ import { SQL, and, asc, ilike, inArray, lte } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; -import { communitySchema } from "~/datasources/db/schema"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { communitySchema } from "~workers/db_service/db/schema"; import { PaginationOptionsType, paginationDBHelper, diff --git a/src/schema/community/mutations.ts b/src/schema/community/mutations.ts index 17d72459..ad8fccff 100644 --- a/src/schema/community/mutations.ts +++ b/src/schema/community/mutations.ts @@ -6,7 +6,7 @@ import { communitySchema, insertCommunitySchema, selectCommunitySchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { CommunityRef } from "~/schema/shared/refs"; import { canCreateCommunity, canEditCommunity } from "~/validations"; diff --git a/src/schema/community/queries.ts b/src/schema/community/queries.ts index 55c2d125..604530ca 100644 --- a/src/schema/community/queries.ts +++ b/src/schema/community/queries.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { selectCommunitySchema } from "~/datasources/db/schema"; +import { selectCommunitySchema } from "~workers/db_service/db/schema"; import { communitiesFetcher } from "~/schema/community/communityFetcher"; import { CommunityRef } from "~/schema/shared/refs"; diff --git a/src/schema/community/types.ts b/src/schema/community/types.ts index b6046bdd..dbf8a9d1 100644 --- a/src/schema/community/types.ts +++ b/src/schema/community/types.ts @@ -1,5 +1,8 @@ import { builder } from "~/builder"; -import { selectEventsSchema, selectUsersSchema } from "~/datasources/db/schema"; +import { + selectEventsSchema, + selectUsersSchema, +} from "~workers/db_service/db/schema"; import { eventsFetcher } from "~/schema/events/eventsFetcher"; import { CommunityRef, EventRef, UserRef } from "~/schema/shared/refs"; diff --git a/src/schema/company/mutations.ts b/src/schema/company/mutations.ts index d14cd50a..719f297f 100644 --- a/src/schema/company/mutations.ts +++ b/src/schema/company/mutations.ts @@ -5,7 +5,7 @@ import { companiesSchema, insertCompaniesSchema, selectCompaniesSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { CompanyRef } from "~/schema/shared/refs"; import { CompanyStatus } from "./types"; diff --git a/src/schema/company/queries.ts b/src/schema/company/queries.ts index 5c4b2913..28f36ed9 100644 --- a/src/schema/company/queries.ts +++ b/src/schema/company/queries.ts @@ -4,7 +4,7 @@ import { builder } from "~/builder"; import { companiesSchema, selectCompaniesSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; import { CompanyRef } from "~/schema/shared/refs"; diff --git a/src/schema/events/eventsFetcher.ts b/src/schema/events/eventsFetcher.ts index 39ce3f5b..dade8773 100644 --- a/src/schema/events/eventsFetcher.ts +++ b/src/schema/events/eventsFetcher.ts @@ -11,13 +11,6 @@ import { lte, } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; -import { eventsSchema } from "~/datasources/db/events"; -import { - userTicketsSchema, - ticketsSchema, - eventsToCommunitiesSchema, -} from "~/datasources/db/schema"; import { PaginationOptionsType, paginationDBHelper, @@ -25,6 +18,13 @@ import { import { SortableSchemaFields } from "~/datasources/helpers/sorting"; import { eventStatus, eventVisibility } from "~/schema/events/types"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { + userTicketsSchema, + ticketsSchema, + eventsToCommunitiesSchema, + eventsSchema, +} from "~workers/db_service/db/schema"; export type UserTicketSearch = { userId?: string; diff --git a/src/schema/events/mutations.ts b/src/schema/events/mutations.ts index b7cf1b06..eb3052a1 100644 --- a/src/schema/events/mutations.ts +++ b/src/schema/events/mutations.ts @@ -8,7 +8,7 @@ import { insertEventsSchema, selectEventsSchema, updateEventsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { EventRef } from "~/schema/shared/refs"; import { canCreateEvent, canEditEvent } from "~/validations"; diff --git a/src/schema/events/queries.ts b/src/schema/events/queries.ts index ae67b506..5a789692 100644 --- a/src/schema/events/queries.ts +++ b/src/schema/events/queries.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { selectEventsSchema } from "~/datasources/db/schema"; +import { selectEventsSchema } from "~workers/db_service/db/schema"; import { eventsFetcher } from "~/schema/events/eventsFetcher"; import { createPaginationInputType, diff --git a/src/schema/events/tests/events.test.ts b/src/schema/events/tests/events.test.ts index ce97269f..ebf3be0c 100644 --- a/src/schema/events/tests/events.test.ts +++ b/src/schema/events/tests/events.test.ts @@ -4,7 +4,7 @@ import { it, describe, assert } from "vitest"; import { UserParticipationStatusEnum, UserTeamRoleEnum, -} from "~/datasources/db/userTeams"; +} from "~workers/db_service/userTeams"; import { EventStatus, EventVisibility, diff --git a/src/schema/events/types.ts b/src/schema/events/types.ts index 2a0ba285..e717d377 100644 --- a/src/schema/events/types.ts +++ b/src/schema/events/types.ts @@ -14,7 +14,7 @@ import { ticketVisibilityEnum, ticketsSchema, usersSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { getImagesBySanityEventId } from "~/datasources/sanity/images"; import { eventsFetcher } from "~/schema/events/eventsFetcher"; import { diff --git a/src/schema/money/queries.ts b/src/schema/money/queries.ts index 2abee0f7..a168bf08 100644 --- a/src/schema/money/queries.ts +++ b/src/schema/money/queries.ts @@ -1,14 +1,14 @@ import { SQL, gte, lte } from "drizzle-orm"; import { builder } from "~/builder"; -import { - paymentLogsSchema, - selectPaymentLogsSchema, -} from "~/datasources/db/paymentLogs"; import { ConsolidatedPaymentLogEntryRef, PaymentLogRef, } from "~/schema/shared/refs"; +import { + paymentLogsSchema, + selectPaymentLogsSchema, +} from "~workers/db_service/db/schema"; const SearchPaymentLogsInput = builder.inputType("SearchPaymentLogsInput", { fields: (t) => ({ diff --git a/src/schema/purchaseOrder/actions.tsx b/src/schema/purchaseOrder/actions.tsx index 8180ec1e..c48c0218 100644 --- a/src/schema/purchaseOrder/actions.tsx +++ b/src/schema/purchaseOrder/actions.tsx @@ -3,7 +3,7 @@ import { GraphQLError } from "graphql"; import { Logger } from "pino"; import { AsyncReturnType } from "type-fest"; -import { ORM_TYPE } from "~/datasources/db"; +import { ORM_TYPE } from "~workers/db_service/db"; import { USER, puchaseOrderPaymentStatusEnum, @@ -12,7 +12,7 @@ import { selectPurchaseOrdersSchema, selectTicketSchema, selectUserTicketsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { createMercadoPagoPayment, getMercadoPagoPayment, diff --git a/src/schema/purchaseOrder/helpers.ts b/src/schema/purchaseOrder/helpers.ts index 4755faa3..9672708d 100644 --- a/src/schema/purchaseOrder/helpers.ts +++ b/src/schema/purchaseOrder/helpers.ts @@ -1,4 +1,4 @@ -import { ORM_TYPE } from "~/datasources/db"; +import { ORM_TYPE } from "~workers/db_service/db"; export const getPurchaseRedirectURLsFromPurchaseOrder = async ({ DB, diff --git a/src/schema/purchaseOrder/mutations.tsx b/src/schema/purchaseOrder/mutations.tsx index a665122c..1da33809 100644 --- a/src/schema/purchaseOrder/mutations.tsx +++ b/src/schema/purchaseOrder/mutations.tsx @@ -1,7 +1,7 @@ import { authHelpers } from "~/authz/helpers"; import { builder } from "~/builder"; -import { selectPurchaseOrdersSchema } from "~/datasources/db/purchaseOrders"; import { getPurchaseRedirectURLsFromPurchaseOrder } from "~/schema/purchaseOrder/helpers"; +import { selectPurchaseOrdersSchema } from "~workers/db_service/db/schema"; import { createPaymentIntent, syncPurchaseOrderPaymentStatus } from "./actions"; import { PurchaseOrderRef } from "./types"; diff --git a/src/schema/purchaseOrder/purchaseOrderFetcher.ts b/src/schema/purchaseOrder/purchaseOrderFetcher.ts index 9fb87392..e620831a 100644 --- a/src/schema/purchaseOrder/purchaseOrderFetcher.ts +++ b/src/schema/purchaseOrder/purchaseOrderFetcher.ts @@ -1,17 +1,17 @@ import { SQL, and, ilike, inArray, desc, asc } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; -import { - purchaseOrderPaymentPlatforms, - purchaseOrderStatusEnum, - purchaseOrdersSchema, -} from "~/datasources/db/purchaseOrders"; import { PaginationOptionsType, paginationDBHelper, } from "~/datasources/helpers/paginationQuery"; import { SortableSchemaFields } from "~/datasources/helpers/sorting"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { + purchaseOrderPaymentPlatforms, + purchaseOrderStatusEnum, + purchaseOrdersSchema, +} from "~workers/db_service/db/schema"; export type PurchaseOrderSearch = { userIds?: string[]; diff --git a/src/schema/purchaseOrder/queries.ts b/src/schema/purchaseOrder/queries.ts index 59e2d16b..92da396f 100644 --- a/src/schema/purchaseOrder/queries.ts +++ b/src/schema/purchaseOrder/queries.ts @@ -1,10 +1,10 @@ import { builder } from "~/builder"; -import { selectPurchaseOrdersSchema } from "~/datasources/db/purchaseOrders"; import { createPaginationInputType, createPaginationObjectType, } from "~/schema/pagination/types"; import { purchaseOrderFetcher } from "~/schema/purchaseOrder/purchaseOrderFetcher"; +import { selectPurchaseOrdersSchema } from "~workers/db_service/db/schema"; import { PurchaseOrderRef } from "./types"; diff --git a/src/schema/purchaseOrder/types.ts b/src/schema/purchaseOrder/types.ts index 185f2435..e12bd376 100644 --- a/src/schema/purchaseOrder/types.ts +++ b/src/schema/purchaseOrder/types.ts @@ -5,7 +5,7 @@ import { selectAllowedCurrencySchema, puchaseOrderPaymentStatusEnum, purchaseOrderStatusEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { AllowedCurrencyRef, UserTicketRef } from "~/schema/shared/refs"; export const PurchaseOrderPaymentStatusEnum = builder.enumType( diff --git a/src/schema/salary/mutations.ts b/src/schema/salary/mutations.ts index c7a1d56f..82c30d75 100644 --- a/src/schema/salary/mutations.ts +++ b/src/schema/salary/mutations.ts @@ -5,7 +5,7 @@ import { insertSalariesSchema, salariesSchema, selectSalariesSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { GenderEnum } from "~/schema/shared/enums"; import { SalaryRef } from "~/schema/shared/refs"; diff --git a/src/schema/salary/queries.ts b/src/schema/salary/queries.ts index e8cc768f..2dcc801a 100644 --- a/src/schema/salary/queries.ts +++ b/src/schema/salary/queries.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { selectSalariesSchema } from "~/datasources/db/schema"; +import { selectSalariesSchema } from "~workers/db_service/db/schema"; import { SalaryRef } from "~/schema/shared/refs"; builder.queryFields((t) => ({ diff --git a/src/schema/salary/tests/editSalary.test.ts b/src/schema/salary/tests/editSalary.test.ts index 72c19480..f34041c2 100644 --- a/src/schema/salary/tests/editSalary.test.ts +++ b/src/schema/salary/tests/editSalary.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vitest"; -import { GenderOptionsEnum } from "~/datasources/db/shared"; +import { GenderOptionsEnum } from "~workers/db_service/shared"; import { Gender, TypeOfEmployment, WorkMetodology } from "~/generated/types"; import { executeGraphqlOperation, diff --git a/src/schema/salary/types.ts b/src/schema/salary/types.ts index 4e761b42..2d509811 100644 --- a/src/schema/salary/types.ts +++ b/src/schema/salary/types.ts @@ -3,7 +3,7 @@ import { selectCompaniesSchema, selectWorkRoleSchema, selectWorkSenioritySchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { GenderEnum } from "~/schema/shared/enums"; import { CompanyRef, diff --git a/src/schema/sessions/sessionsFetcher.ts b/src/schema/sessions/sessionsFetcher.ts index 0651b831..c576fe16 100644 --- a/src/schema/sessions/sessionsFetcher.ts +++ b/src/schema/sessions/sessionsFetcher.ts @@ -1,13 +1,15 @@ import { SQL, and, asc, ilike, inArray } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; -import { sessionSchema } from "~/datasources/db/sessions"; -import { sessionToSpeakersSchema } from "~/datasources/db/sessionsToSpeakers"; import { PaginationOptionsType, paginationDBHelper, } from "~/datasources/helpers/paginationQuery"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { + sessionSchema, + sessionToSpeakersSchema, +} from "~workers/db_service/db/schema"; export type SessionSearch = { sessionIds?: string[]; diff --git a/src/schema/sessions/types.ts b/src/schema/sessions/types.ts index 02f07785..26221c01 100644 --- a/src/schema/sessions/types.ts +++ b/src/schema/sessions/types.ts @@ -4,7 +4,7 @@ import { builder } from "~/builder"; import { selectSessionSchema, selectSpeakerSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { sessionsFetcher } from "~/schema/sessions/sessionsFetcher"; import { speakersFetcher } from "~/schema/speakers/speakersFetcher"; import { SpeakerRef } from "~/schema/speakers/types"; diff --git a/src/schema/shared/enums.ts b/src/schema/shared/enums.ts index 0757782c..a19470e3 100644 --- a/src/schema/shared/enums.ts +++ b/src/schema/shared/enums.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { GenderOptionsEnum } from "~/datasources/db/shared"; +import { GenderOptionsEnum } from "~workers/db_service/db/shared"; export const GenderEnum = builder.enumType(GenderOptionsEnum, { name: "Gender", diff --git a/src/schema/shared/refs.ts b/src/schema/shared/refs.ts index 7c385352..3bd6f42c 100644 --- a/src/schema/shared/refs.ts +++ b/src/schema/shared/refs.ts @@ -15,7 +15,7 @@ import { selectWorkRoleSchema, selectWorkSenioritySchema, selectPaymentLogsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { SanityAsset, SanityEvent } from "~/datasources/sanity/types"; export type UserGraphqlSchema = z.infer; diff --git a/src/schema/speakers/speakersFetcher.ts b/src/schema/speakers/speakersFetcher.ts index 62d3441b..ef6efe82 100644 --- a/src/schema/speakers/speakersFetcher.ts +++ b/src/schema/speakers/speakersFetcher.ts @@ -1,13 +1,15 @@ import { SQL, and, asc, ilike, inArray } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; -import { sessionToSpeakersSchema } from "~/datasources/db/sessionsToSpeakers"; -import { speakerSchema } from "~/datasources/db/speaker"; import { PaginationOptionsType, paginationDBHelper, } from "~/datasources/helpers/paginationQuery"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { + sessionToSpeakersSchema, + speakerSchema, +} from "~workers/db_service/db/schema"; export type SpeakerSearch = { speakerIds?: string[]; diff --git a/src/schema/speakers/types.ts b/src/schema/speakers/types.ts index f010a805..f6502bcd 100644 --- a/src/schema/speakers/types.ts +++ b/src/schema/speakers/types.ts @@ -1,11 +1,13 @@ import { z } from "zod"; import { builder } from "~/builder"; -import { selectSessionSchema } from "~/datasources/db/sessions"; -import { selectSpeakerSchema } from "~/datasources/db/speaker"; import { sessionsFetcher } from "~/schema/sessions/sessionsFetcher"; import { SessionLoadable } from "~/schema/sessions/types"; import { speakersFetcher } from "~/schema/speakers/speakersFetcher"; +import { + selectSpeakerSchema, + selectSessionSchema, +} from "~workers/db_service/db/schema"; type SpeakerGraphqlSchema = z.infer; export const SpeakerRef = builder.objectRef("Speaker"); diff --git a/src/schema/tags/queries.ts b/src/schema/tags/queries.ts index 9d59f8a0..db6a3164 100644 --- a/src/schema/tags/queries.ts +++ b/src/schema/tags/queries.ts @@ -1,7 +1,7 @@ import { SQL, eq, ilike } from "drizzle-orm"; import { builder } from "~/builder"; -import { selectTagsSchema, tagsSchema } from "~/datasources/db/schema"; +import { selectTagsSchema, tagsSchema } from "~workers/db_service/db/schema"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; import { TagRef } from "~/schema/shared/refs"; diff --git a/src/schema/teams/mutations.ts b/src/schema/teams/mutations.ts index d57daac4..aaa9b919 100644 --- a/src/schema/teams/mutations.ts +++ b/src/schema/teams/mutations.ts @@ -12,7 +12,7 @@ import { UserParticipationStatusEnum, UserTeamRoleEnum, userTeamsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { addToObjectIfPropertyExists } from "~/schema/shared/helpers"; import { teamsFetcher } from "~/schema/teams/teamsFetcher"; import { AddUserToTeamResponseRef, TeamRef } from "~/schema/teams/types"; diff --git a/src/schema/teams/queries.ts b/src/schema/teams/queries.ts index 285dec9f..4338a939 100644 --- a/src/schema/teams/queries.ts +++ b/src/schema/teams/queries.ts @@ -1,11 +1,14 @@ import { builder } from "~/builder"; -import { selectTeamsSchema, TeamStatusEnum } from "~/datasources/db/teams"; import { createPaginationInputType, createPaginationObjectType, } from "~/schema/pagination/types"; import { teamsFetcher } from "~/schema/teams/teamsFetcher"; import { TeamRef, TeamStatus } from "~/schema/teams/types"; +import { + selectTeamsSchema, + TeamStatusEnum, +} from "~workers/db_service/db/schema"; const PaginatedTeamRef = createPaginationObjectType(TeamRef); diff --git a/src/schema/teams/teamsFetcher.ts b/src/schema/teams/teamsFetcher.ts index 6720b420..4e13521d 100644 --- a/src/schema/teams/teamsFetcher.ts +++ b/src/schema/teams/teamsFetcher.ts @@ -1,12 +1,12 @@ import { SQL, and, asc, ilike, inArray } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; +import { ORM_TYPE } from "~workers/db_service/db"; import { teamsSchema, TeamStatusEnum, UserTeamRoleEnum, userTeamsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { PaginationOptionsType, paginationDBHelper, diff --git a/src/schema/teams/types.ts b/src/schema/teams/types.ts index 1e74e280..cc6f65a6 100644 --- a/src/schema/teams/types.ts +++ b/src/schema/teams/types.ts @@ -7,7 +7,7 @@ import { TeamStatusEnum, UserParticipationStatusEnum, UserTeamRoleEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { EventLoadable } from "~/schema/events/types"; import { UserGraphqlSchema, UserRef } from "~/schema/shared/refs"; diff --git a/src/schema/ticket/helpers.ts b/src/schema/ticket/helpers.ts index 20355ead..b658f2bd 100644 --- a/src/schema/ticket/helpers.ts +++ b/src/schema/ticket/helpers.ts @@ -2,8 +2,11 @@ import { eq } from "drizzle-orm"; import { Logger } from "pino"; import Stripe from "stripe"; -import { TRANSACTION_HANDLER } from "~/datasources/db"; -import { selectTicketSchema, ticketsSchema } from "~/datasources/db/schema"; +import { TRANSACTION_HANDLER } from "~workers/db_service/db"; +import { + selectTicketSchema, + ticketsSchema, +} from "~workers/db_service/db/schema"; import { createStripeProductAndPrice } from "~/datasources/stripe"; export const ensureProductsAreCreated = async ({ diff --git a/src/schema/ticket/mutations.ts b/src/schema/ticket/mutations.ts index 4aaca871..622f864c 100644 --- a/src/schema/ticket/mutations.ts +++ b/src/schema/ticket/mutations.ts @@ -12,7 +12,7 @@ import { ticketsPricesSchema, ticketsSchema, updateTicketSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { addToObjectIfPropertyExists } from "~/schema/shared/helpers"; import { TicketRef } from "~/schema/shared/refs"; import { ensureProductsAreCreated } from "~/schema/ticket/helpers"; diff --git a/src/schema/ticket/ticketsFetcher.ts b/src/schema/ticket/ticketsFetcher.ts index e13f1df3..d7b46287 100644 --- a/src/schema/ticket/ticketsFetcher.ts +++ b/src/schema/ticket/ticketsFetcher.ts @@ -1,11 +1,11 @@ import { SQL, and, arrayContains, asc, desc, inArray } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; +import { ORM_TYPE } from "~workers/db_service/db"; import { ticketsSchema, ticketStatusEnum, ticketVisibilityEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { paginationDBHelper, PaginationOptionsType, diff --git a/src/schema/ticket/types.ts b/src/schema/ticket/types.ts index 25406342..1b3188d4 100644 --- a/src/schema/ticket/types.ts +++ b/src/schema/ticket/types.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { selectAllowedCurrencySchema } from "~/datasources/db/schema"; +import { selectAllowedCurrencySchema } from "~workers/db_service/db/schema"; import { EventLoadable } from "~/schema/events/types"; import { AllowedCurrencyRef, PriceRef, TicketRef } from "~/schema/shared/refs"; diff --git a/src/schema/user/mutations.ts b/src/schema/user/mutations.ts index 1fcb56be..be921c6c 100644 --- a/src/schema/user/mutations.ts +++ b/src/schema/user/mutations.ts @@ -8,7 +8,7 @@ import { updateUsersSchema, usersSchema, usersToCommunitiesSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { UserRef } from "~/schema/shared/refs"; import { pronounsEnum } from "~/schema/user/types"; import { diff --git a/src/schema/user/queries.ts b/src/schema/user/queries.ts index e50779f6..8d6c29bf 100644 --- a/src/schema/user/queries.ts +++ b/src/schema/user/queries.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { selectUsersSchema } from "~/datasources/db/schema"; +import { selectUsersSchema } from "~workers/db_service/db/schema"; import { createPaginationInputType, createPaginationObjectType, diff --git a/src/schema/user/types.ts b/src/schema/user/types.ts index 664cd8ac..f2fe7759 100644 --- a/src/schema/user/types.ts +++ b/src/schema/user/types.ts @@ -5,7 +5,7 @@ import { PronounsEnum, selectCommunitySchema, selectTeamsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { CommunityRef, UserRef } from "~/schema/shared/refs"; import { TeamRef } from "~/schema/teams/types"; diff --git a/src/schema/user/userFetcher.ts b/src/schema/user/userFetcher.ts index 80f7fd3f..afcc0f66 100644 --- a/src/schema/user/userFetcher.ts +++ b/src/schema/user/userFetcher.ts @@ -1,12 +1,12 @@ import { SQL, and, asc, ilike, inArray, or } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; +import { ORM_TYPE } from "~workers/db_service/db"; import { AllowedUserTags, tagsSchema, usersSchema, usersTagsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { PaginationOptionsType, paginationDBHelper, diff --git a/src/schema/user/userHelpers.ts b/src/schema/user/userHelpers.ts index 20eda27f..098615fd 100644 --- a/src/schema/user/userHelpers.ts +++ b/src/schema/user/userHelpers.ts @@ -1,14 +1,14 @@ import { Logger } from "pino"; import { SetOptional } from "type-fest"; -import { ORM_TYPE } from "~/datasources/db"; +import { usersFetcher } from "~/schema/user/userFetcher"; +import { ORM_TYPE } from "~workers/db_service/db"; import { insertUsersSchema, USER, usersSchema, UserStatusEnum, -} from "~/datasources/db/users"; -import { usersFetcher } from "~/schema/user/userFetcher"; +} from "~workers/db_service/db/schema"; export const createUserIfNotExists = async ({ DB, diff --git a/src/schema/userTickets/mutations.ts b/src/schema/userTickets/mutations.ts index 1e0ad700..ada32a0d 100644 --- a/src/schema/userTickets/mutations.ts +++ b/src/schema/userTickets/mutations.ts @@ -9,7 +9,7 @@ import { selectPurchaseOrdersSchema, selectUserTicketsSchema, userTicketsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { getPurchaseRedirectURLsFromPurchaseOrder } from "~/schema/purchaseOrder/helpers"; import { PurchaseOrderRef } from "~/schema/purchaseOrder/types"; import { isValidUUID } from "~/schema/shared/helpers"; diff --git a/src/schema/userTickets/queries.ts b/src/schema/userTickets/queries.ts index 1ce67be2..afdf09c5 100644 --- a/src/schema/userTickets/queries.ts +++ b/src/schema/userTickets/queries.ts @@ -3,7 +3,7 @@ import { selectUserTicketsSchema, USER, userTicketsApprovalStatusEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { createPaginationInputType, createPaginationObjectType, diff --git a/src/schema/userTickets/types.ts b/src/schema/userTickets/types.ts index 2ea74a1a..1e5b3ea2 100644 --- a/src/schema/userTickets/types.ts +++ b/src/schema/userTickets/types.ts @@ -3,7 +3,7 @@ import { userTicketsApprovalStatusEnum, puchaseOrderPaymentStatusEnum, userTicketsRedemptionStatusEnum, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { PurchaseOrderLoadable, PurchaseOrderPaymentStatusEnum, diff --git a/src/schema/userTickets/userTicketFetcher.ts b/src/schema/userTickets/userTicketFetcher.ts index cbf83c9a..f8b6e16e 100644 --- a/src/schema/userTickets/userTicketFetcher.ts +++ b/src/schema/userTickets/userTicketFetcher.ts @@ -1,21 +1,19 @@ import { SQL, and, desc, eq, inArray } from "drizzle-orm"; -import { ORM_TYPE } from "~/datasources/db"; -import { eventsSchema } from "~/datasources/db/events"; import { + PaginationOptionsType, + paginationDBHelper, +} from "~/datasources/helpers/paginationQuery"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { + eventsSchema, puchaseOrderPaymentStatusEnum, purchaseOrdersSchema, -} from "~/datasources/db/purchaseOrders"; -import { ticketsSchema } from "~/datasources/db/tickets"; -import { + ticketsSchema, userTicketsApprovalStatusEnum, userTicketsRedemptionStatusEnum, userTicketsSchema, -} from "~/datasources/db/userTickets"; -import { - PaginationOptionsType, - paginationDBHelper, -} from "~/datasources/helpers/paginationQuery"; +} from "~workers/db_service/db/schema"; export type UserTicketSearch = { userIds?: string[]; diff --git a/src/schema/workEmail/mutations.ts b/src/schema/workEmail/mutations.ts index 82e6a2a0..68c86f35 100644 --- a/src/schema/workEmail/mutations.ts +++ b/src/schema/workEmail/mutations.ts @@ -9,7 +9,7 @@ import { insertWorkEmailSchema, selectWorkEmailSchema, workEmailSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { enqueueEmail } from "~/datasources/queues/mail"; import { WorkEmailRef } from "~/schema/shared/refs"; builder.mutationFields((t) => ({ diff --git a/src/schema/workEmail/queries.ts b/src/schema/workEmail/queries.ts index 629a73b6..ffd95cf1 100644 --- a/src/schema/workEmail/queries.ts +++ b/src/schema/workEmail/queries.ts @@ -1,7 +1,7 @@ import { eq } from "drizzle-orm"; import { builder } from "~/builder"; -import { selectWorkEmailSchema } from "~/datasources/db/schema"; +import { selectWorkEmailSchema } from "~workers/db_service/db/schema"; import { ValidatedWorkEmailRef, WorkEmailRef } from "~/schema/shared/refs"; builder.queryFields((t) => ({ diff --git a/src/schema/workEmail/types.ts b/src/schema/workEmail/types.ts index 12a81774..40aa209d 100644 --- a/src/schema/workEmail/types.ts +++ b/src/schema/workEmail/types.ts @@ -1,11 +1,11 @@ import { builder } from "~/builder"; -import { selectCompaniesSchema } from "~/datasources/db/schema"; -import { statusEnumOptions } from "~/datasources/db/shared"; import { CompanyRef, ValidatedWorkEmailRef, WorkEmailRef, } from "~/schema/shared/refs"; +import { selectCompaniesSchema } from "~workers/db_service/db/schema"; +import { statusEnumOptions } from "~workers/db_service/db/shared"; const EmailStatusEnum = builder.enumType("EmailStatus", { values: statusEnumOptions, diff --git a/src/schema/workRole/queries.ts b/src/schema/workRole/queries.ts index e68b6064..e1850d5f 100644 --- a/src/schema/workRole/queries.ts +++ b/src/schema/workRole/queries.ts @@ -2,7 +2,7 @@ import { builder } from "~/builder"; import { selectWorkRoleSchema, selectWorkSenioritySchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { WorkRoleRef, WorkSeniorityRef } from "~/schema/shared/refs"; const WorkRoleSenioritiesInput = builder.inputType("WorkRoleSenioritiesInput", { diff --git a/src/schema/workRole/types.ts b/src/schema/workRole/types.ts index f4082af0..aeb72734 100644 --- a/src/schema/workRole/types.ts +++ b/src/schema/workRole/types.ts @@ -1,5 +1,5 @@ import { builder } from "~/builder"; -import { selectWorkSenioritySchema } from "~/datasources/db/schema"; +import { selectWorkSenioritySchema } from "~workers/db_service/db/schema"; import { WorkRoleRef, WorkSeniorityRef } from "~/schema/shared/refs"; builder.objectType(WorkRoleRef, { diff --git a/src/tests/fixtures/databaseHelper.ts b/src/tests/fixtures/databaseHelper.ts index 03ab3ed2..799963bd 100644 --- a/src/tests/fixtures/databaseHelper.ts +++ b/src/tests/fixtures/databaseHelper.ts @@ -4,8 +4,8 @@ import { migrate } from "drizzle-orm/postgres-js/migrator"; import postgres from "postgres"; import { v4 } from "uuid"; -import { ORM_TYPE } from "~/datasources/db"; -import * as schema from "~/datasources/db/schema"; +import { ORM_TYPE } from "~workers/db_service/db"; +import * as schema from "~workers/db_service/db/schema"; export const testDatabasesFolder = `.test_dbs`; export const migrationsFolder = `${process.cwd()}/drizzle/migrations`; diff --git a/src/tests/fixtures/index.ts b/src/tests/fixtures/index.ts index d02d530a..2a75e5c6 100644 --- a/src/tests/fixtures/index.ts +++ b/src/tests/fixtures/index.ts @@ -86,13 +86,13 @@ import { selectUserTeamsSchema, userTeamsSchema, PronounsEnum, -} from "~/datasources/db/schema"; -import { GenderOptionsEnum } from "~/datasources/db/shared"; +} from "~workers/db_service/db/schema"; +import { GenderOptionsEnum } from "~workers/db_service/shared"; import { insertTicketPriceSchema, selectTicketPriceSchema, ticketsPricesSchema, -} from "~/datasources/db/ticketPrice"; +} from "~workers/db_service/ticketPrice"; import { TicketApprovalStatus, TicketRedemptionStatus, diff --git a/src/types.ts b/src/types.ts index ad70d5c2..3f392a66 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,11 +2,11 @@ import pino from "pino"; import { Resend } from "resend"; import { Env } from "worker-configuration"; -import { ORM_TYPE } from "~/datasources/db"; -import { USER } from "~/datasources/db/schema"; import { MercadoPagoFetch } from "~/datasources/mercadopago"; import { getSanityClient } from "~/datasources/sanity/client"; import { getStripeClient } from "~/datasources/stripe/client"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { USER } from "~workers/db_service/db/schema"; export type Context = { DB: ORM_TYPE; @@ -21,6 +21,7 @@ export type Context = { GOOGLE_PHOTOS_IMPORT_QUEUE: Queue; PURCHASE_CALLBACK_URL: string; RPC_SERVICE_EMAIL: Env["RPC_SERVICE_EMAIL"]; + RPC_SERVICE_DB: Env["RPC_SERVICE_DB"]; }; export type GraphqlContext = Context & diff --git a/src/validations/index.ts b/src/validations/index.ts index d87886e8..1772e3fc 100644 --- a/src/validations/index.ts +++ b/src/validations/index.ts @@ -1,8 +1,8 @@ import { inArray } from "drizzle-orm"; import { z } from "zod"; -import { ORM_TYPE } from "~/datasources/db"; -import { selectUsersSchema } from "~/datasources/db/users"; +import { ORM_TYPE } from "~workers/db_service/db"; +import { selectUsersSchema } from "~workers/db_service/users"; import { EventStatus } from "~/generated/types"; import { eventsFetcher } from "~/schema/events/eventsFetcher"; diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index 6d631a62..c99bc135 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -1,5 +1,6 @@ // Generated by Wrangler on Fri Jul 07 2023 08:10:34 GMT-0700 (Pacific Daylight Time) -import type WorkerEntrypoint from "./workers/transactional_email_service"; +import type DBServiceEntryPoint from "./workers/db_service"; +import type EmailServiceEntryPoint from "./workers/transactional_email_service"; export interface Env { GRAPHQL_BASE_ENDPOINT: "/"; NEON_URL: string | undefined; @@ -17,7 +18,8 @@ export interface Env { HIGHLIGHT_PROJECT_ID: string; HYPERDRIVE: Hyperdrive; PURCHASE_CALLBACK_URL: string; - RPC_SERVICE_EMAIL: Service; + RPC_SERVICE_EMAIL: Service; + RPC_SERVICE_DB: Service; } declare global { diff --git a/src/datasources/db/allowedCurrencies.ts b/workers/db_service/db/allowedCurrencies.ts similarity index 100% rename from src/datasources/db/allowedCurrencies.ts rename to workers/db_service/db/allowedCurrencies.ts diff --git a/src/datasources/db/communities.ts b/workers/db_service/db/communities.ts similarity index 100% rename from src/datasources/db/communities.ts rename to workers/db_service/db/communities.ts diff --git a/src/datasources/db/companies.ts b/workers/db_service/db/companies.ts similarity index 100% rename from src/datasources/db/companies.ts rename to workers/db_service/db/companies.ts diff --git a/src/datasources/db/confirmationToken.ts b/workers/db_service/db/confirmationToken.ts similarity index 100% rename from src/datasources/db/confirmationToken.ts rename to workers/db_service/db/confirmationToken.ts diff --git a/src/datasources/db/events.ts b/workers/db_service/db/events.ts similarity index 100% rename from src/datasources/db/events.ts rename to workers/db_service/db/events.ts diff --git a/src/datasources/db/eventsCommunities.ts b/workers/db_service/db/eventsCommunities.ts similarity index 100% rename from src/datasources/db/eventsCommunities.ts rename to workers/db_service/db/eventsCommunities.ts diff --git a/src/datasources/db/eventsTags.ts b/workers/db_service/db/eventsTags.ts similarity index 100% rename from src/datasources/db/eventsTags.ts rename to workers/db_service/db/eventsTags.ts diff --git a/src/datasources/db/eventsUsers.ts b/workers/db_service/db/eventsUsers.ts similarity index 100% rename from src/datasources/db/eventsUsers.ts rename to workers/db_service/db/eventsUsers.ts diff --git a/src/datasources/db/index.ts b/workers/db_service/db/index.ts similarity index 69% rename from src/datasources/db/index.ts rename to workers/db_service/db/index.ts index d1bc558c..2e1a3198 100644 --- a/src/datasources/db/index.ts +++ b/workers/db_service/db/index.ts @@ -1,35 +1,32 @@ import { ExtractTablesWithRelations } from "drizzle-orm"; +import { PgTransaction } from "drizzle-orm/pg-core"; import { - NodePgDatabase, - NodePgQueryResultHKT, + PostgresJsDatabase, + PostgresJsQueryResultHKT, drizzle, -} from "drizzle-orm/node-postgres"; -import { PgTransaction } from "drizzle-orm/pg-core"; -import { Client } from "pg"; +} from "drizzle-orm/postgres-js"; import { Logger } from "pino"; +import postgres from "postgres"; import * as schema from "./schema"; -export type ORM_TYPE = NodePgDatabase; +export type ORM_TYPE = PostgresJsDatabase; export type TRANSACTION_HANDLER = PgTransaction< - NodePgQueryResultHKT, + PostgresJsQueryResultHKT, typeof schema, ExtractTablesWithRelations >; -export const getDb = async ({ +export const getDb = ({ neonUrl, logger, }: { neonUrl: string; logger: Logger; }) => { - const client = new Client({ - connectionString: neonUrl, - }); + const client = postgres(neonUrl); try { - await client.connect(); const db = drizzle(client, { schema, // logger: { diff --git a/src/datasources/db/paymentLogs.ts b/workers/db_service/db/paymentLogs.ts similarity index 100% rename from src/datasources/db/paymentLogs.ts rename to workers/db_service/db/paymentLogs.ts diff --git a/src/datasources/db/prices.ts b/workers/db_service/db/prices.ts similarity index 100% rename from src/datasources/db/prices.ts rename to workers/db_service/db/prices.ts diff --git a/src/datasources/db/purchaseOrders.ts b/workers/db_service/db/purchaseOrders.ts similarity index 100% rename from src/datasources/db/purchaseOrders.ts rename to workers/db_service/db/purchaseOrders.ts diff --git a/src/datasources/db/runMigrations.ts b/workers/db_service/db/runMigrations.ts similarity index 100% rename from src/datasources/db/runMigrations.ts rename to workers/db_service/db/runMigrations.ts diff --git a/src/datasources/db/salaries.ts b/workers/db_service/db/salaries.ts similarity index 100% rename from src/datasources/db/salaries.ts rename to workers/db_service/db/salaries.ts diff --git a/src/datasources/db/schedule.ts b/workers/db_service/db/schedule.ts similarity index 100% rename from src/datasources/db/schedule.ts rename to workers/db_service/db/schedule.ts diff --git a/workers/db_service/db/schema.ts b/workers/db_service/db/schema.ts new file mode 100644 index 00000000..9398106b --- /dev/null +++ b/workers/db_service/db/schema.ts @@ -0,0 +1,31 @@ +// TABLES/RELATIONS/CRUD +export * from "./allowedCurrencies"; +export * from "./communities"; +export * from "./companies"; +export * from "./confirmationToken"; +export * from "./events"; +export * from "./eventsCommunities"; +export * from "./eventsTags"; +export * from "./eventsUsers"; +export * from "./paymentLogs"; +export * from "./prices"; +export * from "./purchaseOrders"; +export * from "./salaries"; +export * from "./schedule"; +export * from "./sessions"; +export * from "./sessionsToSpeakers"; +export * from "./speaker"; +export * from "./tags"; +export * from "./tagsCommunities"; +export * from "./teams"; +export * from "./ticketPrice"; +export * from "./tickets"; +export * from "./users"; +export * from "./usersCommunities"; +export * from "./usersTags"; +export * from "./userTeams"; +export * from "./userTickets"; +export * from "./workEmail"; +export * from "./workRole"; +export * from "./workSeniority"; +export * from "./workSeniorityAndRole"; diff --git a/src/datasources/db/sessions.ts b/workers/db_service/db/sessions.ts similarity index 100% rename from src/datasources/db/sessions.ts rename to workers/db_service/db/sessions.ts diff --git a/src/datasources/db/sessionsToSpeakers.ts b/workers/db_service/db/sessionsToSpeakers.ts similarity index 100% rename from src/datasources/db/sessionsToSpeakers.ts rename to workers/db_service/db/sessionsToSpeakers.ts diff --git a/src/datasources/db/shared.ts b/workers/db_service/db/shared.ts similarity index 100% rename from src/datasources/db/shared.ts rename to workers/db_service/db/shared.ts diff --git a/src/datasources/db/speaker.ts b/workers/db_service/db/speaker.ts similarity index 100% rename from src/datasources/db/speaker.ts rename to workers/db_service/db/speaker.ts diff --git a/src/datasources/db/tags.ts b/workers/db_service/db/tags.ts similarity index 100% rename from src/datasources/db/tags.ts rename to workers/db_service/db/tags.ts diff --git a/src/datasources/db/tagsCommunities.ts b/workers/db_service/db/tagsCommunities.ts similarity index 100% rename from src/datasources/db/tagsCommunities.ts rename to workers/db_service/db/tagsCommunities.ts diff --git a/src/datasources/db/teams.ts b/workers/db_service/db/teams.ts similarity index 100% rename from src/datasources/db/teams.ts rename to workers/db_service/db/teams.ts diff --git a/src/datasources/db/ticketPrice.ts b/workers/db_service/db/ticketPrice.ts similarity index 100% rename from src/datasources/db/ticketPrice.ts rename to workers/db_service/db/ticketPrice.ts diff --git a/src/datasources/db/tickets.ts b/workers/db_service/db/tickets.ts similarity index 100% rename from src/datasources/db/tickets.ts rename to workers/db_service/db/tickets.ts diff --git a/src/datasources/db/userTeams.ts b/workers/db_service/db/userTeams.ts similarity index 100% rename from src/datasources/db/userTeams.ts rename to workers/db_service/db/userTeams.ts diff --git a/src/datasources/db/userTickets.ts b/workers/db_service/db/userTickets.ts similarity index 100% rename from src/datasources/db/userTickets.ts rename to workers/db_service/db/userTickets.ts diff --git a/src/datasources/db/users.ts b/workers/db_service/db/users.ts similarity index 100% rename from src/datasources/db/users.ts rename to workers/db_service/db/users.ts diff --git a/src/datasources/db/usersCommunities.ts b/workers/db_service/db/usersCommunities.ts similarity index 100% rename from src/datasources/db/usersCommunities.ts rename to workers/db_service/db/usersCommunities.ts diff --git a/src/datasources/db/usersTags.ts b/workers/db_service/db/usersTags.ts similarity index 100% rename from src/datasources/db/usersTags.ts rename to workers/db_service/db/usersTags.ts diff --git a/src/datasources/db/workEmail.ts b/workers/db_service/db/workEmail.ts similarity index 100% rename from src/datasources/db/workEmail.ts rename to workers/db_service/db/workEmail.ts diff --git a/src/datasources/db/workRole.ts b/workers/db_service/db/workRole.ts similarity index 100% rename from src/datasources/db/workRole.ts rename to workers/db_service/db/workRole.ts diff --git a/src/datasources/db/workSeniority.ts b/workers/db_service/db/workSeniority.ts similarity index 100% rename from src/datasources/db/workSeniority.ts rename to workers/db_service/db/workSeniority.ts diff --git a/src/datasources/db/workSeniorityAndRole.ts b/workers/db_service/db/workSeniorityAndRole.ts similarity index 100% rename from src/datasources/db/workSeniorityAndRole.ts rename to workers/db_service/db/workSeniorityAndRole.ts diff --git a/workers/db_service/env.ts b/workers/db_service/env.ts new file mode 100644 index 00000000..29c8434e --- /dev/null +++ b/workers/db_service/env.ts @@ -0,0 +1,7 @@ +// variables en este archivo como: +// _APP_ENV, _COOKIE_NAME, son "variables" de entorno que se setean en el wrangler.toml +// A diferencia de las variables que se setean bajo el key [vars] (o [env.production.vars] / [env.staging.vars] ) +// esta variable va a ser reemplazada por un string al momento de hacer build (build-time) +// Esto es útil para permitir al compiler, realizar ead-code-elimination en distintos environments. + +export const APP_ENV = _APP_ENV; diff --git a/workers/db_service/index.ts b/workers/db_service/index.ts new file mode 100644 index 00000000..37f02d4b --- /dev/null +++ b/workers/db_service/index.ts @@ -0,0 +1,52 @@ +import { RpcTarget, WorkerEntrypoint } from "cloudflare:workers"; + +import { createLogger } from "~/logging"; +import { getDb, ORM_TYPE } from "~workers/db_service/db"; +import { APP_ENV } from "~workers/db_service/env"; +import { ENV } from "~workers/db_service/types"; + +export default class DBService extends WorkerEntrypoint { + logger = createLogger("DBService"); + NEON_URL = ""; + + DB: ORM_TYPE | null = null; + + constructor(ctx: ExecutionContext, env: ENV) { + super(ctx, env); + const { NEON_URL, HYPERDRIVE } = env; + + if (!NEON_URL) { + throw new Error("NEON_URL is required"); + } + + if (!HYPERDRIVE) { + throw new Error("HYPERDRIVE is required"); + } + + const DB_URL = + HYPERDRIVE.connectionString.startsWith("postgresql://fake-user:fake") && + APP_ENV === "development" + ? NEON_URL + : HYPERDRIVE.connectionString; + + this.DB = getDb({ + neonUrl: DB_URL, + logger: this.logger, + }); + } + + fetch() { + return new Response("ok"); + } + + getConnection(): ORM_TYPE { + if (!this.DB) { + this.DB = getDb({ + neonUrl: this.env.NEON_URL, + logger: this.logger, + }); + } + + return this.DB; + } +} diff --git a/workers/db_service/types.ts b/workers/db_service/types.ts new file mode 100644 index 00000000..6eab65ee --- /dev/null +++ b/workers/db_service/types.ts @@ -0,0 +1,4 @@ +export type ENV = { + NEON_URL: string; + HYPERDRIVE: Hyperdrive; +}; diff --git a/workers/db_service/wrangler.toml b/workers/db_service/wrangler.toml new file mode 100644 index 00000000..8b4d200a --- /dev/null +++ b/workers/db_service/wrangler.toml @@ -0,0 +1,34 @@ +# 🚨 DEFAULT CONFIG 🚨 +name = "db-service" +main = "./index.ts" +node_compat = true +compatibility_date = "2024-07-12" +upload_source_maps = true + +[dev] +port = 50124 + +[define] +_APP_ENV = "'development'" + +[[hyperdrive]] +binding = "HYPERDRIVE" +id = "f0bc5f4533eb4557976b7d0b59d880ad" +localConnectionString="postgresql://fake-user:fake-pasword@fake:5432/fake-db" + + +[env.production.define] +_APP_ENV = "'production'" + +[[env.production.hyperdrive]] +binding = "HYPERDRIVE" +id = "faa163999e9f40c6a26b3612940bc5ba" + + +[env.staging.define] +_APP_ENV = "'staging'" + +[[env.staging.hyperdrive]] +binding = "HYPERDRIVE" +id = "c693e76575c64a8eab15032d97ab938f" + diff --git a/workers/purchase_order_payment_sync_cron/scheduled.tsx b/workers/purchase_order_payment_sync_cron/scheduled.tsx index 6a92a35e..4316c1f6 100644 --- a/workers/purchase_order_payment_sync_cron/scheduled.tsx +++ b/workers/purchase_order_payment_sync_cron/scheduled.tsx @@ -1,4 +1,4 @@ -import { getDb } from "~/datasources/db"; +import { getDb } from "~workers/db_service/db"; import { getMercadoPagoFetch } from "~/datasources/mercadopago"; import { getStripeClient } from "~/datasources/stripe/client"; import { createLogger } from "~/logging"; diff --git a/workers/sanity_asset_importer/importSanity.ts b/workers/sanity_asset_importer/importSanity.ts index dda80589..ff98d208 100644 --- a/workers/sanity_asset_importer/importSanity.ts +++ b/workers/sanity_asset_importer/importSanity.ts @@ -1,8 +1,8 @@ import { Logger } from "pino"; -import { getDb } from "~/datasources/db"; -import { eventsSchema } from "~/datasources/db/events"; -import { eventsToCommunitiesSchema } from "~/datasources/db/eventsCommunities"; +import { getDb } from "~workers/db_service/db"; +import { eventsSchema } from "~workers/db_service/events"; +import { eventsToCommunitiesSchema } from "~workers/db_service/eventsCommunities"; import { getSanityClient } from "~/datasources/sanity/client"; import { SanityEvent } from "~/datasources/sanity/types"; diff --git a/workers/transactional_email_service/index.tsx b/workers/transactional_email_service/index.tsx index bebf3b51..953ecb0e 100644 --- a/workers/transactional_email_service/index.tsx +++ b/workers/transactional_email_service/index.tsx @@ -5,12 +5,10 @@ import { Resend } from "resend"; import { sendTransactionalHTMLEmail } from "~/datasources/email/sendTransactionalHTMLEmail"; import { createLogger } from "~/logging"; +import { ENV } from "~workers/transactional_email_service/types"; import { PurchaseOrderSuccessful } from "../../emails/templates/tickets/purchase-order-successful"; -type ENV = { - RESEND_API_KEY: string | undefined; -}; export default class EmailService extends WorkerEntrypoint { logger = createLogger("EmailService"); diff --git a/workers/transactional_email_service/types.ts b/workers/transactional_email_service/types.ts index 9ab18782..d8a19a8a 100644 --- a/workers/transactional_email_service/types.ts +++ b/workers/transactional_email_service/types.ts @@ -1,8 +1,3 @@ export type ENV = { - NEON_URL: string; - HIGHLIGHT_PROJECT_ID: string; - MP_ACCESS_TOKEN: string; - MP_PUBLIC_KEY: string; - ST_KEY: string; - RV_KEY: string; + RESEND_API_KEY: string | undefined; }; diff --git a/workers/wall_of_fame_cron/api.mercadopago.ts b/workers/wall_of_fame_cron/api.mercadopago.ts index 9ce93a94..83efe92b 100644 --- a/workers/wall_of_fame_cron/api.mercadopago.ts +++ b/workers/wall_of_fame_cron/api.mercadopago.ts @@ -1,6 +1,6 @@ import { Logger } from "pino"; -import { ORM_TYPE, getDb } from "~/datasources/db"; +import { ORM_TYPE, getDb } from "~workers/db_service/db"; import { insertUsersToTagsSchema, insertTagsSchema, @@ -9,7 +9,7 @@ import { AllowedUserTags, insertPaymentLogsSchema, paymentLogsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { sanitizeForLikeSearch } from "~/schema/shared/helpers"; import { ENV } from "./types"; diff --git a/workers/wall_of_fame_cron/api.stripe.ts b/workers/wall_of_fame_cron/api.stripe.ts index 1172630b..5907fbe8 100644 --- a/workers/wall_of_fame_cron/api.stripe.ts +++ b/workers/wall_of_fame_cron/api.stripe.ts @@ -1,10 +1,10 @@ import Stripe from "stripe"; -import { ORM_TYPE, getDb } from "~/datasources/db"; +import { ORM_TYPE, getDb } from "~workers/db_service/db"; import { insertPaymentLogsSchema, paymentLogsSchema, -} from "~/datasources/db/schema"; +} from "~workers/db_service/db/schema"; import { defaultLogger } from "~/logging"; import { ENV } from "./types"; diff --git a/wrangler.toml b/wrangler.toml index f6533ec1..6b206701 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -2,7 +2,7 @@ name = "graphql-api" compatibility_date = "2024-06-03" main = "src/index.ts" -node_compat = true +compatibility_flags = ["nodejs_compat"] [dev] port = 50123 @@ -11,6 +11,11 @@ port = 50123 binding = "RPC_SERVICE_EMAIL" service = "transactional-email-service" +[[services]] +binding = "RPC_SERVICE_DB" +service = "db-service" + + [vars] GRAPHQL_BASE_ENDPOINT = "/" @@ -28,11 +33,6 @@ binding = "MAIL_QUEUE" queue = "google-photos-import-queue-dev" binding = "GOOGLE_PHOTOS_IMPORT_QUEUE" -[[hyperdrive]] -binding = "HYPERDRIVE" -id = "f0bc5f4533eb4557976b7d0b59d880ad" -localConnectionString="postgresql://fake-user:fake-pasword@fake:5432/fake-db" - # ===================================== # ===================================== # 🚨 PRODUCTION CONFIG 🚨 @@ -46,6 +46,11 @@ logpush = true binding = "RPC_SERVICE_EMAIL" service = "transactional-email-service" +[[env.production.services]] +binding = "RPC_SERVICE_DB" +service = "db-service-prod" + + [env.production.vars] GRAPHQL_BASE_ENDPOINT = "/" @@ -63,9 +68,7 @@ binding = "MAIL_QUEUE" queue = "google-photos-import-queue-production" binding = "GOOGLE_PHOTOS_IMPORT_QUEUE" -[[env.production.hyperdrive]] -binding = "HYPERDRIVE" -id = "faa163999e9f40c6a26b3612940bc5ba" + # ===================================== @@ -81,6 +84,10 @@ logpush = true binding = "RPC_SERVICE_EMAIL" service = "transactional-email-service" +[[env.staging.services]] +binding = "RPC_SERVICE_DB" +service = "db-service-prod-staging" + [env.staging.vars] GRAPHQL_BASE_ENDPOINT = "/" @@ -97,7 +104,3 @@ binding = "MAIL_QUEUE" [[env.staging.queues.producers]] queue = "google-photos-import-queue-staging" binding = "GOOGLE_PHOTOS_IMPORT_QUEUE" - -[[env.staging.hyperdrive]] -binding = "HYPERDRIVE" -id = "c693e76575c64a8eab15032d97ab938f"