Hi :wave: I'm running into some issues with migra...
# sst
g
Hi 👋 I'm running into some issues with migrations, I'm receiving the following error:
Copy code
e8a5a024-b37d-4ce6-b85e-d0d7ee454267 REQUEST dev-dolartec-app-db-DatabaseMigrationFunction9CBE9-qOutRhPjrpC9 [index.handler] invoked
(node:19518) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
e8a5a024-b37d-4ce6-b85e-d0d7ee454267 ERROR Runtime.UnhandledPromiseRejection: Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module
t
Can you name the migrations .mjs
g
yes it is named
20220610210900_cleanup.mjs
Copy code
e8d7e450-ef09-41a4-9ca9-85d74941bd38 RESPONSE {"results":[{"migrationName":"20220610210900_cleanup","direction":"Up","status":"Success"}]}
505e446a-7f0b-44f7-b389-135ff932f5b0 RESPONSE [{"name":"20220610210900_cleanup","migration":{},"executedAt":"2022-06-11T19:01:56.582Z"}]

BadRequestException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'schemas AS (
        SELECT nspname AS name, oid AS oid
        FROM pg_namespac' at line 1; Error code: 1064; SQLState: 42000
    at Object.extractError (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.extractError (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/protocol/rest_json.js:49:8)
    at Request.callListeners (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/request.js:686:14)
    at Request.transition (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/request.js:688:12)
    at Request.callListeners (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
    at Request.emit (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/request.js:686:14)
    at Request.transition (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/giorgioleveroni/Projects/dolartec/node_modules/.pnpm/aws-sdk@2.1152.0/node_modules/aws-sdk/lib/state_machine.js:26:10
additionally I think SST with
pnpm
requires me to explicitly add a few more packages in order to run:
aws-sdk
,
kysely
,
kysely-data-api
,
@serverless-stack/core
Even after adding those dependencies I get the stack trace mentioned above ^
t
That looks like a postgres query to MySQL hm
g
(I wonder if I'm making progress compared to
UserCodeSyntaxError
error before or if I'm following a red herring)
t
You are making progress
g
yes that's true, I'm creating an sst.RDS resource with a mysql engine
have migrations only been tested with postgres?
(I'm switching to yarn for a bit to see if it works)
t
I haven't tried it myself so not sure if we forgot something
g
I switched to yarn and I get the same stack trace of
You have an error in your SQL syntax
, and I'm running it on a migration file with empty
up
and
down
functions.
also, in my case I have to add
"type": "module",
inside the root
package.json
in addition to the one in the
backend
folder which isn't included in the template
okay I confirmed that this doesn't happen when the engine is set to
postgresql10.14
at this point I really have no idea what code is making that call, I console.log'ed kysely-data-api and it is instantiating the mysql dialect as expected, I even removed the extra references to postgres including in the kysely library and somehow that query still gets called 🤯
ohh I finally found the culprit, it is actually the type generator from adding
types: "backend/sql.generated.ts",
@thdxr ^
t
Ahh
It's the type generation
Will fix
g
I'm now having issues having the migrations run successfully with
sst deploy --stage prod
. It might be because of pnpm again, I'm running them with yarn now and see how it goes:
Copy code
'../.pnpm/@serverless-stack+resources@1.2.20/@serverless-stack/resources/dist/RDS_migrator/index.handler' is not a valid handler name. Use absolute paths when specifying root directories in handler names.
yup, migrations works with yarn
t
There's certain patterns we have that don't work right we pnpm and we haven't gone down and fixed everything
g
I see, in addition for
sst deploy
I realized that it doesn't work with a different directory layout where the lambdas are outside the SST directory. I have the following layout: . infrastructure/ (SST) lambdas/ (all the backend logic) frontend/ (Expo) api/ (GraphQL schema + generated .ts typedef file) common/ logic shared between frontend and lambdas (mainly validations so frontend can also use it in the forms) so in
infrastructure/index.ts
I'd then define
srcPath: '../lambdas'
but I'm hit with an error similar to the one previously mentioned. Might be because ESM is more strict on these things? I'm not sure. I ended up moving
lambdas
to
infrastructure/backend
.
t
SST.json needs to be in the root
And paths must be specified from the root
So srcPath should be ./`lambdas`
fixed your mysql issue in the latest release