u
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
/** Drop order = reverse of schema create dependency order. */
|
||||
export const TABLES = [
|
||||
'articleattributevalue',
|
||||
'articleproperty',
|
||||
'attributevalue',
|
||||
'attributename',
|
||||
'propertyname',
|
||||
'manifestattachment',
|
||||
'labeltemplate',
|
||||
'file',
|
||||
|
||||
41
src/providers/mssql/queries/articleattributevalue.js
Normal file
41
src/providers/mssql/queries/articleattributevalue.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export const LIST_BY_ARTICLE_ID = `
|
||||
SELECT
|
||||
aav.id,
|
||||
aav.article_id AS articleId,
|
||||
an.id AS attributeId,
|
||||
an.name AS attributeName,
|
||||
an.exclusive,
|
||||
av.id AS attributeValueId,
|
||||
av.value,
|
||||
aav.sort
|
||||
FROM articleattributevalue aav
|
||||
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id
|
||||
INNER JOIN attributename an ON an.id = av.attribute_id
|
||||
WHERE aav.article_id = @articleId
|
||||
ORDER BY an.sort ASC, an.id ASC, aav.sort ASC, aav.id ASC
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ARTICLE_ID = `
|
||||
DELETE FROM articleattributevalue
|
||||
WHERE article_id = @articleId
|
||||
`;
|
||||
|
||||
export const INSERT_ROW = `
|
||||
INSERT INTO articleattributevalue (article_id, attributevalue_id, sort)
|
||||
OUTPUT INSERTED.id, INSERTED.article_id AS articleId, INSERTED.attributevalue_id AS attributeValueId, INSERTED.sort
|
||||
VALUES (@articleId, @attributeValueId, @sort)
|
||||
`;
|
||||
|
||||
export const GET_VALUE_DETAIL = `
|
||||
SELECT
|
||||
av.id AS attributeValueId,
|
||||
av.value,
|
||||
av.sort,
|
||||
an.id AS attributeId,
|
||||
an.name AS attributeName,
|
||||
an.exclusive,
|
||||
an.company_id AS companyId
|
||||
FROM attributevalue av
|
||||
INNER JOIN attributename an ON an.id = av.attribute_id
|
||||
WHERE av.id = @attributeValueId
|
||||
`;
|
||||
29
src/providers/mssql/queries/articleproperty.js
Normal file
29
src/providers/mssql/queries/articleproperty.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export const LIST_BY_ARTICLE_ID = `
|
||||
SELECT
|
||||
ap.id,
|
||||
ap.article_id AS articleId,
|
||||
ap.property_id AS propertyId,
|
||||
pn.name AS name,
|
||||
ap.value,
|
||||
ap.sort
|
||||
FROM articleproperty ap
|
||||
INNER JOIN propertyname pn ON pn.id = ap.property_id
|
||||
WHERE ap.article_id = @articleId
|
||||
ORDER BY ap.sort ASC, ap.id ASC
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ARTICLE_ID = `
|
||||
DELETE FROM articleproperty
|
||||
WHERE article_id = @articleId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ARTICLE_AND_PROPERTY_ID = `
|
||||
DELETE FROM articleproperty
|
||||
WHERE article_id = @articleId AND property_id = @propertyId
|
||||
`;
|
||||
|
||||
export const INSERT_ROW = `
|
||||
INSERT INTO articleproperty (article_id, property_id, value, sort)
|
||||
OUTPUT INSERTED.id, INSERTED.article_id AS articleId, INSERTED.property_id AS propertyId, INSERTED.value, INSERTED.sort
|
||||
VALUES (@articleId, @propertyId, @value, @sort)
|
||||
`;
|
||||
88
src/providers/mssql/queries/attributename.js
Normal file
88
src/providers/mssql/queries/attributename.js
Normal file
@@ -0,0 +1,88 @@
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
an.id,
|
||||
an.name,
|
||||
an.sort,
|
||||
an.exclusive,
|
||||
(
|
||||
SELECT
|
||||
av.id,
|
||||
av.value,
|
||||
av.sort
|
||||
FROM attributevalue av
|
||||
WHERE av.attribute_id = an.id
|
||||
ORDER BY av.sort ASC, av.id ASC
|
||||
FOR JSON PATH
|
||||
) AS valuesJson
|
||||
FROM attributename an
|
||||
WHERE an.company_id = @companyId
|
||||
ORDER BY an.sort ASC, an.id ASC
|
||||
`;
|
||||
|
||||
export const LIST_IDS_BY_COMPANY = `
|
||||
SELECT id
|
||||
FROM attributename
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY sort ASC, id ASC
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_ID = `
|
||||
SELECT
|
||||
an.id,
|
||||
an.company_id,
|
||||
an.name,
|
||||
an.sort,
|
||||
an.exclusive,
|
||||
(
|
||||
SELECT
|
||||
av.id,
|
||||
av.value,
|
||||
av.sort
|
||||
FROM attributevalue av
|
||||
WHERE av.attribute_id = an.id
|
||||
ORDER BY av.sort ASC, av.id ASC
|
||||
FOR JSON PATH
|
||||
) AS valuesJson
|
||||
FROM attributename an
|
||||
WHERE an.id = @id AND an.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
id,
|
||||
company_id,
|
||||
name,
|
||||
sort,
|
||||
exclusive
|
||||
FROM attributename
|
||||
WHERE name = @name AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM attributename
|
||||
WHERE company_id = @companyId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO attributename (company_id, name, sort, exclusive)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.sort, INSERTED.exclusive
|
||||
VALUES (@companyId, @name, @sort, @exclusive)
|
||||
`;
|
||||
|
||||
export const UPDATE_BY_ID = `
|
||||
UPDATE attributename
|
||||
SET name = @name, sort = @sort, exclusive = @exclusive
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const UPDATE_SORT = `
|
||||
UPDATE attributename
|
||||
SET sort = @sort
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM attributename
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
70
src/providers/mssql/queries/attributevalue.js
Normal file
70
src/providers/mssql/queries/attributevalue.js
Normal file
@@ -0,0 +1,70 @@
|
||||
export const LIST_BY_ATTRIBUTE_ID = `
|
||||
SELECT
|
||||
av.id,
|
||||
av.attribute_id AS attributeId,
|
||||
av.value,
|
||||
av.sort
|
||||
FROM attributevalue av
|
||||
INNER JOIN attributename an ON an.id = av.attribute_id
|
||||
WHERE av.attribute_id = @attributeId AND an.company_id = @companyId
|
||||
ORDER BY av.sort ASC, av.id ASC
|
||||
`;
|
||||
|
||||
export const LIST_IDS_BY_ATTRIBUTE_ID = `
|
||||
SELECT av.id
|
||||
FROM attributevalue av
|
||||
INNER JOIN attributename an ON an.id = av.attribute_id
|
||||
WHERE av.attribute_id = @attributeId AND an.company_id = @companyId
|
||||
ORDER BY av.sort ASC, av.id ASC
|
||||
`;
|
||||
|
||||
export const GET_BY_ID_AND_COMPANY = `
|
||||
SELECT
|
||||
av.id,
|
||||
av.attribute_id AS attributeId,
|
||||
av.value,
|
||||
av.sort,
|
||||
an.company_id AS companyId
|
||||
FROM attributevalue av
|
||||
INNER JOIN attributename an ON an.id = av.attribute_id
|
||||
WHERE av.id = @id AND an.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_BY_ATTRIBUTE_AND_VALUE = `
|
||||
SELECT
|
||||
av.id,
|
||||
av.attribute_id AS attributeId,
|
||||
av.value,
|
||||
av.sort
|
||||
FROM attributevalue av
|
||||
WHERE av.attribute_id = @attributeId AND av.value = @value
|
||||
`;
|
||||
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM attributevalue
|
||||
WHERE attribute_id = @attributeId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO attributevalue (attribute_id, value, sort)
|
||||
OUTPUT INSERTED.id, INSERTED.attribute_id AS attributeId, INSERTED.value, INSERTED.sort
|
||||
VALUES (@attributeId, @value, @sort)
|
||||
`;
|
||||
|
||||
export const UPDATE_BY_ID = `
|
||||
UPDATE attributevalue
|
||||
SET value = @value, sort = @sort
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const UPDATE_SORT = `
|
||||
UPDATE attributevalue
|
||||
SET sort = @sort
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ID = `
|
||||
DELETE FROM attributevalue
|
||||
WHERE id = @id
|
||||
`;
|
||||
65
src/providers/mssql/queries/propertyname.js
Normal file
65
src/providers/mssql/queries/propertyname.js
Normal file
@@ -0,0 +1,65 @@
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
sort
|
||||
FROM propertyname
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY sort ASC, id ASC
|
||||
`;
|
||||
|
||||
export const LIST_IDS_BY_COMPANY = `
|
||||
SELECT id
|
||||
FROM propertyname
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY sort ASC, id ASC
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_ID = `
|
||||
SELECT
|
||||
id,
|
||||
company_id,
|
||||
name,
|
||||
sort
|
||||
FROM propertyname
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
id,
|
||||
company_id,
|
||||
name,
|
||||
sort
|
||||
FROM propertyname
|
||||
WHERE name = @name AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM propertyname
|
||||
WHERE company_id = @companyId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO propertyname (company_id, name, sort)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.sort
|
||||
VALUES (@companyId, @name, @sort)
|
||||
`;
|
||||
|
||||
export const UPDATE_BY_ID = `
|
||||
UPDATE propertyname
|
||||
SET name = @name, sort = @sort
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const UPDATE_SORT = `
|
||||
UPDATE propertyname
|
||||
SET sort = @sort
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM propertyname
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
@@ -894,6 +894,80 @@ END
|
||||
');
|
||||
`;
|
||||
|
||||
export const INIT_PROPERTYNAME = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'propertyname')
|
||||
BEGIN
|
||||
CREATE TABLE propertyname (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
name NVARCHAR(255) NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_propertyname_sort DEFAULT 0,
|
||||
CONSTRAINT FK_propertyname_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_propertyname_company_name UNIQUE (company_id, name)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLEPROPERTY = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articleproperty')
|
||||
BEGIN
|
||||
CREATE TABLE articleproperty (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
article_id INT NOT NULL,
|
||||
property_id INT NOT NULL,
|
||||
value NVARCHAR(MAX) NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_articleproperty_sort DEFAULT 0,
|
||||
CONSTRAINT FK_articleproperty_article FOREIGN KEY (article_id) REFERENCES article(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_articleproperty_property FOREIGN KEY (property_id) REFERENCES propertyname(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_articleproperty_article_property UNIQUE (article_id, property_id)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ATTRIBUTENAME = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'attributename')
|
||||
BEGIN
|
||||
CREATE TABLE attributename (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
name NVARCHAR(255) NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_attributename_sort DEFAULT 0,
|
||||
exclusive BIT NOT NULL CONSTRAINT DF_attributename_exclusive DEFAULT 0,
|
||||
CONSTRAINT FK_attributename_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_attributename_company_name UNIQUE (company_id, name)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ATTRIBUTEVALUE = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'attributevalue')
|
||||
BEGIN
|
||||
CREATE TABLE attributevalue (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
attribute_id INT NOT NULL,
|
||||
value NVARCHAR(255) NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_attributevalue_sort DEFAULT 0,
|
||||
CONSTRAINT FK_attributevalue_attribute FOREIGN KEY (attribute_id) REFERENCES attributename(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_attributevalue_attribute_value UNIQUE (attribute_id, value)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLEATTRIBUTEVALUE = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articleattributevalue')
|
||||
BEGIN
|
||||
CREATE TABLE articleattributevalue (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
article_id INT NOT NULL,
|
||||
attributevalue_id INT NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_articleattributevalue_sort DEFAULT 0,
|
||||
CONSTRAINT FK_articleattributevalue_article FOREIGN KEY (article_id) REFERENCES article(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_articleattributevalue_attributevalue FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_articleattributevalue_article_attributevalue UNIQUE (article_id, attributevalue_id)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
/** DDL scripts in dependency order for schema init. */
|
||||
export const SCHEMA_SCRIPTS = [
|
||||
INIT_META,
|
||||
@@ -926,6 +1000,11 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLENAME,
|
||||
INIT_PRICE,
|
||||
INIT_ARTICLE_SUPPLIER,
|
||||
INIT_PROPERTYNAME,
|
||||
INIT_ARTICLEPROPERTY,
|
||||
INIT_ATTRIBUTENAME,
|
||||
INIT_ATTRIBUTEVALUE,
|
||||
INIT_ARTICLEATTRIBUTEVALUE,
|
||||
INIT_MANIFEST,
|
||||
INIT_MANIFESTARTICLE,
|
||||
INIT_WAREHOUSE,
|
||||
|
||||
Reference in New Issue
Block a user