feat: Implement default API site seeding, add a dialect-aware setting upsert utility, and introduce check-in API routes with background task processing.

This commit is contained in:
cita
2026-03-11 14:31:23 +08:00
parent f43247e91d
commit 921c551a3a
6 changed files with 52 additions and 38 deletions
+2 -7
View File
@@ -1,6 +1,7 @@
import { asc } from 'drizzle-orm';
import cron from 'node-cron';
import { db, schema } from '../db/index.js';
import { upsertSetting } from '../db/upsertSetting.js';
const BACKUP_VERSION = '2.0';
@@ -558,13 +559,7 @@ async function importPreferencesSection(section: PreferencesBackupSection): Prom
for (const row of section.settings) {
if (!isSettingValueAcceptable(row.key, row.value)) continue;
await tx.insert(schema.settings).values({
key: row.key,
value: stringifySettingValue(row.value),
}).onConflictDoUpdate({
target: schema.settings.key,
set: { value: stringifySettingValue(row.value) },
}).run();
await upsertSetting(row.key, row.value, tx);
applied.push({ key: row.key, value: row.value });
}
});
+2 -10
View File
@@ -1,5 +1,6 @@
import { eq } from 'drizzle-orm';
import { db, schema } from '../db/index.js';
import { upsertSetting } from '../db/upsertSetting.js';
export const DEFAULT_SITE_SEED_SETTING_KEY = 'default_site_seed_v1';
@@ -53,16 +54,7 @@ type SeedSummary = {
};
async function writeSeedMarker(tx: typeof db) {
await tx.insert(schema.settings)
.values({
key: DEFAULT_SITE_SEED_SETTING_KEY,
value: JSON.stringify(true),
})
.onConflictDoUpdate({
target: schema.settings.key,
set: { value: JSON.stringify(true) },
})
.run();
await upsertSetting(DEFAULT_SITE_SEED_SETTING_KEY, true, tx);
}
export async function ensureDefaultSitesSeeded(): Promise<SeedSummary> {