Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCORE-259 Fix database start plugin #82

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading