Add company-scoped unit list/upsert/delete and article unit patches.

Units are isolated per company; article detail exposes full unit shape, and unused units can be deleted safely via FK NO ACTION.
This commit is contained in:
seb
2026-08-01 06:12:24 +02:00
parent 54700a145e
commit 12e83a7ffb
16 changed files with 519 additions and 44 deletions

View File

@@ -163,10 +163,12 @@ IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'unit')
BEGIN
CREATE TABLE unit (
id INT IDENTITY(1,1) PRIMARY KEY,
company_id INT NOT NULL,
si NVARCHAR(50) NOT NULL,
basesi NVARCHAR(50) NOT NULL,
basesifactor FLOAT NOT NULL,
CONSTRAINT UQ_unit_si UNIQUE (si)
CONSTRAINT UQ_unit_company_si UNIQUE (company_id, si),
CONSTRAINT FK_unit_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE NO ACTION
);
END
`;
@@ -233,7 +235,7 @@ BEGIN
fathersort INT NOT NULL CONSTRAINT DF_article_fathersort DEFAULT 0,
created_at DATETIME2 NOT NULL CONSTRAINT DF_article_created_at DEFAULT SYSUTCDATETIME(),
updated_at DATETIME2 NOT NULL CONSTRAINT DF_article_updated_at DEFAULT SYSUTCDATETIME(),
CONSTRAINT FK_article_unit FOREIGN KEY (unit_id) REFERENCES unit(id) ON DELETE CASCADE,
CONSTRAINT FK_article_unit FOREIGN KEY (unit_id) REFERENCES unit(id) ON DELETE NO ACTION,
CONSTRAINT FK_article_brand FOREIGN KEY (brand_id) REFERENCES brand(id) ON DELETE SET NULL,
CONSTRAINT FK_article_articlelist FOREIGN KEY (articlelist_id) REFERENCES articlelist(id) ON DELETE SET NULL,
CONSTRAINT FK_article_optionslist FOREIGN KEY (optionslist_id) REFERENCES optionslist(id) ON DELETE SET NULL,