From 490d4208d7ca9c2892cc7af67f1ec089e42a6cf6 Mon Sep 17 00:00:00 2001 From: "Gabriel Silva (Gabe)" <192261+gabeidx@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:52:34 +0200 Subject: [PATCH] docs(sql): add `preload` config example for migrations (#1557) * docs(sql): add `preload` config example for migrations * improve idempotency explanation --- plugins/sql/README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/sql/README.md b/plugins/sql/README.md index acfe095d..fa9b9c57 100644 --- a/plugins/sql/README.md +++ b/plugins/sql/README.md @@ -158,7 +158,26 @@ fn main() { ### Applying Migrations -Migrations are applied automatically when the plugin is initialized. The plugin runs these migrations against the database specified by the connection string. Ensure that the migrations are defined in the correct order and are idempotent (safe to run multiple times). +To apply the migrations when the plugin is initialized, add the connection string to the `tauri.conf.json` file: + +```json +{ + "plugins": { + "sql": { + "preload": ["sqlite:mydatabase.db"] + } + } +} +``` + +Alternatively, the client side `load()` also runs the migrations for a given connection string: + +```ts +import Database from "@tauri-apps/plugin-sql"; +const db = await Database.load("sqlite:mydatabase.db"); +``` + +Ensure that the migrations are defined in the correct order and are safe to run multiple times. ### Migration Management