u
This commit is contained in:
@@ -323,10 +323,10 @@ BEGIN
|
||||
brand_id INT NULL,
|
||||
articlelist_id INT NULL,
|
||||
optionslist_id INT NULL,
|
||||
is_father BIT NOT NULL CONSTRAINT DF_article_is_father DEFAULT 0,
|
||||
fatherarticle_id INT NULL,
|
||||
fatherattributename_id INT NULL,
|
||||
fathersort INT NOT NULL CONSTRAINT DF_article_fathersort DEFAULT 0,
|
||||
is_parent BIT NOT NULL CONSTRAINT DF_article_is_parent DEFAULT 0,
|
||||
parentarticle_id INT NULL,
|
||||
parentattributename_id INT NULL,
|
||||
parentsort INT NOT NULL CONSTRAINT DF_article_parentsort 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_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE NO ACTION,
|
||||
@@ -334,23 +334,23 @@ BEGIN
|
||||
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,
|
||||
CONSTRAINT FK_article_fatherarticle FOREIGN KEY (fatherarticle_id) REFERENCES article(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_article_fatherattributename FOREIGN KEY (fatherattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_article_parentarticle FOREIGN KEY (parentarticle_id) REFERENCES article(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_article_parentattributename FOREIGN KEY (parentattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT UQ_article_company_sku UNIQUE (company_id, sku)
|
||||
);
|
||||
|
||||
-- Only enforce sibling sort uniqueness among children of the same father.
|
||||
-- Only enforce sibling sort uniqueness among children of the same parent.
|
||||
-- (SQL Server UNIQUE treats NULLs as equal, which would block multiple root articles.)
|
||||
CREATE UNIQUE INDEX UQ_article_fatherarticle_fathersort
|
||||
ON article (fatherarticle_id, fathersort)
|
||||
WHERE fatherarticle_id IS NOT NULL;
|
||||
CREATE UNIQUE INDEX UQ_article_parentarticle_parentsort
|
||||
ON article (parentarticle_id, parentsort)
|
||||
WHERE parentarticle_id IS NOT NULL;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('article') AND name = 'fatherattributename_id')
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('article') AND name = 'parentattributename_id')
|
||||
BEGIN
|
||||
ALTER TABLE article ADD fatherattributename_id INT NULL;
|
||||
ALTER TABLE article ADD CONSTRAINT FK_article_fatherattributename FOREIGN KEY (fatherattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION;
|
||||
ALTER TABLE article ADD parentattributename_id INT NULL;
|
||||
ALTER TABLE article ADD CONSTRAINT FK_article_parentattributename FOREIGN KEY (parentattributename_id) REFERENCES attributename(id) ON DELETE NO ACTION;
|
||||
END
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('article') AND name = 'track_stock')
|
||||
|
||||
Reference in New Issue
Block a user