erikash
erikash
Explore posts from servers
TTCTheo's Typesafe Cult
Created by erikash on 1/12/2024 in #questions
`tsx ./src/server/db/SCRIPT_NAME` doesn't recognize environment variables.
I created a db migrator script similar to the recommendations here: https://create.t3.gg/en/usage/prisma/#seeding-your-database I'm trying to execute a script and the t3-env doesn't seem to load the .env file. src/server/db/migrator.ts is:
import { migrate } from "drizzle-orm/neon-http/migrator";
import { db } from "~/server/db/index";

await migrate(db, { migrationsFolder: "src/server/db/drizzle" });
import { migrate } from "drizzle-orm/neon-http/migrator";
import { db } from "~/server/db/index";

await migrate(db, { migrationsFolder: "src/server/db/drizzle" });
package.json scripts are:
"scripts": {
...
"migrate": "tsx ./src/server/db/migrator.ts"
},
"scripts": {
...
"migrate": "tsx ./src/server/db/migrator.ts"
},
When running pnpm run migrate I'm getting:
❌ Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
DISCORD_CLIENT_ID: [ 'Required' ],
DISCORD_CLIENT_SECRET: [ 'Required' ]
}
/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/core/index.ts:217
throw new Error("Invalid environment variables");
^


Error: Invalid environment variables
at error (/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/core/index.ts:217:13)
at b (/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/core/index.ts:229:12)
at P (/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/env-nextjs/index.ts:73:10)
at file:///Users/erikashepa/Projects/budget/src/env.js:4:20
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.17.1
❌ Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
DISCORD_CLIENT_ID: [ 'Required' ],
DISCORD_CLIENT_SECRET: [ 'Required' ]
}
/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/core/index.ts:217
throw new Error("Invalid environment variables");
^


Error: Invalid environment variables
at error (/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/core/index.ts:217:13)
at b (/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/core/index.ts:229:12)
at P (/Users/erikashepa/Projects/budget/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@t3-oss/env-nextjs/index.ts:73:10)
at file:///Users/erikashepa/Projects/budget/src/env.js:4:20
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.17.1
Erik.
3 replies
DTDrizzle Team
Created by erikash on 12/7/2023 in #help
What is the best way to join with JSONB arrays with Drizzle?
Hi guys, I'm trying to migrate the following query to Drizzle: SELECT "mutzar"."misparzihuylakoach", "mutzar"."sugmutzar", "mutzar"."shemyatzran", "heshbonopolisas" ->> 'MISPAR_POLISA_O_HESHBON' FROM "mutzar" LEFT JOIN Jsonb_array_elements("data" -> 'HeshbonotOPolisot' -> 'HeshbonOPolisa' ) AS "heshbonOPolisas" ON TRUE WHERE "mutzar"."misparzihuylakoach" = $1 -- params: ["123123123"] I've successfully migrated it to: const result = await db .select({ misparZihuyLakoach: mutzar.misparZihuyLakoach, sugMutzar: mutzar.sugMutzar, shemYatzran: mutzar.shemYatzran, misparPolisaOHeshbon: sql"heshbonOPolisas" ->> 'MISPAR_POLISA_O_HESHBON', }) .from(mutzar) .leftJoin( sqljsonb_array_elements("data"->'HeshbonotOPolisot'->'HeshbonOPolisa') as "heshbonOPolisas", eq(sqlTRUE, sqlTRUE) ) .where(eq(mutzar.misparZihuyLakoach, '123123123')); I've tried following the docs and using const heshbonOPolisas = alias(sqljsonb_array_elements("data"->'HeshbonotOPolisot'->'HeshbonOPolisa'), "heshbonOPolisa") but got a type error What is the best way to join with JSONB arrays with Drizzle?
1 replies