cloudroam
2025-03-13 e9db61f701979a365a1002d46f1340d539fc2e20
app/src/main/java/com/example/firstapp/database/AppDatabase.kt
@@ -1,6 +1,5 @@
package com.example.firstapp
import android.content.Context
import androidx.room.Database
import androidx.room.Room
@@ -21,11 +20,21 @@
import com.example.firstapp.utils.TAG_LIST
import com.example.firstapp.database.ext.ConvertersDate
import com.example.firstapp.model.CourierStat
import com.example.firstapp.model.DailyStat
@Database(
    entities = [ Msg::class, Code::class, KeywordEntity::class, Reminder::class],
    entities = [
        Msg::class,
        Code::class,
        KeywordEntity::class,
        Reminder::class
    ],
    views = [
        CourierStat::class,
        DailyStat::class
    ],
    version = 20,
    exportSchema = false
)
@@ -72,16 +81,6 @@
        private val MIGRATION_MSG = object : Migration(19, 20) {
            override fun migrate(database: SupportSQLiteDatabase) {
                //database.execSQL("Create table Msg as Select id,type,`from`,content,(case when sim_info like 'SIM1%' then '0' when sim_info like 'SIM2%' then '1' else '-1' end) as sim_slot,sim_info,sub_id,time from Logs where 1 = 1")
@@ -111,6 +110,23 @@
                        `isEnabled` INTEGER NOT NULL
                    )
                """)
                // 创建 CourierStat 视图
                database.execSQL("""
                    CREATE VIEW IF NOT EXISTS CourierStat AS
                    SELECT courierName, COUNT(*) as count
                    FROM packages
                    GROUP BY courierName
                """)
                // 创建 DailyStat 视图
                database.execSQL("""
                    CREATE VIEW IF NOT EXISTS DailyStat AS
                    SELECT date(receivedTime/1000, 'unixepoch', 'localtime') as date,
                           COUNT(*) as count
                    FROM packages
                    GROUP BY date(receivedTime/1000, 'unixepoch', 'localtime')
                """)
//                database.execSQL("""
//                   CREATE TABLE   IF NOT EXISTS `reminders` (
//                    id INTEGER PRIMARY KEY AUTOINCREMENT,