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

Found Back:Lower for field `discreteValue`, but expected a string #86

Closed lylejohnson closed 2 months ago

lylejohnson commented 2 months ago

Describe the bug I'm running a migration which creates several records in an existing table. The migration fails with an error message:

Executing migration AddelectronicSupportTypeRecords...
Error:
   0: The query was not executed due to a failed transaction
      Found ree:pss for field `discreteValue`, with record `electronic_support_type:s0hs33jqh8qv79z3hk6m`, but expected a string

Location:
   /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/surrealdb-migrations-1.5.0/src/surrealdb.rs:185

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

To Reproduce

I'll try to put together a small dataset to reproduce it with.

Expected behavior I expected the migration to run without errors. I don't understand what's special about a string field value like "Back:Lower" or "ree:pss" when creating records.

Information Please complete the following information and remove the unnecessary ones.

Additional context Add any other context about the problem here.

lylejohnson commented 2 months ago

Actually, looks like I can't create it in Surrealist.app either, so it's something special and fun about SurrealDB.

CREATE electronic_support_type CONTENT { discreteValue: "lm:arf" };

yields the error message:

Found lm:arf for field `discreteValue`, with record `electronic_support:...`, but expected a string
Odonno commented 2 months ago

It appears to be seen as a record id. You can add a suffix for it to always be seen a string, like this:

CREATE electronic_support_type CONTENT { discreteValue: s"lm:arf" };

Or simply cast it:

CREATE electronic_support_type CONTENT { discreteValue: <string>"lm:arf" };
lylejohnson commented 2 months ago

@Odonno Thank you! I'll add that fix to my code that generates those.