Files
portabase/src/utils/init.ts
T

93 lines
2.7 KiB
TypeScript
Raw Normal View History

import {prisma} from "@/prisma";
import {env} from "@/env.mjs";
export function init() {
consoleAscii()
console.log("====Init Functions====")
2024-11-29 19:25:44 +01:00
createDefaultOrganization().then(() => {
})
createSettingsIfNotExist()
.then(() => {
console.log('====Initialization completed====');
})
.catch((err) => {
console.error('Error during initialization:', err);
});
}
async function createSettingsIfNotExist() {
const configSettings = {
name: "system",
smtpPassword: env.SMTP_PASSWORD ?? null,
smtpFrom: env.SMTP_FROM ?? null,
smtpHost: env.SMTP_HOST ?? null,
smtpPort: env.SMTP_PORT ?? null,
smtpUser: env.SMTP_USER ?? null,
s3EndPointUrl: env.S3_ENDPOINT ?? null,
s3AccessKeyId: env.S3_ACCESS_KEY ?? null,
s3SecretAccessKey: env.S3_SECRET_KEY ?? null,
S3BucketName: env.S3_BUCKET_NAME ?? null,
}
const settings = await prisma.settings.findUnique({
where: {
name: "system",
}
})
2024-11-29 19:25:44 +01:00
if (!settings) {
console.log("====Init Setting : Create ====")
await prisma.settings.create({
data: {
2024-11-17 21:01:05 +01:00
...configSettings
}
})
2024-11-29 19:25:44 +01:00
} else {
console.log("====Init Setting : Update ====")
await prisma.settings.update({
where: {
name: "system",
},
data: {
...configSettings,
}
})
}
}
2024-11-29 19:25:44 +01:00
async function createDefaultOrganization() {
const defaultOrganizationConf = {
slug: "default",
name: "Default Organization",
}
const defaultOrganization = await prisma.organization.findUnique({
where: {
slug: "default",
}
})
if (!defaultOrganization) {
2024-11-30 21:05:47 +01:00
console.log("==== Creating default Organization... ====\n")
2024-11-29 19:25:44 +01:00
await prisma.organization.create({
data: {
...defaultOrganizationConf
}
})
}
}
function consoleAscii() {
console.log("\n" +
" ____ __ __ _____ \n" +
" / __ \\ ____ _____ / /_ ____ _ / /_ ____ _ _____ ___ / ___/ ___ _____ _ __ ___ _____\n" +
2024-11-29 12:54:34 +01:00
" / /_/ // __ \\ / ___// __// __ // __ \\ / __ // ___// _ \\ \\__ \\ / _ \\ / ___/| | / // _ \\ / ___/\n" +
" / ____// /_/ // / / /_ / /_/ // /_/ // /_/ /(__ )/ __/ ___/ // __// / | |/ // __// / \n" +
"/_/ \\____//_/ \\__/ \\__,_//_.___/ \\__,_//____/ \\___/ /____/ \\___//_/ |___/ \\___//_/ \n" +
" \n")
}