kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
9.82k stars 250 forks source link

Failures during migration do not create errors #1008

Closed Sleepful closed 1 month ago

Sleepful commented 1 month ago

Simple example:

Adding a new column with (col) => col.setNotNull(), to a table that already has rows will fail, because the existing rows will have null values. This is OK.

However, the failure does not create any kind of error, it just fails silently, which makes it difficult to debug.

My migrations are ran with await migrator.migrateToLatest();

koskimas commented 1 month ago

Tried it. Worked for me. Also, we have tests.

Sleepful commented 1 month ago

@koskimas What should the error look like on the terminal?

I am running on Deno with PostgresJS driver, I noticed even failure to connect to DB was not creating an error with a stack trace, it was just terminating the process.

This is without putting try/catch around the code.

I don't see tests that cover this scenario though.

igalklebanov commented 1 month ago

Hey 👋

By design.

const { error, results } = await migrator.migrateToLatest()

if (error) {
 // ...
}

https://kysely.dev/docs/migrations#running-migrations

Sleepful commented 1 month ago

@igalklebanov thank you! I must have missed this bit.

I was just going to comment how the error can be caught inside the migration file itself but not outside.

Got it!

igalklebanov commented 1 month ago

Btw, we have a new CLI in the works. https://github.com/kysely-org/kysely-ctl

Try it out.

koskimas commented 1 month ago

I must have missed this bit.

It's the first thing we mention in the docs. You can also just hover over the function to see the docs.

Screenshot 2024-05-27 at 12 53 34
Sleepful commented 1 month ago

Yeah it's my bad guys, sorry 😅 In part because I was rewriting the code to work well with Deno so I was a little distracted. I want to push a PR for docs with my Deno code soon to make it up to you both.