This commit is contained in:
seb
2026-10-18 20:48:47 +02:00
parent 8cc7d0eb0b
commit 9ed7e4ee3b
11 changed files with 201 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
/** Drop order = reverse of schema create dependency order. */
export const TABLES = [
'healthcheck',
'articlewarehousesummary',
'deliverysummary',
'shipmentsummary',

View File

@@ -0,0 +1,19 @@
export const ENSURE_ROW = `
IF NOT EXISTS (SELECT 1 FROM healthcheck)
BEGIN
INSERT INTO healthcheck ([sequence]) VALUES (0);
END
`;
export const SELECT_FOR_UPDATE = `
SELECT TOP 1 id, [sequence]
FROM healthcheck WITH (UPDLOCK, ROWLOCK)
ORDER BY id ASC;
`;
export const UPDATE_SEQUENCE = `
UPDATE healthcheck
SET [sequence] = @sequence,
updated_at = SYSUTCDATETIME()
WHERE id = @id;
`;

View File

@@ -1437,8 +1437,20 @@ BEGIN
END
`;
export const INIT_HEALTHCHECK = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'healthcheck')
BEGIN
CREATE TABLE healthcheck (
id INT IDENTITY(1,1) PRIMARY KEY,
[sequence] BIGINT NOT NULL CONSTRAINT DF_healthcheck_sequence DEFAULT 0,
updated_at DATETIME2 NOT NULL CONSTRAINT DF_healthcheck_updated_at DEFAULT SYSUTCDATETIME()
);
END
`;
/** DDL scripts in dependency order for schema init. */
export const SCHEMA_SCRIPTS = [
INIT_HEALTHCHECK,
INIT_META,
INIT_LANGUAGE,
INIT_TAX,

View File

@@ -0,0 +1,24 @@
import * as source from '../../mssql/queries/healthcheck.js';
import { translateQueries } from './translate.js';
const queries = translateQueries(source, 'healthcheck');
export const ENSURE_ROW = `
INSERT INTO healthcheck (id, "sequence")
SELECT 1, 0
WHERE NOT EXISTS (SELECT 1 FROM healthcheck);
`;
export const SELECT_FOR_UPDATE = `
SELECT id, "sequence"
FROM healthcheck
ORDER BY id ASC
LIMIT 1;
`;
export const UPDATE_SEQUENCE = `
UPDATE healthcheck
SET "sequence" = @sequence,
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
WHERE id = @id;
`;

View File

@@ -1058,8 +1058,17 @@ CREATE TABLE IF NOT EXISTS subagentschedule (
CREATE INDEX IF NOT EXISTS IX_subagentschedule_company ON subagentschedule (company_id);
`;
export const INIT_HEALTHCHECK = `
CREATE TABLE IF NOT EXISTS healthcheck (
id INTEGER PRIMARY KEY AUTOINCREMENT,
"sequence" INTEGER NOT NULL DEFAULT 0,
updated_at TEXT NOT NULL DEFAULT (${UTC_NOW})
);
`;
/** DDL scripts in dependency order for SQLite schema initialization. */
export const SCHEMA_SCRIPTS = [
INIT_HEALTHCHECK,
INIT_META,
INIT_LANGUAGE,
INIT_TAX,