bostonsheraff
bostonsheraff
TTCTheo's Typesafe Cult
Created by bostonsheraff on 5/3/2023 in #questions
How do you run a one-off prisma script?
Hello 👋 I'm trying to run a little script to change some stuff in my database. Kind of like a prisma seed or some sort of scripted migrate . I need to be in a JS environment (not just SQL) so I can run some logic, and I also need to import some functions from the rest of my codebase. The issue is the classic "node is bad at importing web stuff" and "typescript needs to be compiled". So I'm trying ts-node but it doesn't solve the importing issues. I've tried many variations of this script in my package.json
"foo": "ts-node --project tsconfig.json --compiler-options {\\\"module\\\":\\\"CommonJS\\\"} src/scripts/test.ts"
"foo": "ts-node --project tsconfig.json --compiler-options {\\\"module\\\":\\\"CommonJS\\\"} src/scripts/test.ts"
which all resulted in many variations of
Error: Cannot find module 'server/db/client'
Error: Cannot find module 'server/db/client'
As you can tell I'm using aliased imports everywhere in my project. But I need to be able to import functions. If not for like the above (that's just the prisma client, which I could instantiate directly within my script), at least so that I don't have to rewrite some of the logic I need that already exists somewhere in the project. I've had this problem many times before and never quite found a good solution for it. It's always involved copy/pasting stuff into .mjs files and stripping the types and that's really ugly. I'm hoping the T3 community has some bright idea.
7 replies