feat: add server settings (#487)
* feat: add server settings * feat: remove old migration * feat: add new migrations * refactor: format * fix: build error * refactor: format * fix: lint
This commit is contained in:
@@ -22,12 +22,14 @@
|
||||
"@homarr/common": "workspace:^0.1.0",
|
||||
"@homarr/db": "workspace:^0.1.0",
|
||||
"@homarr/definitions": "workspace:^0.1.0",
|
||||
"@homarr/icons": "workspace:^0.1.0",
|
||||
"@homarr/log": "workspace:^",
|
||||
"@homarr/redis": "workspace:^0.1.0",
|
||||
"@homarr/server-settings": "workspace:^0.1.0",
|
||||
"@homarr/validation": "workspace:^0.1.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"node-cron": "^3.0.3",
|
||||
"@homarr/icons": "workspace:^0.1.0"
|
||||
"superjson": "2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { jobs } from "./jobs";
|
||||
import { seedServerSettingsAsync } from "./seed-server-settings";
|
||||
|
||||
jobs.startAll();
|
||||
|
||||
void seedServerSettingsAsync();
|
||||
|
||||
33
apps/tasks/src/seed-server-settings.ts
Normal file
33
apps/tasks/src/seed-server-settings.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import SuperJSON from "superjson";
|
||||
|
||||
import { db } from "@homarr/db";
|
||||
import { serverSettings } from "@homarr/db/schema/sqlite";
|
||||
import { logger } from "@homarr/log";
|
||||
|
||||
import {
|
||||
defaultServerSettings,
|
||||
defaultServerSettingsKeys,
|
||||
} from "../../../packages/server-settings";
|
||||
|
||||
export const seedServerSettingsAsync = async () => {
|
||||
const serverSettingsData = await db.query.serverSettings.findMany();
|
||||
let insertedSettingsCount = 0;
|
||||
|
||||
for (const settingsKey of defaultServerSettingsKeys) {
|
||||
if (
|
||||
serverSettingsData.some((setting) => setting.settingKey === settingsKey)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
await db.insert(serverSettings).values({
|
||||
settingKey: settingsKey,
|
||||
value: SuperJSON.stringify(defaultServerSettings[settingsKey]),
|
||||
});
|
||||
insertedSettingsCount++;
|
||||
}
|
||||
|
||||
if (insertedSettingsCount > 0) {
|
||||
logger.info(`Inserted ${insertedSettingsCount} missing settings`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user