diff --git a/packages/console/src/Components/Setup/StepPluginConfig/StepPluginConfig.tsx b/packages/console/src/Components/Setup/StepPluginConfig/StepPluginConfig.tsx index 3b35abcf..d5fc9a2e 100644 --- a/packages/console/src/Components/Setup/StepPluginConfig/StepPluginConfig.tsx +++ b/packages/console/src/Components/Setup/StepPluginConfig/StepPluginConfig.tsx @@ -113,6 +113,7 @@ function StepPluginConfig(props: IStepPluginConfigProps) { moduleID: mod?.id, field: key, value: values[key], + setupDatabase: true, })); await editPluginSettings(plugin?.id || "", editValues); diff --git a/packages/server/Services/Plugins.ts b/packages/server/Services/Plugins.ts index 404abebc..c02bda60 100644 --- a/packages/server/Services/Plugins.ts +++ b/packages/server/Services/Plugins.ts @@ -298,11 +298,12 @@ export async function deactivatePlugin(pluginID: string) { (id) => id !== pluginID, ); await setMainSettings(settings); - const plugins = await getAllInsidePlugins(); - const plugin = plugins.find((x: any) => x.id === pluginID); + const allPlugins = await getAllInsidePlugins(); + const plugin = allPlugins.find((x: any) => x.id === pluginID); if (plugin) { const stopPlugin = new Plugin(plugin.fullPath); await stopPlugin.stop(true, 3000).catch(() => null); + plugins.delete(pluginID); const socketData = { id: pluginID, delete: true, diff --git a/packages/server/Services/Settings.ts b/packages/server/Services/Settings.ts index 982efbba..0699bc50 100644 --- a/packages/server/Services/Settings.ts +++ b/packages/server/Services/Settings.ts @@ -211,6 +211,7 @@ export async function setPluginModulesSettings(id: string, values: any) { const filePath = path.join(root, "settings.yml"); const plugin = plugins.get(id); const modules: IPluginSettingsModule[] = []; + let firstConfig = false; for (const item of values) { const module = plugin?.modules?.get(item.moduleID); @@ -231,6 +232,8 @@ export async function setPluginModulesSettings(id: string, values: any) { } else { modules.push({ id: item.moduleID, values: { [item.field]: item.value } }); } + + firstConfig = item.setupDatabase; } const data: IPluginSettings = { @@ -251,6 +254,15 @@ export async function setPluginModulesSettings(id: string, values: any) { await startPluginModule(id, item.moduleID); } } + + if (firstConfig) { + for (const plugin of plugins.values()) { + if (plugin.types.includes("database") && plugin.id !== id) { + await plugin.stop(true, 3000).catch(() => null); + plugins.delete(plugin.id); + } + } + } } /** diff --git a/plugins/mysql/src/Helpers/DeviceDatabase.ts b/plugins/mysql/src/Helpers/DeviceDatabase.ts index 20349920..bfa71cef 100644 --- a/plugins/mysql/src/Helpers/DeviceDatabase.ts +++ b/plugins/mysql/src/Helpers/DeviceDatabase.ts @@ -21,6 +21,7 @@ export async function getDeviceConnection(id: TGenericID, type: TDeviceType) { table.timestamp("created_at").nullable(); table.timestamp("chunk_timestamp_start"); table.timestamp("chunk_timestamp_end"); + table.string("serie", 100); if (type === "mutable") { table.timestamp("updated_at"); @@ -32,7 +33,6 @@ export async function getDeviceConnection(id: TGenericID, type: TDeviceType) { table.index(["time"]); table.index(["group"]); table.index(["created_at"]); - table.string("serie", 100); }); } diff --git a/plugins/postgres/src/Helpers/DeviceDatabase.ts b/plugins/postgres/src/Helpers/DeviceDatabase.ts index 750baa87..a5e85387 100644 --- a/plugins/postgres/src/Helpers/DeviceDatabase.ts +++ b/plugins/postgres/src/Helpers/DeviceDatabase.ts @@ -21,6 +21,7 @@ export async function getDeviceConnection(id: TGenericID, type: TDeviceType) { table.timestamp("created_at").nullable(); table.timestamp("chunk_timestamp_start"); table.timestamp("chunk_timestamp_end"); + table.string("serie", 100); if (type === "mutable") { table.timestamp("updated_at");