Эх сурвалжийг харах

✨ feat(database): 添加初始数据库迁移脚本和表结构定义

陈雪 2 долоо хоног өмнө
parent
commit
62a986e4c2

+ 14 - 0
src-tauri/resources/init.sql

@@ -0,0 +1,14 @@
+IF NOT EXISTS (SELECT name FROM sqlite_master WHERE type='table' AND name='mt_goods_cate') THEN
+    CREATE TABLE mt_goods_cate (
+        ID INTEGER PRIMARY KEY AUTOINCREMENT,
+        NAME TEXT DEFAULT '',
+        LOGO TEXT DEFAULT '',
+        LOCAL_LOGO TEXT DEFAULT '',
+        DESCRIPTION TEXT,
+        CREATE_TIME DATETIME DEFAULT NULL,
+        UPDATE_TIME DATETIME DEFAULT NULL,
+        OPERATOR TEXT DEFAULT NULL,
+        SORT INTEGER DEFAULT 0,
+        STATUS TEXT DEFAULT 'A'
+    );
+END IF;

+ 15 - 1
src-tauri/src/lib.rs

@@ -1,3 +1,7 @@
+use std::vec;
+
+use tauri_plugin_sql::{Migration, MigrationKind};
+
 // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
 #[tauri::command]
 fn greet(name: &str) -> String {
@@ -6,8 +10,18 @@ fn greet(name: &str) -> String {
 
 #[cfg_attr(mobile, tauri::mobile_entry_point)]
 pub fn run() {
+    let migrations = vec![Migration {
+        version: 1,
+        description: "create_initial_tables",
+        sql: include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/resources/init.sql")),
+        kind: MigrationKind::Up,
+    }];
     tauri::Builder::default()
-        .plugin(tauri_plugin_sql::Builder::new().build())
+        .plugin(
+            tauri_plugin_sql::Builder::default()
+                .add_migrations("sqlite:store.db", migrations)
+                .build(),
+        )
         .plugin(tauri_plugin_opener::init())
         .invoke_handler(tauri::generate_handler![greet])
         .run(tauri::generate_context!())

+ 1 - 0
src-tauri/tauri.conf.json

@@ -29,6 +29,7 @@
   "bundle": {
     "active": true,
     "targets": "all",
+    "resources": ["resources/*"],
     "icon": [
       "icons/32x32.png",
       "icons/128x128.png",