Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration error #1321

Closed
kelbyfaessler opened this issue Apr 17, 2024 · 7 comments
Closed

migration error #1321

kelbyfaessler opened this issue Apr 17, 2024 · 7 comments

Comments

@kelbyfaessler
Copy link

Using Turso with drizzle + sveltekit. Sveltekit has import aliases like $env, $lib and for that reason, I run scripts using vite-node so imports resolve.

I created a migration and am attempting to migrate using drizzles migrate() function. Here is the libsql/hrana error.

> vite-node --options.transformMode.ssr='/.*/' src/lib/server/migrate.ts

Running migrations...
<project>/node_modules/@libsql/client/lib-esm/hrana.js:264
        return new __vite_ssr_import_1__.LibsqlError(e.message, code, undefined, e);
               ^

LibsqlError: SQL_PARSE_ERROR: SQL string could not be parsed: near LP, "None": syntax error at (5, 37)
    at mapHranaError (<project>/node_modules/@libsql/client/lib-esm/hrana.js:257:16)
    at HttpTransaction.batch (<project>/node_modules/@libsql/client/lib-esm/hrana.js:105:19)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at <project>/node_modules/src/sqlite-core/dialect.ts:799:7
    at LibSQLSession.transaction (<project>/node_modules/src/libsql/session.ts:86:19)
    at SQLiteAsyncDialect.migrate (<project>/node_modules/src/sqlite-core/dialect.ts:795:3)
    at <project>/src/lib/server/migrate.ts:8:1
    at ViteNodeRunner.directRequest (file://<project>/node_modules/vite-node/dist/client.mjs:328:5)
    at ViteNodeRunner.cachedRequest (file://<project>/node_modules/vite-node/dist/client.mjs:186:14)
    at ViteNodeRunner.executeFile (file://<project>/node_modules/vite-node/dist/client.mjs:154:12) {
  code: 'SQL_PARSE_ERROR',
  rawCode: undefined,
  [cause]: [ResponseError: SQL string could not be parsed: near LP, "None": syntax error at (5, 37)] {
    code: 'SQL_PARSE_ERROR',
    proto: {
      message: 'SQL string could not be parsed: near LP, "None": syntax error at (5, 37)',
      code: 'SQL_PARSE_ERROR'
    }
  }
}

Node.js v18.19.1

@haaawk
Copy link
Contributor

haaawk commented Apr 18, 2024

Thank you for bringing up the issue @kelbyfaessler . Would you have a code / SQL that reproduces the issue?

@kelbyfaessler
Copy link
Author

kelbyfaessler commented Apr 19, 2024

I played around with the generated SQL and figured out the issue.

The issue is in this part of a table definition

CREATE TABLE `mytable` (
    ...
    `created_at` text DEFAULT strftime('%Y-%m-%dT%H:%M:%fZ', 'now') NOT NULL,
    ...
);

If I put parens around the strftime call, then it works

`created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) NOT NULL,

@kelbyfaessler
Copy link
Author

closing the issue since its a drizzle issue with their generated sql

@AndriiSherman
Copy link

@kelbyfaessler сan you show the drizzle schema you are using?

@kelbyfaessler
Copy link
Author

@AndriiSherman the line in the schema looks like this:

    createdAt: text("created_at").notNull().default(sql`strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`),

which means its not a drizzle issue and rather issue with my own code, right? Since I could insert the parens like so

    createdAt: text("created_at").notNull().default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`),

@haaawk
Copy link
Contributor

haaawk commented Apr 20, 2024

According to my understanding you're right @kelbyfaessler. This is an issue with the code not drizzle itself but @AndriiSherman will know better.

@AndriiSherman
Copy link

Author

Yes, so the case here is that if you are using the sql template in the drizzle schema, we can't know exactly what is there because it can be basically anything. It's done to not block you from using anything you need while we are implementing first-class support for a specific feature. So it means anything that is in the sql template will be added after the default as-is, so it is your responsibility to put the right code there, same as you would put in raw sql DDL statement after DEFAULT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants