This commit is contained in:
seb
2026-10-11 17:26:11 +02:00
parent 7ffb21aabb
commit 7f4092971d
17 changed files with 3076 additions and 2616 deletions

View File

@@ -6,6 +6,7 @@ export const TABLES = [
'account',
'articleattributevalue',
'articleproperty',
'attributevaluepic',
'attributevalue',
'attributename',
'propertyname',

View File

@@ -0,0 +1,23 @@
export const GET_NEXT_SORT = `
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
FROM attributevaluepic
WHERE attributevalue_id = @attributeValueId
`;
export const ADD = `
INSERT INTO attributevaluepic (attributevalue_id, pic_id, sort)
VALUES (@attributeValueId, @picId, @sort)
`;
export const DELETE_BY_ATTRIBUTE_VALUE = `
DELETE FROM attributevaluepic
WHERE attributevalue_id = @attributeValueId
`;
export const GET_FIRST_PIC_BY_ATTRIBUTE_VALUE = `
SELECT TOP 1 p.id AS picId, p.thumbw AS thumbW, p.thumbh AS thumbH, p.thumbhash AS thumbHash
FROM attributevaluepic avp
INNER JOIN pic p ON p.id = avp.pic_id
WHERE avp.attributevalue_id = @attributeValueId
ORDER BY avp.sort ASC, avp.id ASC
`;

View File

@@ -45,6 +45,16 @@ FROM (
INNER JOIN brand b ON b.id = bp.brand_id
INNER JOIN company c ON c.id = b.company_id
WHERE p.hash = @hash
UNION
SELECT c.root_category_id AS categoryId
FROM pic p
INNER JOIN attributevaluepic avp ON avp.pic_id = p.id
INNER JOIN attributevalue av ON av.id = avp.attributevalue_id
INNER JOIN attributename an ON an.id = av.attribute_id
INNER JOIN company c ON c.id = an.company_id
WHERE p.hash = @hash
) AS combined
WHERE categoryId IS NOT NULL
`;

View File

@@ -463,6 +463,22 @@ BEGIN
END
`;
export const INIT_ATTRIBUTEVALUEPIC = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'attributevaluepic')
BEGIN
CREATE TABLE attributevaluepic (
id INT IDENTITY(1,1) PRIMARY KEY,
attributevalue_id INT NOT NULL,
pic_id INT NOT NULL,
sort INT NOT NULL CONSTRAINT DF_attributevaluepic_sort DEFAULT 0,
CONSTRAINT FK_attributevaluepic_attributevalue FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE,
CONSTRAINT FK_attributevaluepic_pic FOREIGN KEY (pic_id) REFERENCES pic(id) ON DELETE CASCADE,
CONSTRAINT UQ_attributevaluepic_attributevalue_pic UNIQUE (attributevalue_id, pic_id),
CONSTRAINT UQ_attributevaluepic_attributevalue_sort UNIQUE (attributevalue_id, sort)
);
END
`;
export const INIT_ARTICLELISTARTICLE = `
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articlelistarticle')
BEGIN
@@ -1183,6 +1199,7 @@ export const SCHEMA_SCRIPTS = [
INIT_ARTICLEEAN,
INIT_ARTICLEPIC,
INIT_BRANDPIC,
INIT_ATTRIBUTEVALUEPIC,
INIT_ARTICLELISTARTICLE,
INIT_OPTIONSLISTARTICLE,
INIT_CATEGORYARTICLE,