Odonno / surrealdb-migrations

An awesome SurrealDB migration tool, with a user-friendly CLI and a versatile Rust library that enables seamless integration into any project.
https://crates.io/crates/surrealdb-migrations
MIT License
210 stars 16 forks source link

Error in down migration: `Specify some SQL code to execute` #40

Closed unidesigner closed 1 year ago

unidesigner commented 1 year ago

I followed the readme very closely however I run into the issue that my call to down migrate to 0 fails:

surrealdb-migrations apply --down 0   --address ws://localhost:8000 --ns myns --db mydb --username root --password root

with

Error: Specify some SQL code to execute

I have specified valid SQL code in all of the schema, (down)migration. The interesting thing is that down migration works with the blog example. So I tried to add a new migration AddPost, and copied the content of the blog example (20230628_155502_AddPost.surql) to my migration files, as well as the schema.

image

Do you have any idea of what I could be doing wrong, and how to debug this further? Thanks!

Odonno commented 1 year ago

Hi Stephan

This error seems to happen when your migration file is empty, see https://github.com/surrealdb/surrealdb/blob/main/lib/src/err/mod.rs#L78

Can you share a reproducible example so I can see what is wrong.

If your .surql file is indeed empty, you can safely remove it and the error should go away.

unidesigner commented 1 year ago

Hi David

The migration are not empty, so there must be another reason. Here is the folder with the files.

term2.tar.gz

With the following code

$ surrealdb-migrations apply --address ws://localhost:8000 --ns test --db term2 --username root --password root 
Executing migration AddPost...
Schema files successfully executed!
Migration files successfully executed!
$ surrealdb-migrations apply --down 0 --address ws://localhost:8000 --ns test --db term2 --username root --password root 
Error: Specify some SQL code to execute

using

surrealdb-migrations 0.9.10
surreal: 1.0.0-beta.9+20230402.5eafebd for linux on x86_64

Thanks for help!

Odonno commented 1 year ago

Ok, this is my mistake. BTW, thanks for sharing this reproducible example!

When applying revert (on rollback migrations), I parse the schemas and events statements to detect the difference between them in order to correctly rollback to the previous database schema. However, parsing empty string (without any statement) fails miserably. When you have a migration project without event, it then fails for this reason.

I am now releasing the v0.9.11 which will fix this error.

Thank you for reporting this error.

unidesigner commented 1 year ago

This works now! Thanks a lot for the quick response, fix and this useful tool. I hope you will continue developing it.