Error: Can't find meta/_journal.json file when trying to apply migrations in a lambda

I'm trying to apply migration in a lambda locally with running sls invoke local -f db_run_migrations I use serverless framework with the serverless-esbuild plugin to package my lambdas I execute the lambda using the sls invoke local -f db_run_migrationscommand This is my folder structure and lambda handler
8 Replies
pandareaper
pandareaper16mo ago
I'm doing the same thing in my project without issue, play around with fs.existsSync() to make sure the path you are setting is correct, it likely isn't This is what we set as the path to our migrations folders path.join(__dirname, 'drizzle') We copy the migration folder into our lambda bundle as part of our build "postbuild": "cp -r ../../packages/database/drizzle dist",
Amur
AmurOP16mo ago
and what's executin the 'postbuild' script? are you also using the serverless-esbuild plugin? or i assume you are using sst because i'm using serverless framewrok the migrations are definitely not getting included now, so i just have to find out how to include them @pandareaper is the migration folder part of all your lambda's bundle? or just the one that's doing the migration?
pandareaper
pandareaper16mo ago
Just the one thats doing the migration, after the build my dist directory looks like this. main.js is my javascript bundle, using webpack. drizzle is my migration files etc. which are copied into the folder postbuild which yarn runs automatically when I run yarn build
pandareaper
pandareaper16mo ago
I use the CDK and bundle everything in the dist folder as a ZIP Locally I use serverless-offline and just point to the dist/main.js as my handler, so it can work with serverless as well
Amur
AmurOP16mo ago
you bundle everything in the dist folder so you don't package them individually so your main.jsfile will have all the code for all your lambdas if i understand correctly this is how my .build dir look like when i esbuild bundles everything
Amur
AmurOP16mo ago
so then serverless-framework packages them individually ⬇️
Amur
AmurOP16mo ago
ah i think i got it working, i just had to set it up in serverless framework 🤦‍♂️ added the inlclude option to my function
db_run_migrations:
handler: src/core/database/runMigrations.handler
events:
- http:
path: "api/migrations"
method: GET
<<: *cors_config
package:
include:
- src/core/database/migrations/**
db_run_migrations:
handler: src/core/database/runMigrations.handler
events:
- http:
path: "api/migrations"
method: GET
<<: *cors_config
package:
include:
- src/core/database/migrations/**
pandareaper
pandareaper16mo ago
Nice, thats effectively equivalent to my postbuild step where I copy over the migration files 👍
Want results from more Discord servers?
Add your server