This commit is contained in:
seb
2026-07-31 00:08:50 +02:00
parent 93e52cd513
commit 6bdac7e543
17 changed files with 520 additions and 24 deletions

16
src/sql/category.js Normal file
View File

@@ -0,0 +1,16 @@
export const GET_TREE = `
WITH tree AS (
SELECT id, parent_id, sort
FROM category
WHERE id = @rootId
UNION ALL
SELECT c.id, c.parent_id, c.sort
FROM category c
INNER JOIN tree t ON c.parent_id = t.id
)
SELECT id, parent_id, sort
FROM tree
ORDER BY sort, id
`;

10
src/sql/company.js Normal file
View File

@@ -0,0 +1,10 @@
export const GET_BY_COMPANY_USER_ID = `
SELECT
c.id,
c.default_language_id,
c.root_category_id,
c.name
FROM company c
INNER JOIN companyuser cu ON cu.company_id = c.id
WHERE cu.id = @companyUserId
`;

6
src/sql/companyuser.js Normal file
View File

@@ -0,0 +1,6 @@
export const GET_BY_EMAIL = `
SELECT cu.id
FROM companyuser cu
INNER JOIN google_auth ga ON ga.id = cu.google_auth_id
WHERE ga.email = @email
`;

49
src/sql/purge.js Normal file
View File

@@ -0,0 +1,49 @@
/** Drop order = reverse of schema create dependency order. */
export const TABLES = [
'companyuser',
'numbers',
'manifestarticle',
'manifest',
'price',
'articletext',
'categorytext',
'categorypic',
'categoryarticle',
'optionslistarticle',
'articlelistarticle',
'brandpic',
'articlepic',
'articleean',
'articlehistory',
'article',
'brand',
'articlelist',
'optionslist',
'unittext',
'unit',
'entity',
'customergroup',
'company',
'pic',
'category',
'tax',
'language',
'google_auth',
'meta',
];
export const PROCEDURES = ['getnextnumberwithprefixandpadding'];
export function buildPurgeSql() {
const drops = [
...PROCEDURES.map(
(name) =>
`IF OBJECT_ID(N'dbo.${name}', N'P') IS NOT NULL DROP PROCEDURE dbo.[${name}];`,
),
...TABLES.map(
(name) =>
`IF OBJECT_ID(N'dbo.${name}', N'U') IS NOT NULL DROP TABLE dbo.[${name}];`,
),
];
return drops.join('\n');
}