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
|
NODE_ENV=development
|
||||||
|
|
||||||
# Base de données
|
# 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
|
# Projet
|
||||||
PROJECT_NAME="Portabase"
|
PROJECT_NAME="Portabase"
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ services:
|
|||||||
db:
|
db:
|
||||||
image: postgres:17-alpine
|
image: postgres:17-alpine
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "5433:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- postgres-data:/var/lib/postgresql/data
|
- postgres-data:/var/lib/postgresql/data
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
+105
-38
@@ -21,56 +21,123 @@ export async function init() {
|
|||||||
async function setupCronJobs() {
|
async function setupCronJobs() {
|
||||||
console.log("==== Setting up Cron Jobs ====");
|
console.log("==== Setting up Cron Jobs ====");
|
||||||
retentionJob.start();
|
retentionJob.start();
|
||||||
console.log(`==== Cron job started ====`);
|
console.log("==== Cron job started ====");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createSettingsIfNotExist() {
|
async function createSettingsIfNotExist() {
|
||||||
const configSettings = {
|
await db.transaction(async (tx) => {
|
||||||
name: "system",
|
const systemSettingsValues = {
|
||||||
smtpPassword: env.SMTP_PASSWORD ?? null,
|
name: "system",
|
||||||
smtpFrom: env.SMTP_FROM ?? null,
|
smtpPassword: env.SMTP_PASSWORD ?? null,
|
||||||
smtpHost: env.SMTP_HOST ?? null,
|
smtpFrom: env.SMTP_FROM ?? null,
|
||||||
smtpPort: env.SMTP_PORT ?? null,
|
smtpHost: env.SMTP_HOST ?? null,
|
||||||
smtpUser: env.SMTP_USER ?? null,
|
smtpPort: env.SMTP_PORT ?? null,
|
||||||
smtpSecure: env.SMTP_SECURE,
|
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) {
|
const [finalSystemSetting] = systemSetting
|
||||||
console.log("====Init Setting : Create ====");
|
? await tx
|
||||||
await db.insert(drizzleDb.schemas.setting).values(configSettings);
|
.update(drizzleDb.schemas.setting)
|
||||||
} else {
|
.set(systemSettingsValues)
|
||||||
console.log("====Init Setting : Update ====");
|
.where(eq(drizzleDb.schemas.setting.name, "system"))
|
||||||
await db.update(drizzleDb.schemas.setting).set(configSettings).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 = {
|
const localStorageValues = {
|
||||||
provider: "local" as StorageProviderKind,
|
provider: "local" as StorageProviderKind,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: "System",
|
name: "System",
|
||||||
config: {}
|
config: {},
|
||||||
}
|
};
|
||||||
|
|
||||||
if (!existingLocalChannelStorage) {
|
const [existingLocalStorage] = await tx
|
||||||
console.log("====Local Storage : Create ====");
|
.select()
|
||||||
const [localChannelCreated] = await db.insert(drizzleDb.schemas.storageChannel).values(localChannelValues).returning();
|
.from(drizzleDb.schemas.storageChannel)
|
||||||
|
.where(eq(drizzleDb.schemas.storageChannel.provider, "local"))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (localChannelCreated) {
|
const [localStorage] = existingLocalStorage
|
||||||
await db.update(drizzleDb.schemas.setting).set({
|
? await tx
|
||||||
defaultStorageChannelId: localChannelCreated.id,
|
.update(drizzleDb.schemas.storageChannel)
|
||||||
}).where(eq(drizzleDb.schemas.setting.name, "system"));
|
.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() {
|
async function createDefaultOrganization() {
|
||||||
const defaultOrganizationConf = {
|
const defaultOrganizationConf = {
|
||||||
slug: "default",
|
slug: "default",
|
||||||
|
|||||||
Reference in New Issue
Block a user