u
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/** Drop order = reverse of schema create dependency order. */
|
||||
export const TABLES = [
|
||||
'quotesummary',
|
||||
'ordersummary',
|
||||
'package',
|
||||
'shipping',
|
||||
|
||||
@@ -1215,6 +1215,34 @@ BEGIN
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_QUOTESUMMARY = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'quotesummary')
|
||||
BEGIN
|
||||
CREATE TABLE quotesummary (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
manifest_id INT NOT NULL CONSTRAINT UQ_quotesummary_manifest UNIQUE,
|
||||
quote_number NVARCHAR(100) NOT NULL,
|
||||
quote_date DATETIME2 NOT NULL,
|
||||
created_at DATETIME2 NOT NULL CONSTRAINT DF_quotesummary_created_at DEFAULT SYSUTCDATETIME(),
|
||||
entity_id INT NULL,
|
||||
customer_name NVARCHAR(255) NULL,
|
||||
positions INT NOT NULL CONSTRAINT DF_quotesummary_positions DEFAULT 0,
|
||||
gross_total FLOAT NOT NULL CONSTRAINT DF_quotesummary_gross_total DEFAULT 0,
|
||||
total_quantity FLOAT NOT NULL CONSTRAINT DF_quotesummary_total_quantity DEFAULT 0,
|
||||
CONSTRAINT FK_quotesummary_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_quotesummary_manifest FOREIGN KEY (manifest_id) REFERENCES manifest(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_quotesummary_entity FOREIGN KEY (entity_id) REFERENCES entity(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IX_quotesummary_company_date
|
||||
ON quotesummary (company_id, quote_date DESC, manifest_id DESC);
|
||||
|
||||
CREATE INDEX IX_quotesummary_company_number
|
||||
ON quotesummary (company_id, quote_number);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_MCP_CLIENT = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'mcp_client')
|
||||
BEGIN
|
||||
@@ -1338,6 +1366,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_SHIPPING,
|
||||
INIT_PACKAGE,
|
||||
INIT_ORDERSUMMARY,
|
||||
INIT_QUOTESUMMARY,
|
||||
INIT_MCP_CLIENT,
|
||||
INIT_MCP_AUTH_CODE,
|
||||
INIT_MCP_TOKEN,
|
||||
|
||||
@@ -876,6 +876,29 @@ CREATE INDEX IF NOT EXISTS IX_ordersummary_company_number
|
||||
ON ordersummary (company_id, order_number);
|
||||
`;
|
||||
|
||||
export const INIT_QUOTESUMMARY = `
|
||||
CREATE TABLE IF NOT EXISTS quotesummary (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
company_id INTEGER NOT NULL,
|
||||
manifest_id INTEGER NOT NULL UNIQUE,
|
||||
quote_number TEXT NOT NULL,
|
||||
quote_date TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
entity_id INTEGER NULL,
|
||||
customer_name TEXT NULL,
|
||||
positions INTEGER NOT NULL DEFAULT 0,
|
||||
gross_total REAL NOT NULL DEFAULT 0,
|
||||
total_quantity REAL NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE NO ACTION,
|
||||
FOREIGN KEY (manifest_id) REFERENCES manifest(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (entity_id) REFERENCES entity(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS IX_quotesummary_company_date
|
||||
ON quotesummary (company_id, quote_date DESC, manifest_id DESC);
|
||||
CREATE INDEX IF NOT EXISTS IX_quotesummary_company_number
|
||||
ON quotesummary (company_id, quote_number);
|
||||
`;
|
||||
|
||||
export const INIT_MCP_CLIENT = `
|
||||
CREATE TABLE IF NOT EXISTS mcp_client (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -985,6 +1008,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_SHIPPING,
|
||||
INIT_PACKAGE,
|
||||
INIT_ORDERSUMMARY,
|
||||
INIT_QUOTESUMMARY,
|
||||
INIT_MCP_CLIENT,
|
||||
INIT_MCP_AUTH_CODE,
|
||||
INIT_MCP_TOKEN,
|
||||
|
||||
Reference in New Issue
Block a user