diff --git a/db/patch-maintenance-table.sql b/db/patch-maintenance-table.sql deleted file mode 100644 index ce14f766..00000000 --- a/db/patch-maintenance-table.sql +++ /dev/null @@ -1,34 +0,0 @@ --- You should not modify if this have pushed to Github, unless it does serious wrong with the db. -BEGIN TRANSACTION; - -CREATE TABLE maintenance -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - title VARCHAR(150), - description TEXT, - user_id INTEGER REFERENCES user ON UPDATE CASCADE ON DELETE SET NULL, - start_date DATETIME, - end_date DATETIME -); - -CREATE TABLE monitor_maintenance -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - monitor_id INTEGER NOT NULL, - maintenance_id INTEGER NOT NULL, - CONSTRAINT FK_maintenance FOREIGN KEY (maintenance_id) REFERENCES maintenance (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT FK_monitor FOREIGN KEY (monitor_id) REFERENCES monitor (id) ON DELETE CASCADE ON UPDATE CASCADE -); - -CREATE TABLE maintenance_status_page -( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - status_page_id INTEGER NOT NULL, - maintenance_id INTEGER NOT NULL, - CONSTRAINT FK_maintenance FOREIGN KEY (maintenance_id) REFERENCES maintenance (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT FK_status_page FOREIGN KEY (status_page_id) REFERENCES status_page (id) ON DELETE CASCADE ON UPDATE CASCADE -); - -create index maintenance_user_id on maintenance (user_id); - -COMMIT; diff --git a/db/patch-maintenance-table2.sql b/db/patch-maintenance-table2.sql new file mode 100644 index 00000000..76644596 --- /dev/null +++ b/db/patch-maintenance-table2.sql @@ -0,0 +1,56 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +-- Just for someone who tested maintenance before (patch-maintenance-table.sql) +DROP TABLE IF EXISTS maintenance_status_page; +DROP TABLE IF EXISTS monitor_maintenance; +DROP TABLE IF EXISTS maintenance; +DROP TABLE IF EXISTS maintenance_timeslot; + +-- maintenance +CREATE TABLE [maintenance] ( + [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + [title] VARCHAR(150) NOT NULL, + [description] TEXT NOT NULL, + [user_id] INTEGER REFERENCES [user]([id]) ON DELETE SET NULL ON UPDATE CASCADE, + [active] BOOLEAN NOT NULL DEFAULT 1, + [strategy] VARCHAR(50) NOT NULL DEFAULT 'single', + [start_date] DATETIME, + [end_date] DATETIME, + [start_time] TIME, + [end_time] TIME, + [weekdays] VARCHAR2(250) DEFAULT '[]', + [days_of_month] TEXT DEFAULT '[]', + [interval_day] INTEGER +); + +CREATE INDEX [maintenance_user_id] ON [maintenance]([user_id]); + +-- maintenance_status_page +CREATE TABLE maintenance_status_page ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + status_page_id INTEGER NOT NULL, + maintenance_id INTEGER NOT NULL, + CONSTRAINT FK_maintenance FOREIGN KEY (maintenance_id) REFERENCES maintenance (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT FK_status_page FOREIGN KEY (status_page_id) REFERENCES status_page (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +-- maintenance_timeslot +CREATE TABLE [maintenance_timeslot] ( + [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + [maintenance_id] INTEGER NOT NULL CONSTRAINT [FK_maintenance] REFERENCES [maintenance]([id]) ON DELETE CASCADE ON UPDATE CASCADE, + [start_date] DATETIME NOT NULL, + [end_date] DATETIME, + [generated_next] BOOLEAN DEFAULT 0 +); + +-- monitor_maintenance +CREATE TABLE monitor_maintenance ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + monitor_id INTEGER NOT NULL, + maintenance_id INTEGER NOT NULL, + CONSTRAINT FK_maintenance FOREIGN KEY (maintenance_id) REFERENCES maintenance (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT FK_monitor FOREIGN KEY (monitor_id) REFERENCES monitor (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +COMMIT; diff --git a/server/database.js b/server/database.js index 5666d9a6..16f12445 100644 --- a/server/database.js +++ b/server/database.js @@ -64,7 +64,7 @@ class Database { "patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] }, "patch-add-radius-monitor.sql": true, "patch-monitor-add-resend-interval.sql": true, - "patch-maintenance-table.sql": true, + "patch-maintenance-table2.sql": true, }; /** diff --git a/server/model/maintenance_timeslot.js b/server/model/maintenance_timeslot.js index f06806ac..3ac64b6b 100644 --- a/server/model/maintenance_timeslot.js +++ b/server/model/maintenance_timeslot.js @@ -7,7 +7,7 @@ const { UptimeKumaServer } = require("../uptime-kuma-server"); class MaintenanceTimeslot extends BeanModel { async toPublicJSON() { - const serverTimezoneOffset = await UptimeKumaServer.getInstance().getTimezoneOffset(); + const serverTimezoneOffset = UptimeKumaServer.getInstance().getTimezoneOffset(); const obj = { id: this.id, diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 667f6b6a..ac832f8e 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -204,7 +204,7 @@ class UptimeKumaServer { } } - async getTimezoneOffset() { + getTimezoneOffset() { return dayjs().format("Z"); }