Skip to content

Commit

Permalink
Merge pull request #82 from tago-io/TCORE-259_Fix_Database_Plugin
Browse files Browse the repository at this point in the history
TCORE-259 Fix database start plugin
  • Loading branch information
felipefdl authored Nov 7, 2024
2 parents 968d7c0 + 49805da commit 9924589
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function StepPluginConfig(props: IStepPluginConfigProps) {
moduleID: mod?.id,
field: key,
value: values[key],
setupDatabase: true,
}));

await editPluginSettings(plugin?.id || "", editValues);
Expand Down
5 changes: 3 additions & 2 deletions packages/server/Services/Plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions packages/server/Services/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = {
Expand All @@ -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);
}
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/mysql/src/Helpers/DeviceDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
});
}

Expand Down
1 change: 1 addition & 0 deletions plugins/postgres/src/Helpers/DeviceDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 9924589

Please sign in to comment.