@tauri-apps/plugin-sql 2.0.0-alpha.5 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +62 -1
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -19,7 +19,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
19
19
  ```toml
20
20
  [dependencies.tauri-plugin-sql]
21
21
  features = ["sqlite"] # or "postgres", or "mysql"
22
- version = "2.0.0-alpha"
22
+ version = "2.0.0-beta"
23
23
  # alternatively with Git
24
24
  git = "https://github.com/tauri-apps/plugins-workspace"
25
25
  branch = "v2"
@@ -105,6 +105,67 @@ const result = await db.execute(
105
105
  );
106
106
  ```
107
107
 
108
+ ## Migrations
109
+
110
+ This plugin supports database migrations, allowing you to manage database schema evolution over time.
111
+
112
+ ### Defining Migrations
113
+
114
+ Migrations are defined in Rust using the `Migration` struct. Each migration should include a unique version number, a description, the SQL to be executed, and the type of migration (Up or Down).
115
+
116
+ Example of a migration:
117
+
118
+ ```rust
119
+ use tauri_plugin_sql::{Migration, MigrationKind};
120
+
121
+ let migration = Migration {
122
+ version: 1,
123
+ description: "create_initial_tables",
124
+ sql: "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);",
125
+ kind: MigrationKind::Up,
126
+ };
127
+ ```
128
+
129
+ ### Adding Migrations to the Plugin Builder
130
+
131
+ Migrations are registered with the `Builder` struct provided by the plugin. Use the `add_migrations` method to add your migrations to the plugin for a specific database connection.
132
+
133
+ Example of adding migrations:
134
+
135
+ ```rust
136
+ use tauri_plugin_sql::{Builder, Migration, MigrationKind};
137
+
138
+ fn main() {
139
+ let migrations = vec![
140
+ // Define your migrations here
141
+ Migration {
142
+ version: 1,
143
+ description: "create_initial_tables",
144
+ sql: "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);",
145
+ kind: MigrationKind::Up,
146
+ }
147
+ ];
148
+
149
+ tauri::Builder::default()
150
+ .plugin(
151
+ tauri_plugin_sql::Builder::default()
152
+ .add_migrations("sqlite:mydatabase.db", migrations)
153
+ .build(),
154
+ )
155
+ ...
156
+ }
157
+ ```
158
+
159
+ ### Applying Migrations
160
+
161
+ 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).
162
+
163
+ ### Migration Management
164
+
165
+ - **Version Control**: Each migration must have a unique version number. This is crucial for ensuring the migrations are applied in the correct order.
166
+ - **Idempotency**: Write migrations in a way that they can be safely re-run without causing errors or unintended consequences.
167
+ - **Testing**: Thoroughly test migrations to ensure they work as expected and do not compromise the integrity of your database.
168
+
108
169
  ## Contributing
109
170
 
110
171
  PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-sql",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Interface with SQL databases",
5
5
  "license": "MIT or APACHE-2.0",
6
6
  "authors": [
@@ -21,7 +21,7 @@
21
21
  "LICENSE"
22
22
  ],
23
23
  "dependencies": {
24
- "@tauri-apps/api": "2.0.0-alpha.13"
24
+ "@tauri-apps/api": "2.0.0-beta.0"
25
25
  },
26
26
  "scripts": {
27
27
  "build": "rollup -c"