fix: remove cleanlog in initcheck
This commit is contained in:
1 parent
e0473bffdb
commit
c88d4dd5b2
2 files changed
+3
-18
No files matched your search
@@ -5,7 +5,6 @@
|
||||
import { Bindings } from "../models/db";
|
||||
import { createTables } from "./database";
|
||||
import { runMigrations } from "../migrations/migration";
|
||||
import { cleanupOldRecords } from "../repositories/monitor";
|
||||
|
||||
// 检查表是否存在
|
||||
async function tableExists(env: Bindings, tableName: string): Promise<boolean> {
|
||||
@@ -51,28 +50,17 @@ export async function checkAndInitializeDatabase(
|
||||
let missingTables: string[] = [];
|
||||
|
||||
for (const table of tablesToCheck) {
|
||||
// 先检查表是否存在
|
||||
// 检查表是否存在
|
||||
const exists = await tableExists(env, table);
|
||||
|
||||
if (!exists) {
|
||||
console.log(`表 ${table} 不存在`);
|
||||
missingTables.push(table);
|
||||
} else {
|
||||
try {
|
||||
// 表存在,再查询记录数
|
||||
const result = await env.DB.prepare(
|
||||
`SELECT COUNT(*) as count FROM ${table}`
|
||||
).first<{ count: number }>();
|
||||
console.log(`表 ${table} 存在,记录数:${result?.count || 0}`);
|
||||
} catch (error) {
|
||||
console.log(`表 ${table} 查询记录时出错:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let initialized = false;
|
||||
|
||||
// 如果有表不存在或用户表为空,则进行初始化
|
||||
// 如果有表不存在那就创建
|
||||
if (missingTables.length > 0) {
|
||||
console.log("开始初始化数据库...");
|
||||
console.log(
|
||||
@@ -89,9 +77,6 @@ export async function checkAndInitializeDatabase(
|
||||
// 执行迁移
|
||||
await runMigrations(env);
|
||||
|
||||
// 执行清理任务
|
||||
await cleanupOldRecords(env.DB);
|
||||
|
||||
return {
|
||||
initialized,
|
||||
message: initialized
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 导出所有定时任务
|
||||
import monitorTask from "./monitor-task";
|
||||
import { checkAgentsStatus } from "./agent-task";
|
||||
import { cleanupOldRecords } from "../repositories/monitor";
|
||||
import { cleanupOldRecords } from "../services";
|
||||
// 统一的定时任务处理函数
|
||||
export const runScheduledTasks = async (event: any, env: any, ctx: any) => {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user