Closed gabeidx closed 1 month ago
After a conversation with @FabianLars on Discord, it seems the current fix is to load the DB from the client side:
import Database from "@tauri-apps/plugin-sql";
const db = await Database.load("sqlite:mydatabase.db"); // <- same db name from plugin setup!
The reason is that the migrations are run on the load()
command implementation https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/sql/src/plugin.rs#L166-L169 and not when the plugin is initialized.
A refactoring of the plugin is being considered, which may change the behavior and match the expectation of the migrations being run from the Rust side automatically when the plugin is initialized.
Related to https://github.com/tauri-apps/plugins-workspace/issues/509 and https://github.com/tauri-apps/plugins-workspace/issues/506.
It seems this could be solved if there was a way to write config.preload
value, based on https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/sql/src/plugin.rs#L313-L317
Oh my god, i totally forgot about that. You absolutely can change that value! Simply add this to your tauri.conf.json file:
{
"plugins": {
"sql": {
"preload": ["dbname"]
}
}
}
I JUST found it in the docs as well! 🤦 https://v2.tauri.app/develop/plugins/#plugin-configuration
I've opened a couple of PRs to update the readme and the v2 docs for the plugin:
While following the docs instructions to use the
tauri-plugin-sql
with sqlite and use the migrations feature, I noticed the migrations were not executed at all.Reproduction
cargo create-tauri-app --beta
cargo tauri add sql
Cargo.toml
fn main() {
];
tauri::Builder::default() .plugin( tauri_plugin_sql::Builder::default()
Expected behavior
Migrations are applied automatically when the plugin is initialized.
Full
capabilities/default.json
Full
tauri info
output