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

Strict mode apparently unsupported #55

Closed turbohz closed 9 months ago

turbohz commented 11 months ago

Describe the bug

The tool does not work when running a SurrealDB instance with SURREAL_STRICT=true.

To Reproduce

  1. Start SurrealDB with SURREAL_STRICT=true.
  2. surrealdb-migrations scaffold template empty
  3. surrealdb-migrations apply

Initially, you’ll get:

Error: There was a problem with the database: The namespace 'test' does not exist

If you create the namespace and database already defined in the config file, then you get:

Error: There was a problem with the database: The table 'script_migration' does not exist

Expected behavior

Successful creation of the script_migration table.

Perhaps, even, the namespace and database specified in the configuration file (debatable).

Information

turbohz commented 11 months ago

This mode is still not well documented, here's an explanation:

https://surrealdb.com/docs/cli/start

SurrealDB supports the ability to startup in strict mode. When running in strict mode, all NAMESPACE, DATABASE, and TABLE definitions will not be created automatically when data is inserted. Instead, if the selected namespace, database, or table has not been specifically defined, then the query will return an error.

user@localhost % surreal start --strict --log debug memory

Odonno commented 11 months ago

Hi @turbohz

Thank you for your feedback. I can indeed reproduce this error.

This error is happening because in order to apply migrations, we have first to detect the already applied migrations. Hence the table must be created or it returns [] when the table does not exist. But in strict mode, it seems you cannot query something that does not exist.

The simple fix would be to detect the absence of this table using INFO FOR DB;. If the table does not exist, we can skip retrieving the list of migrations.

turbohz commented 11 months ago

Cool. I might try to implement a fix.

Odonno commented 11 months ago

Here is some tasks to get you on track:

Good luck!