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

Turso -schema DBs don't work with Goose migrations #1383

Open
JordanMartinWebDev opened this issue May 10, 2024 · 6 comments
Open

Turso -schema DBs don't work with Goose migrations #1383

JordanMartinWebDev opened this issue May 10, 2024 · 6 comments

Comments

@JordanMartinWebDev
Copy link

Description

When attempting to migrate a Turso schema database with Goose, the following error occurs:
2024/05/10 11:47:00 goose run: failed to execute SQL: BEGIN
error code 500: Internal Error: migration error: Connection left in transaction state

From talking to Turso maintainer @avinassh in the Discord, this fails because Goose attempts to run migrations in a transaction, which the Turso schema DBs do not accept. I then attempted to migrate without Goose transactions as documented here:
https://pressly.github.io/goose/blog/2022/overview-sql-file/#migrations-outside-transaction

This returns with the same error as before.

Suspected Problem:

Goose keeps track of migrations in a migrations table inside of a DB. It's believed that this table creation and insertion is likely running within a transaction and it causing this problem.

Link to troubleshooting Discord Thread: https://discord.com/channels/933071162680958986/1229116060859502716

@haaawk
Copy link
Contributor

haaawk commented May 10, 2024

This is sort of expected. Turso multi database schema migrations are asynchronous. User has to call special API to wait for the migration to finish. I doubt Goose does that.

@JordanMartinWebDev
Copy link
Author

I'm not sure of all the inner workings of Turso, but from 1000 foot view I would think this should work.

If the schema db is just a db that children propagate their schema from (and Goose is sending a non-transactional query), it should update that parent db and return successful. Then the propagation should happen from the schema db to the children asynchronously without Goose being involved at all.

I think the problem here is that Goose also has a side effect of sending transactional queries for their migration table, which from talking to avinassh the schema dbs don't support.

I could be very wrong here though.

@haaawk
Copy link
Contributor

haaawk commented May 11, 2024

That's not the way it works. The call registers update tasks for all databases and then returns. The parent db is updated last.

I don't think this is a transaction issue. We wrap the schema change into a transaction anyway so this non-transactional query Goose produces ends up being one big transaction anyway.

@avinassh
Copy link
Member

I am the cause for the confusion. I forgot about transactions being run async for migrations and I guessing it could be due to Goose editing migration table

@JordanMartinWebDev
Copy link
Author

Sounds like where we have landed is this should be a feature request for Goose and not for libsql.

@haaawk
Copy link
Contributor

haaawk commented May 11, 2024

Possibly yes but let us see if we can fix it on our side.

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