refactor: introduce database provider abstraction, isolate MSSQL layer

- Add provider contract (src/providers/provider.js): query() -> {rows,
  rowsAffected, insertId}, callback transaction(fn), exec() for stored
  procs, initialize/purge lifecycle
- Add MssqlProvider (src/providers/mssql/index.js) wrapping an mssql
  ConnectionPool with normalized results, tx commit/rollback and
  constraint-error classifiers (unique 2627/2601, FK 547)
- LibDashStore constructor now takes a provider instead of a pool
  (breaking); adds LibDashStore.create() async factory; keeps pool as
  transitional bridge until store modules are converted (see TODO.md)
- Move MSSQL-specific code into the provider: src/sql/* ->
  src/providers/mssql/queries/*, src/schema.js ->
  src/providers/mssql/schema.js, purge SQL -> purgeSql.js
- Update scripts, generate-schema-graph.js and package.json exports
  (./providers/mssql, ./providers/provider)
- Add TODO.md with the remaining provider/SQLite migration plan

No SQL or behavioral changes.
This commit is contained in:
seb
2026-09-20 13:51:01 +02:00
parent 67b3f8b6bf
commit 53a20c4353
184 changed files with 508 additions and 192 deletions

View File

@@ -0,0 +1,74 @@
/** Drop order = reverse of schema create dependency order. */
export const TABLES = [
'companyuser',
'syncpos',
'companysetting',
'posterminalcategory',
'posterminal',
'numbers',
'ledger',
'articlesupplier',
'manifestarticle',
'manifest',
'price',
'articletext',
'categorytext',
'categorypic',
'categoryarticle',
'optionslistarticle',
'articlelistarticle',
'brandpic',
'articlepic',
'articleean',
'articlehistory',
'entityhistory',
'entityaddress',
'entitycontact',
'article',
'brand',
'articlelist',
'optionslist',
'unittext',
'unit',
'entity',
'customergroup',
'google_auth',
'company',
'pic',
'category',
'tax',
'language',
'meta',
];
export const PROCEDURES = [
'getnextnumberwithprefixandpadding',
'peeknextnumberwithprefixandpadding',
];
export const VIEWS = ['v_entity_company_number'];
/** 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}];`,
),
...VIEWS.map(
(name) =>
`IF OBJECT_ID(N'dbo.${name}', N'V') IS NOT NULL DROP VIEW 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');
}