58 lines
1.2 KiB
JavaScript
58 lines
1.2 KiB
JavaScript
/** Drop order = reverse of schema create dependency order. */
|
|
export const TABLES = [
|
|
'companyuser',
|
|
'syncpos',
|
|
'numbers',
|
|
'manifestarticle',
|
|
'manifest',
|
|
'price',
|
|
'articletext',
|
|
'categorytext',
|
|
'categorypic',
|
|
'categoryarticle',
|
|
'optionslistarticle',
|
|
'articlelistarticle',
|
|
'brandpic',
|
|
'articlepic',
|
|
'articleean',
|
|
'articlehistory',
|
|
'article',
|
|
'brand',
|
|
'articlelist',
|
|
'optionslist',
|
|
'unittext',
|
|
'unit',
|
|
'entity',
|
|
'customergroup',
|
|
'google_auth',
|
|
'company',
|
|
'pic',
|
|
'category',
|
|
'tax',
|
|
'language',
|
|
'meta',
|
|
];
|
|
|
|
export const PROCEDURES = ['getnextnumberwithprefixandpadding'];
|
|
|
|
/** Drop before tables — breaks company ↔ customergroup cycle for purge. */
|
|
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;`,
|
|
];
|
|
|
|
export function buildPurgeSql() {
|
|
const drops = [
|
|
...PROCEDURES.map(
|
|
(name) =>
|
|
`IF OBJECT_ID(N'dbo.${name}', N'P') IS NOT NULL DROP PROCEDURE dbo.[${name}];`,
|
|
),
|
|
...CONSTRAINTS,
|
|
...TABLES.map(
|
|
(name) =>
|
|
`IF OBJECT_ID(N'dbo.${name}', N'U') IS NOT NULL DROP TABLE dbo.[${name}];`,
|
|
),
|
|
];
|
|
return drops.join('\n');
|
|
}
|