mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: attribute default storage at startup in init.
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
NODE_ENV=development
|
||||
|
||||
# Base de données
|
||||
DATABASE_URL=postgresql://devuser:changeme@localhost:5432/devdb?schema=public
|
||||
DATABASE_URL=postgresql://devuser:changeme@localhost:5433/devdb?schema=public
|
||||
|
||||
# Projet
|
||||
PROJECT_NAME="Portabase"
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ services:
|
||||
db:
|
||||
image: postgres:17-alpine
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "5433:5432"
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
|
||||
+105
-38
@@ -21,56 +21,123 @@ export async function init() {
|
||||
async function setupCronJobs() {
|
||||
console.log("==== Setting up Cron Jobs ====");
|
||||
retentionJob.start();
|
||||
console.log(`==== Cron job started ====`);
|
||||
console.log("==== Cron job started ====");
|
||||
}
|
||||
|
||||
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,
|
||||
smtpSecure: env.SMTP_SECURE,
|
||||
};
|
||||
await db.transaction(async (tx) => {
|
||||
const systemSettingsValues = {
|
||||
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,
|
||||
smtpSecure: env.SMTP_SECURE ?? false,
|
||||
};
|
||||
|
||||
const [existing] = await db.select().from(drizzleDb.schemas.setting).where(eq(drizzleDb.schemas.setting.name, "system")).limit(1);
|
||||
const [systemSetting] = await tx
|
||||
.select()
|
||||
.from(drizzleDb.schemas.setting)
|
||||
.where(eq(drizzleDb.schemas.setting.name, "system"))
|
||||
.limit(1);
|
||||
|
||||
if (!existing) {
|
||||
console.log("====Init Setting : Create ====");
|
||||
await db.insert(drizzleDb.schemas.setting).values(configSettings);
|
||||
} else {
|
||||
console.log("====Init Setting : Update ====");
|
||||
await db.update(drizzleDb.schemas.setting).set(configSettings).where(eq(drizzleDb.schemas.setting.name, "system"));
|
||||
}
|
||||
const [finalSystemSetting] = systemSetting
|
||||
? await tx
|
||||
.update(drizzleDb.schemas.setting)
|
||||
.set(systemSettingsValues)
|
||||
.where(eq(drizzleDb.schemas.setting.name, "system"))
|
||||
.returning()
|
||||
: await tx
|
||||
.insert(drizzleDb.schemas.setting)
|
||||
.values(systemSettingsValues)
|
||||
.returning();
|
||||
|
||||
const [existingLocalChannelStorage] = await db.select().from(drizzleDb.schemas.storageChannel).where(eq(drizzleDb.schemas.storageChannel.provider, "local")).limit(1);
|
||||
|
||||
const localChannelValues = {
|
||||
provider: "local" as StorageProviderKind,
|
||||
enabled: true,
|
||||
name: "System",
|
||||
config: {}
|
||||
}
|
||||
const localStorageValues = {
|
||||
provider: "local" as StorageProviderKind,
|
||||
enabled: true,
|
||||
name: "System",
|
||||
config: {},
|
||||
};
|
||||
|
||||
if (!existingLocalChannelStorage) {
|
||||
console.log("====Local Storage : Create ====");
|
||||
const [localChannelCreated] = await db.insert(drizzleDb.schemas.storageChannel).values(localChannelValues).returning();
|
||||
const [existingLocalStorage] = await tx
|
||||
.select()
|
||||
.from(drizzleDb.schemas.storageChannel)
|
||||
.where(eq(drizzleDb.schemas.storageChannel.provider, "local"))
|
||||
.limit(1);
|
||||
|
||||
if (localChannelCreated) {
|
||||
await db.update(drizzleDb.schemas.setting).set({
|
||||
defaultStorageChannelId: localChannelCreated.id,
|
||||
}).where(eq(drizzleDb.schemas.setting.name, "system"));
|
||||
const [localStorage] = existingLocalStorage
|
||||
? await tx
|
||||
.update(drizzleDb.schemas.storageChannel)
|
||||
.set(localStorageValues)
|
||||
.where(eq(drizzleDb.schemas.storageChannel.provider, "local"))
|
||||
.returning()
|
||||
: await tx
|
||||
.insert(drizzleDb.schemas.storageChannel)
|
||||
.values(localStorageValues)
|
||||
.returning();
|
||||
|
||||
|
||||
if (finalSystemSetting.defaultStorageChannelId !== localStorage.id) {
|
||||
await tx
|
||||
.update(drizzleDb.schemas.setting)
|
||||
.set({ defaultStorageChannelId: localStorage.id })
|
||||
.where(eq(drizzleDb.schemas.setting.id, finalSystemSetting.id));
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("====Local Storage : Update ====");
|
||||
await db.update(drizzleDb.schemas.storageChannel).set(localChannelValues).where(eq(drizzleDb.schemas.storageChannel.provider, "local"));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 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,
|
||||
// smtpSecure: env.SMTP_SECURE,
|
||||
// };
|
||||
//
|
||||
// const [existing] = await db.select().from(drizzleDb.schemas.setting).where(eq(drizzleDb.schemas.setting.name, "system")).limit(1);
|
||||
//
|
||||
// if (!existing) {
|
||||
// console.log("==== Init Setting : Create ====");
|
||||
// await db.insert(drizzleDb.schemas.setting).values(configSettings);
|
||||
// } else {
|
||||
// console.log("==== Init Setting : Update ====");
|
||||
// await db.update(drizzleDb.schemas.setting).set(configSettings).where(eq(drizzleDb.schemas.setting.name, "system"));
|
||||
// }
|
||||
//
|
||||
// const [existingLocalChannelStorage] = await db.select().from(drizzleDb.schemas.storageChannel).where(eq(drizzleDb.schemas.storageChannel.provider, "local")).limit(1);
|
||||
//
|
||||
// const localChannelValues = {
|
||||
// provider: "local" as StorageProviderKind,
|
||||
// enabled: true,
|
||||
// name: "System",
|
||||
// config: {}
|
||||
// }
|
||||
//
|
||||
// if (!existingLocalChannelStorage) {
|
||||
// console.log("====Local Storage : Create ====");
|
||||
// const [localChannelCreated] = await db.insert(drizzleDb.schemas.storageChannel).values(localChannelValues).returning();
|
||||
// console.log(localChannelCreated)
|
||||
// if (localChannelCreated) {
|
||||
// await db.update(drizzleDb.schemas.setting).set({
|
||||
// defaultStorageChannelId: localChannelCreated.id,
|
||||
// }).where(eq(drizzleDb.schemas.setting.name, "system"));
|
||||
// }
|
||||
// } else {
|
||||
// console.log("====Local Storage : Update ====");
|
||||
// await db.update(drizzleDb.schemas.storageChannel).set(localChannelValues).where(eq(drizzleDb.schemas.storageChannel.provider, "local"));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
async function createDefaultOrganization() {
|
||||
const defaultOrganizationConf = {
|
||||
slug: "default",
|
||||
|
||||
Reference in New Issue
Block a user