diff --git a/.vscode/settings.json b/.vscode/settings.json index 5312a02..26b3786 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -54,6 +54,7 @@ "alpla", "alplamart", "alplaprod", + "alplapurchase", "bookin", "Datamart", "dotenvx", diff --git a/backend/app.ts b/backend/app.ts index 8621776..6bce1cd 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -26,7 +26,7 @@ const createApp = async () => { const __dirname = dirname(__filename); // well leave this active so we can monitor it to validate - app.use(morgan("tiny")); + app.use(morgan("dev")); app.set("trust proxy", true); app.use(lstCors()); app.all(`${baseUrl}/api/auth/*splat`, toNodeHandler(auth)); @@ -34,11 +34,11 @@ const createApp = async () => { setupRoutes(baseUrl, app); app.use( - baseUrl + "/app", + `${baseUrl}/app`, express.static(join(__dirname, "../frontend/dist")), ); - app.get(baseUrl + "/app/*splat", (_, res) => { + app.get(`${baseUrl}/app/*splat`, (_, res) => { res.sendFile(join(__dirname, "../frontend/dist/index.html")); }); diff --git a/backend/db/schema/alplapurchase.schema.ts b/backend/db/schema/alplapurchase.schema.ts new file mode 100644 index 0000000..a10fd84 --- /dev/null +++ b/backend/db/schema/alplapurchase.schema.ts @@ -0,0 +1,38 @@ +import { + integer, + jsonb, + pgTable, + text, + timestamp, + uuid, +} from "drizzle-orm/pg-core"; +import { createInsertSchema, createSelectSchema } from "drizzle-zod"; +import type { z } from "zod"; + +export const alplaPurchaseHistory = pgTable("alpla_purchase_history", { + id: uuid("id").defaultRandom().primaryKey(), + apo: integer("apo"), + revision: integer("revision"), + confirmed: integer("confirmed"), + status: integer("status"), + statusText: integer("status_text"), + journalNum: integer("journal_num"), + add_date: timestamp("add_date").defaultNow(), + upd_date: timestamp("upd_date").defaultNow(), + add_user: text("add_user"), + upd_user: text("upd_user"), + remark: text("remark"), + approvedStatus: text("approved_status"), + position: jsonb("position").default([]), + createdAt: timestamp("created_at").defaultNow(), +}); + +export const alplaPurchaseHistorySchema = + createSelectSchema(alplaPurchaseHistory); +export const newAlplaPurchaseHistorySchema = + createInsertSchema(alplaPurchaseHistory); + +export type AlplaPurchaseHistory = z.infer; +export type NewAlplaPurchaseHistory = z.infer< + typeof newAlplaPurchaseHistorySchema +>; diff --git a/backend/notification/notification.alplapurchase.ts b/backend/notification/notification.alplapurchase.ts new file mode 100644 index 0000000..1710e5c --- /dev/null +++ b/backend/notification/notification.alplapurchase.ts @@ -0,0 +1,113 @@ +import { eq } from "drizzle-orm"; +import { db } from "../db/db.controller.js"; +import { notifications } from "../db/schema/notifications.schema.js"; +import { prodQuery } from "../prodSql/prodSqlQuery.controller.js"; +import { + type SqlQuery, + sqlQuerySelector, +} from "../prodSql/prodSqlQuerySelector.utils.js"; +import { returnFunc } from "../utils/returnHelper.utils.js"; +import { sendEmail } from "../utils/sendEmail.utils.js"; +import { tryCatch } from "../utils/trycatch.utils.js"; + +/** + * + */ +const func = async (data: any, emails: string) => { + // get the actual notification as items will be updated between intervals if no one touches + const { data: l, error: le } = (await tryCatch( + db.select().from(notifications).where(eq(notifications.id, data.id)), + )) as any; + + if (le) { + return returnFunc({ + success: false, + level: "error", + module: "notification", + subModule: "query", + message: `${data.name} encountered an error while trying to get initial info`, + data: [le], + notify: true, + }); + } + + // search the query db for the query by name + const sqlQuery = sqlQuerySelector(`${data.name}`) as SqlQuery; + // create the ignore audit logs ids + const ignoreIds = l[0].options[0]?.auditId + ? `${l[0].options[0]?.auditId}` + : "0"; + + // run the check + const { data: queryRun, error } = await tryCatch( + prodQuery( + sqlQuery.query + .replace("[intervalCheck]", l[0].interval) + .replace("[ignoreList]", ignoreIds), + `Running notification query: ${l[0].name}`, + ), + ); + + if (error) { + return returnFunc({ + success: false, + level: "error", + module: "notification", + subModule: "query", + message: `Data for: ${l[0].name} encountered an error while trying to get it`, + data: [error], + notify: true, + }); + } + + if (queryRun.data.length > 0) { + // update the latest audit id + const { error: dbe } = await tryCatch( + db + .update(notifications) + .set({ options: [{ auditId: `${queryRun.data[0].id}` }] }) + .where(eq(notifications.id, data.id)), + ); + + if (dbe) { + return returnFunc({ + success: false, + level: "error", + module: "notification", + subModule: "query", + message: `Data for: ${l[0].name} encountered an error while trying to get it`, + data: [dbe], + notify: true, + }); + } + + // send the email + + const sentEmail = await sendEmail({ + email: emails, + subject: "Alert! Label Reprinted", + template: "reprintLabels", + context: { + items: queryRun.data, + }, + }); + + if (!sentEmail?.success) { + return returnFunc({ + success: false, + level: "error", + module: "email", + subModule: "notification", + message: `${l[0].name} failed to send the email`, + data: [sentEmail], + notify: true, + }); + } + } else { + console.log("doing nothing as there is nothing to do."); + } + // TODO send the error to systemAdmin users so they do not always need to be on the notifications. + // these errors are defined per notification. +}; + +export default func; diff --git a/backend/notification/notifications.master.ts b/backend/notification/notifications.master.ts index 048c802..17f4c22 100644 --- a/backend/notification/notifications.master.ts +++ b/backend/notification/notifications.master.ts @@ -16,6 +16,26 @@ const note: NewNotification[] = [ interval: "10", options: [{ auditId: [0] }], }, + { + name: "qualityBlocking", + description: + "Checks for new blocking orders that have been entered, recommend to get the most recent order in here before activating.", + active: false, + interval: "10", + options: [{ sentBlockingOrders: [{ timeStamp: "0", blockingOrder: 1 }] }], + }, + { + name: "alplaPurchaseHistory", + description: + "Will check the alpla purchase data for any changes, if the req has not been sent already then we will send this, for a po or fresh order we will ignore. ", + active: false, + interval: "5", + options: [ + { sentReqs: [{ timeStamp: "0", req: 1, approved: false }] }, + { sentAPOs: [{ timeStamp: "0", apo: 1 }] }, + { sentRCT: [{ timeStamp: "0", rct: 1 }] }, + ], + }, ]; export const createNotifications = async () => { diff --git a/backend/prodSql/queries/alplapurchase.sql b/backend/prodSql/queries/alplapurchase.sql new file mode 100644 index 0000000..4be9128 --- /dev/null +++ b/backend/prodSql/queries/alplapurchase.sql @@ -0,0 +1,61 @@ +use AlplaPROD_test1 +declare @intervalCheck as int = '[interval]' + +/* +Monitors alpla purchase for thing new. this will not update unless the order status is updated. +this means if a user just reopens the order it will update but everything changed in the position will not be updated until the user reorders or cancels the po +*/ + +select +IdBestellung as apo +,po.revision as revision +,po.Bestaetigt as confirmed +,po.status +,case po.Status + when 1 then 'Created' + when 2 then 'Ordered' + when 22 then 'Reopened' + when 4 then 'Planned' + when 5 then 'Partly Delivered' + when 6 then 'Delivered' + when 7 then 'Canceled' + when 8 then 'Closed' + else 'Unknown' end as statusText +,po.Add_User +,po.Add_Date +,po.Upd_User +,po.Upd_Date +,po.Bemerkung as remark +,po.IdJournal as journal -- use this to validate if we used it already. +,isnull(( +select + o.IdArtikelVarianten as av + ,a.Bezeichnung as alias + ,Lieferdatum as deliveryDate + ,cast(BestellMenge as decimal(18,2)) as qty + ,cast(BestellMengeVPK as decimal(18,0)) as pkg + ,cast(PreisProEinheit as decimal(18,0)) as price + ,PositionsStatus + ,case PositionsStatus + when 1 then 'Created' + when 2 then 'Ordered' + when 22 then 'Reopened' + when 4 then 'Planned' + when 5 then 'Partly Delivered' + when 6 then 'Delivered' + when 7 then 'Canceled' + when 8 then 'Closed' + else 'Unknown' end as statusText + ,o.upd_user + ,o.upd_date +from T_Bestellpositionen (nolock) as o + +left join + T_Artikelvarianten as a on + a.IdArtikelvarianten = o.IdArtikelVarianten +where o.IdBestellung = po.IdBestellung +for json path +), '[]') as postion +--,* +from T_Bestellungen (nolock) as po +where po.Upd_Date > dateadd(MINUTE, -@intervalCheck, getdate()) \ No newline at end of file diff --git a/backend/purchase/purchase.controller.ts b/backend/purchase/purchase.controller.ts new file mode 100644 index 0000000..8f521ab --- /dev/null +++ b/backend/purchase/purchase.controller.ts @@ -0,0 +1,63 @@ +/** + * This will monitor alpla purchase + */ + +import { eq } from "drizzle-orm"; +import { db } from "../db/db.controller.js"; +import { settings } from "../db/schema/settings.schema.js"; +import { createLogger } from "../logger/logger.controller.js"; +import { prodQuery } from "../prodSql/prodSqlQuery.controller.js"; +import { + type SqlQuery, + sqlQuerySelector, +} from "../prodSql/prodSqlQuerySelector.utils.js"; +import { createCronJob } from "../utils/croner.utils.js"; +import { delay } from "../utils/delay.utils.js"; +import { returnFunc } from "../utils/returnHelper.utils.js"; + +const log = createLogger({ module: "purchase", subModule: "purchaseMonitor" }); + +export const monitorAlplaPurchase = async () => { + const purchaseMonitor = await db + .select() + .from(settings) + .where(eq(settings.name, "purchaseMonitor")); + + const sqlQuery = sqlQuerySelector(`alplapurchase`) as SqlQuery; + + if (!sqlQuery.success) { + return returnFunc({ + success: false, + level: "error", + module: "purchase", + subModule: "query", + message: `Error getting alpla purchase info`, + data: [sqlQuery.message], + notify: false, + }); + } + + if (purchaseMonitor[0]?.active) { + createCronJob("opendock_sync", "* */5 * * * *", async () => { + try { + const result = await prodQuery( + sqlQuery.query.replace( + "[interval]", + `'${purchaseMonitor[0]?.value || "5"}'`, + ), + "Get release info", + ); + + if (result.data.length) { + await delay(500); + } + } catch (e) { + console.error( + { error: e }, + "Error occurred while running the monitor job", + ); + log.error({ error: e }, "Error occurred while running the monitor job"); + } + }); + } +}; diff --git a/backend/server.ts b/backend/server.ts index 9985524..00a6b72 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -10,6 +10,7 @@ import { createNotifications } from "./notification/notifications.master.js"; import { monitorReleaseChanges } from "./opendock/openDockRreleaseMonitor.utils.js"; import { opendockSocketMonitor } from "./opendock/opendockSocketMonitor.utils.js"; import { connectProdSql } from "./prodSql/prodSqlConnection.controller.js"; +import { monitorAlplaPurchase } from "./purchase/purchase.controller.js"; import { setupSocketIORoutes } from "./socket.io/serverSetup.js"; import { baseSettingValidationCheck } from "./system/settingsBase.controller.js"; import { createCronJob } from "./utils/croner.utils.js"; @@ -36,7 +37,7 @@ const start = async () => { // also we always want to have long lived processes inside a setting check. setTimeout(() => { if (systemSettings.filter((n) => n.name === "opendock_sync")[0]?.active) { - log.info({}, "Opendock is not active"); + log.info({}, "Opendock is active"); monitorReleaseChanges(); // this is od monitoring the db for all new releases opendockSocketMonitor(); createCronJob("opendockAptCleanup", "0 30 5 * * *", () => @@ -44,6 +45,10 @@ const start = async () => { ); } + if (systemSettings.filter((n) => n.name === "purchaseMonitor")[0]?.active) { + monitorAlplaPurchase(); + } + // these jobs below are system jobs and should run no matter what. createCronJob("JobAuditLogCleanUp", "0 0 5 * * *", () => dbCleanup("jobs", 30), diff --git a/backend/system/settingsBase.controller.ts b/backend/system/settingsBase.controller.ts index d3369e0..8cdc0bb 100644 --- a/backend/system/settingsBase.controller.ts +++ b/backend/system/settingsBase.controller.ts @@ -66,6 +66,16 @@ const newSettings: NewSetting[] = [ roles: ["admin"], seedVersion: 1, }, + { + name: "purchaseMonitor", + value: "5", + active: false, + description: "Monitors alpla purchase fo all changes", + moduleName: "purchase", + settingType: "feature", + roles: ["admin"], + seedVersion: 1, + }, // standard settings { diff --git a/backend/utils/returnHelper.utils.ts b/backend/utils/returnHelper.utils.ts index 194ba84..57ced08 100644 --- a/backend/utils/returnHelper.utils.ts +++ b/backend/utils/returnHelper.utils.ts @@ -11,7 +11,8 @@ interface Data { | "utils" | "opendock" | "notification" - | "email"; + | "email" + | "purchase"; subModule: | "db" | "labeling" diff --git a/frontend/src/routes/admin/notifications.tsx b/frontend/src/routes/admin/notifications.tsx index 8f0c69f..6d4ebaf 100644 --- a/frontend/src/routes/admin/notifications.tsx +++ b/frontend/src/routes/admin/notifications.tsx @@ -7,12 +7,7 @@ import { Suspense, useState } from "react"; import { toast } from "sonner"; import type { Notifications } from "../../../types/notifications"; import { Button } from "../../components/ui/button"; -import { - Card, - CardContent, - CardHeader, - CardTitle, -} from "../../components/ui/card"; +import { Card, CardContent } from "../../components/ui/card"; import { Label } from "../../components/ui/label"; import { Switch } from "../../components/ui/switch"; import { @@ -297,16 +292,13 @@ function RouteComponent() { return (
-

Settings

+

Notifications

- Manage you settings and related data. + Manage all notification settings and user subs.

- - System Settings - diff --git a/migrations/0020_stale_ma_gnuci.sql b/migrations/0020_stale_ma_gnuci.sql new file mode 100644 index 0000000..debb8d2 --- /dev/null +++ b/migrations/0020_stale_ma_gnuci.sql @@ -0,0 +1,15 @@ +CREATE TABLE "alpla_purchase_history" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "apo" integer, + "revision" integer, + "confirmed" integer, + "status" integer, + "status_text" integer, + "add_date" timestamp DEFAULT now(), + "upd_date" timestamp DEFAULT now(), + "add_user" text, + "upd_user" text, + "remark" text, + "position" jsonb DEFAULT '[]'::jsonb, + "created_at" timestamp DEFAULT now() +); diff --git a/migrations/meta/0020_snapshot.json b/migrations/meta/0020_snapshot.json new file mode 100644 index 0000000..1f71cb5 --- /dev/null +++ b/migrations/meta/0020_snapshot.json @@ -0,0 +1,1423 @@ +{ + "id": "26301706-bfb9-4e28-80a3-a1908f5f8933", + "prevId": "5628fac7-7958-4306-9c5d-5f00b843624d", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.alpla_purchase_history": { + "name": "alpla_purchase_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "apo": { + "name": "apo", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "confirmed": { + "name": "confirmed", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status_text": { + "name": "status_text", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "add_date": { + "name": "add_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "upd_date": { + "name": "upd_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "add_user": { + "name": "add_user", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "upd_user": { + "name": "upd_user", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.job_audit_log": { + "name": "job_audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "job_name": { + "name": "job_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_at": { + "name": "start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_stack": { + "name": "error_stack", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "meta_data": { + "name": "meta_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_job_audit_logs_cleanup": { + "name": "idx_job_audit_logs_cleanup", + "columns": [ + { + "expression": "start_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "account_userId_idx": { + "name": "account_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.apikey": { + "name": "apikey", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start": { + "name": "start", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prefix": { + "name": "prefix", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refill_interval": { + "name": "refill_interval", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "refill_amount": { + "name": "refill_amount", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_refill_at": { + "name": "last_refill_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "rate_limit_enabled": { + "name": "rate_limit_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "rate_limit_time_window": { + "name": "rate_limit_time_window", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 86400000 + }, + "rate_limit_max": { + "name": "rate_limit_max", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 10 + }, + "request_count": { + "name": "request_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "remaining": { + "name": "remaining", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_request": { + "name": "last_request", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "apikey_key_idx": { + "name": "apikey_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "apikey_userId_idx": { + "name": "apikey_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "apikey_user_id_user_id_fk": { + "name": "apikey_user_id_user_id_fk", + "tableFrom": "apikey", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.jwks": { + "name": "jwks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_username": { + "name": "display_username", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.datamart": { + "name": "datamart", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "options": { + "name": "options", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "public_access": { + "name": "public_access", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "add_date": { + "name": "add_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "add_user": { + "name": "add_user", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'lst-system'" + }, + "upd_date": { + "name": "upd_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "upd_user": { + "name": "upd_user", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'lst-system'" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "datamart_name_unique": { + "name": "datamart_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.logs": { + "name": "logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "module": { + "name": "module", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subModule": { + "name": "subModule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stack": { + "name": "stack", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "checked": { + "name": "checked", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "hostname": { + "name": "hostname", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notifications": { + "name": "notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "interval": { + "name": "interval", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'5'" + }, + "options": { + "name": "options", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "notify_name": { + "name": "notify_name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification_sub": { + "name": "notification_sub", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "notification_id": { + "name": "notification_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "emails": { + "name": "emails", + "type": "text[]", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + } + }, + "indexes": {}, + "foreignKeys": { + "notification_sub_user_id_user_id_fk": { + "name": "notification_sub_user_id_user_id_fk", + "tableFrom": "notification_sub", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "notification_sub_notification_id_notifications_id_fk": { + "name": "notification_sub_notification_id_notifications_id_fk", + "tableFrom": "notification_sub", + "tableTo": "notifications", + "columnsFrom": [ + "notification_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "notification_sub_user_notification_unique": { + "name": "notification_sub_user_notification_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id", + "notification_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.opendock_apt": { + "name": "opendock_apt", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "release": { + "name": "release", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "open_dock_apt_id": { + "name": "open_dock_apt_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "appointment": { + "name": "appointment", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "upd_date": { + "name": "upd_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "opendock_apt_release_unique": { + "name": "opendock_apt_release_unique", + "nullsNotDistinct": false, + "columns": [ + "release" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.printer_log": { + "name": "printer_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "printer_log_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.settings": { + "name": "settings", + "schema": "", + "columns": { + "settings_id": { + "name": "settings_id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "moduleName": { + "name": "moduleName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "roles": { + "name": "roles", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[\"systemAdmin\"]'::jsonb" + }, + "settingType": { + "name": "settingType", + "type": "setting_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "seed_version": { + "name": "seed_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "add_User": { + "name": "add_User", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'LST_System'" + }, + "add_Date": { + "name": "add_Date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "upd_User": { + "name": "upd_User", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'LST_System'" + }, + "upd_date": { + "name": "upd_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "name": { + "name": "name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.stats": { + "name": "stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "default": "'serverStats'" + }, + "build": { + "name": "build", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "last_update": { + "name": "last_update", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.setting_type": { + "name": "setting_type", + "schema": "public", + "values": [ + "feature", + "system", + "standard" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index 951806e..fe184be 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -141,6 +141,13 @@ "when": 1775159956510, "tag": "0019_large_thunderbird", "breakpoints": true + }, + { + "idx": 20, + "version": "7", + "when": 1775566910220, + "tag": "0020_stale_ma_gnuci", + "breakpoints": true } ] } \ No newline at end of file