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

missing field `executed_at` #46

Closed jaymes15 closed 1 year ago

jaymes15 commented 1 year ago

@Odonno While trying to apply migrations using surrealdb-migrations apply I get the following error:

Error: Failed to convert `[{ id: script_migration:0h0r8c71clh98jciohol, script_name: '20230717_225815_001_Index' }, { executed_at: '2023-07-17T21:56:38.217948925Z', id: script_migration:iwf5blj1nk7d5oj3pv8o, script_name: '20230717_225627_script_migration' }]` to `T`: missing field `executed_at`

Here is a screenshot for my migration folder:

Screenshot 2023-07-17 at 23 15 21

I noticed from the error that script_migration as executed_at field in 20230717_225627_script_migration.surql but 20230717_225815_001_Index.surql does not have executed_at field, hence the error.

Screenshot 2023-07-17 at 23 17 10 Screenshot 2023-07-18 at 05 27 44
Odonno commented 1 year ago

I am curious. This should never happen. script_migration is an auto-managed table by this library, you should never modify the data or data structure.

If this is not reason of the problem, can you show the content of the 20230717_225627_script_migration.surql file?

jaymes15 commented 1 year ago

@Odonno here is the content of script_migration.surql

DEFINE TABLE script_migration SCHEMAFULL;

DEFINE FIELD script_name ON script_migration TYPE string;
DEFINE FIELD executed_at ON script_migration TYPE datetime VALUE $before OR time::now();
Odonno commented 1 year ago

After checking internally, this was due to the OPTION IMPORT statement in a schema file. This statement erases the database entirely before import.