mirror of
https://github.com/tauri-apps/tauri-docs.git
synced 2026-01-31 00:35:16 +01:00
docs(sql): add preload config example for migrations (#2417)
This commit is contained in:
committed by
GitHub
parent
38178d8ad8
commit
5e67a5234c
@@ -221,7 +221,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 title="src-tauri/tauri.conf.json" {3-5}
|
||||
{
|
||||
"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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user