This commit is contained in:
seb
2026-09-26 23:06:05 +02:00
parent e491ecfa47
commit e7f92ebef8
41 changed files with 3632 additions and 1751 deletions

View File

@@ -592,19 +592,34 @@ END
`;
export const INIT_WAREHOUSE = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'warehouse')
BEGIN
CREATE TABLE warehouse (
id INT IDENTITY(1,1) PRIMARY KEY,
company_id INT NOT NULL,
name NVARCHAR(255) NOT NULL,
CONSTRAINT FK_warehouse_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
CONSTRAINT UQ_warehouse_company_name UNIQUE (company_id, name)
);
END
`;
export const INIT_LEDGER = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'ledger')
BEGIN
CREATE TABLE ledger (
id INT IDENTITY(1,1) PRIMARY KEY,
manifestarticle_id INT NOT NULL,
warehouse_id INT NULL,
transaction_type NVARCHAR(100) NOT NULL,
amount FLOAT NOT NULL,
transaction_text NVARCHAR(MAX) NOT NULL,
hash_version INT NOT NULL,
prev_hash NVARCHAR(128) NULL,
created_at DATETIME2 NOT NULL CONSTRAINT DF_ledger_created_at DEFAULT SYSUTCDATETIME(),
CONSTRAINT FK_ledger_manifestarticle FOREIGN KEY (manifestarticle_id) REFERENCES manifestarticle(id) ON DELETE NO ACTION
CONSTRAINT FK_ledger_manifestarticle FOREIGN KEY (manifestarticle_id) REFERENCES manifestarticle(id) ON DELETE NO ACTION,
CONSTRAINT FK_ledger_warehouse FOREIGN KEY (warehouse_id) REFERENCES warehouse(id) ON DELETE NO ACTION
) WITH (LEDGER = ON (APPEND_ONLY = ON));
END
`;
@@ -772,6 +787,25 @@ BEGIN
END
`;
export const INIT_PRINTER = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'printer')
BEGIN
CREATE TABLE printer (
id INT IDENTITY(1,1) PRIMARY KEY,
company_id INT NOT NULL,
address NVARCHAR(255) NOT NULL,
type NVARCHAR(50) NOT NULL,
model NVARCHAR(255) NULL,
serial NVARCHAR(255) NULL,
sort INT NOT NULL CONSTRAINT DF_printer_sort DEFAULT 0,
[desc] NVARCHAR(MAX) NULL,
CONSTRAINT FK_printer_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
CONSTRAINT CK_printer_type CHECK (type IN ('esc/pos', 'zpl'))
);
END
`;
export const INIT_FILE = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'file')
BEGIN
@@ -862,6 +896,7 @@ export const SCHEMA_SCRIPTS = [
INIT_ARTICLE_SUPPLIER,
INIT_MANIFEST,
INIT_MANIFESTARTICLE,
INIT_WAREHOUSE,
INIT_LEDGER,
INIT_NUMBERS,
INIT_GET_NEXT_NUMBER_WITH_PREFIX_AND_PADDING,
@@ -873,6 +908,7 @@ export const SCHEMA_SCRIPTS = [
INIT_COMPANYSETTING,
INIT_POSTERMINAL,
INIT_POSTERMINALCATEGORY,
INIT_PRINTER,
INIT_FILE,
INIT_MANIFESTATTACHMENT,
INIT_MANIFESTATTACHMENT_TRIGGER,