bench
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/** Drop order = reverse of schema create dependency order. */
|
||||
export const TABLES = [
|
||||
'manifestattachment',
|
||||
'file',
|
||||
'companyuser',
|
||||
'syncpos',
|
||||
'companysetting',
|
||||
@@ -48,10 +50,12 @@ export const PROCEDURES = [
|
||||
|
||||
export const VIEWS = ['v_entity_company_number'];
|
||||
|
||||
/** Drop before tables — breaks company ↔ customergroup cycle for purge. */
|
||||
/** Drop before tables — drops all foreign keys so all tables can be purged safely. */
|
||||
export const CONSTRAINTS = [
|
||||
`IF EXISTS (SELECT 1 FROM sys.foreign_keys WHERE name = N'FK_company_poscustomergroup')
|
||||
ALTER TABLE company DROP CONSTRAINT FK_company_poscustomergroup;`,
|
||||
`DECLARE @dropFkSql NVARCHAR(MAX) = N'';
|
||||
SELECT @dropFkSql += N'ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + N'.' + QUOTENAME(OBJECT_NAME(parent_object_id)) + N' DROP CONSTRAINT ' + QUOTENAME(name) + N';'
|
||||
FROM sys.foreign_keys;
|
||||
IF @dropFkSql <> N'' EXEC sp_executesql @dropFkSql;`,
|
||||
];
|
||||
|
||||
export function buildPurgeSql() {
|
||||
|
||||
@@ -76,7 +76,8 @@ WHERE ean = @ean
|
||||
/** Link an article to its father article and mark the father. */
|
||||
export const UPDATE_FATHER_BY_SKU = `
|
||||
UPDATE article
|
||||
SET fatherarticle_id = @fatherArticleId
|
||||
SET fatherarticle_id = @fatherArticleId,
|
||||
fathersort = COALESCE(@fathersort, 0)
|
||||
WHERE sku = @sku
|
||||
`;
|
||||
|
||||
|
||||
@@ -53,6 +53,6 @@ WHERE id = @googleAuthId
|
||||
|
||||
export const SET_PROFILE = `
|
||||
UPDATE google_auth
|
||||
SET picture = @picture, picturebinary = @pictureBinary, sub = @sub
|
||||
SET picture = @picture, picturebinary = CONVERT(VARBINARY(MAX), @pictureBinary), sub = @sub
|
||||
WHERE id = @googleAuthId
|
||||
`;
|
||||
|
||||
@@ -283,22 +283,17 @@ export default function importRows(provider) {
|
||||
const father = await runner.query(articleQueries.GET_ID_BY_SKU, { sku: fatherSku });
|
||||
const fatherId = father.rows[0]?.articleId;
|
||||
if (fatherId && fatherId !== childId) {
|
||||
await runner.query(articleQueries.UPDATE_FATHER_BY_SKU, {
|
||||
sku,
|
||||
fatherArticleId: fatherId,
|
||||
});
|
||||
await runner.query(articleQueries.SET_IS_FATHER, {
|
||||
articleId: fatherId,
|
||||
});
|
||||
const childCount = await runner.query(getChildCountSql, {
|
||||
articleId: fatherId,
|
||||
});
|
||||
const count = childCount.rows[0].count;
|
||||
// The child's sort is its 0-based position among the father's children.
|
||||
await runner.query(articleQueries.SET_FATHER_SORT, {
|
||||
articleId: childId,
|
||||
await runner.query(articleQueries.UPDATE_FATHER_BY_SKU, {
|
||||
sku,
|
||||
fatherArticleId: fatherId,
|
||||
fathersort: count - 1,
|
||||
fathersort: count,
|
||||
});
|
||||
await runner.query(articleQueries.SET_IS_FATHER, {
|
||||
articleId: fatherId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,25 +53,19 @@ export default function setFatherBySku(provider) {
|
||||
throw new Error('Invalid father');
|
||||
}
|
||||
|
||||
await runner.query(queries.UPDATE_FATHER_BY_SKU, {
|
||||
sku,
|
||||
fatherArticleId: fatherId,
|
||||
});
|
||||
|
||||
await runner.query(queries.SET_IS_FATHER, {
|
||||
articleId: fatherId,
|
||||
});
|
||||
|
||||
const childCount = await runner.query(getChildCountSql, {
|
||||
articleId: fatherId,
|
||||
});
|
||||
const count = childCount.rows[0].count;
|
||||
|
||||
// The child's sort is its 0-based position among the father's children.
|
||||
await runner.query(queries.SET_FATHER_SORT, {
|
||||
articleId,
|
||||
await runner.query(queries.UPDATE_FATHER_BY_SKU, {
|
||||
sku,
|
||||
fatherArticleId: fatherId,
|
||||
fathersort: count - 1,
|
||||
fathersort: count,
|
||||
});
|
||||
|
||||
await runner.query(queries.SET_IS_FATHER, {
|
||||
articleId: fatherId,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
|
||||
Reference in New Issue
Block a user