`runMigrations.ts` not found
Closed this issue ยท 11 comments
Hello!
I'm trying to get started with this project but pnpm run dev
fails due to the absence of runMigrations.ts
.
I can create my own but was wondering whether your missing version had any specific logic?
Discussed in #47
Originally posted by toddjudd May 1, 2023
Hey! Awesome template.
I'm trying to use some of this applying it to an app bootstrapped with create-t3-app. I'm struggling to understand the prisma sst setup though. I've pulled over the network, layer, database, and databaseMigrations stacks. but I'm failing to understand migration stack. the migrationFunction
constructor references a src/repo/runMigrations.handler
which doesn't exist. Is this file generated, or should it be created in advance? What's it's purpose?
const migrationFunction = new Function(this, 'MigrationScriptLambda', {
vpc,
enableLiveDev: false,
handler: 'src/repo/runMigrations.handler',
layers: [migrationLayer],
copyFiles: [
{ from: 'prisma/schema.prisma' },
{ from: 'prisma/migrations' },
{ from: 'prisma/schema.prisma', to: 'src/repo/schema.prisma' },
{ from: 'prisma/migrations', to: 'src/repo/migrations' },
{ from: 'package.json', to: 'src/package.json' },
],
nodejs: {
format: 'cjs',
esbuild: { external: [...(migrationLayer.externalModules || [])] },
},
timeout: '3 minutes',
environment: {
DB_SECRET_ARN: dbSecretsArn,
},
});
```</div>
It's here https://github.com/jetbridge/sst-prisma/blob/master/backend/src/db/migrationScript.ts
It automatically runs database migrations during deployment
Thanks! So instead it should read migrationScript.handler
?
Yeah something like that
Ah, so it should reference itself? ie, The file stacks/resources/migrationScript.ts
should contain the line handler: 'stacks/resources/migrationScript.handler',
?
If so, this doesn't appear to work (even after deleting everything and starting again) โ I get:
Error: Failed to build function "stacks/resources/migrationScript.handler"
No loader is configured for ".node" files: node_modules/.pnpm/fsevents@2.3.2/node_modules/fsevents/fsevents.node
node_modules/.pnpm/fsevents@2.3.2/node_modules/fsevents/fsevents.js
13 โ const Native = require("./fsevents.node");
Could not resolve "proxy-agent"
node_modules/.pnpm/sst-aws-cdk@2.62.2-3/node_modules/sst-aws-cdk/lib/api/aws-auth/sdk-provider.js
311 โ const ProxyAgent = require('proxy-agent');
Top-level await is not available in the configured target environment ("node14")
node_modules/.pnpm/sst@2.7.2/node_modules/sst/constructs/AppSyncApi.js
11 โ const { print, buildSchema } = await weakImport("graphql");
Top-level await is not available in the configured target environment ("node14")
node_modules/.pnpm/sst@2.7.2/node_modules/sst/constructs/AppSyncApi.js
12 โ const { mergeTypeDefs } = await weakImport("@graphql-tools/merge");
at file:///personal/development/sst-prisma-test/node_modules/.pnpm/sst@2.7.2/node_modules/sst/constructs/Function.js:202:27
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
seems like your tsconfig is using node14 which doesn't support top-level await which the script uses, that's how i read that
This file doesn't seem right though as it's using chalk which I don't see specified in the layer.
I get the following error when I try to use it :(
Error: Failed to build function "./cdk/resources/migrate.handler"
Could not resolve "@prisma/migrate/dist/Migrate.js"
cdk/resources/migrate.ts
5 โ import { Migrate } from '@prisma/migrate/dist/Migrate.js';
Could not resolve "@prisma/migrate/dist/utils/ensureDatabaseExists"
cdk/resources/migrate.ts
6 โ import { ensureDatabaseExists } from '@prisma/migrate/dist/utils/ensureDatabaseExists';
Could not resolve "@prisma/migrate/dist/utils/printFiles"
cdk/resources/migrate.ts
7 โ import { printFilesFromMigrationIds } from '@prisma/migrate/dist/utils/printFiles';
Trace: Error: Failed to build function "./cdk/resources/migrate.handler"
Could not resolve "@prisma/migrate/dist/Migrate.js"
cdk/resources/migrate.ts
5 โ import { Migrate } from '@prisma/migrate/dist/Migrate.js';
Could not resolve "@prisma/migrate/dist/utils/ensureDatabaseExists"
cdk/resources/migrate.ts
6 โ import { ensureDatabaseExists } from '@prisma/migrate/dist/utils/ensureDatabaseExists';
Could not resolve "@prisma/migrate/dist/utils/printFiles"
cdk/resources/migrate.ts
7 โ import { printFilesFromMigrationIds } from '@prisma/migrate/dist/utils/printFiles';
at file:///home/john/Repositories/mccausland/node_modules/sst/constructs/Function.js:206:27
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at process.<anonymous> (file:///home/john/Repositories/mccausland/node_modules/sst/cli/sst.js:58:17)
at process.emit (node:events:525:35)
at process.emit (node:domain:489:12)
at process._fatalException (node:internal/process/execution:149:25)
at processPromiseRejections (node:internal/process/promises:288:13)
at process.processTicksAndRejections (node:internal/process/task_queues:96:32)
seems like your tsconfig is using node14 which doesn't support top-level await which the script uses, that's how i read that
Thanks for the suggestion, but I'm on Node 18.
I think (like @jmcelreavey) there are some issues with the project.
what is your module setting in your tsconfig.json?
For me it's the default for this jetbridge/sst-prisma
repo: "module": "esnext",
Please try out the new version! It fixes many things. Let me know if you still have issues.