فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

feat(A03): add v7 transactional audit schema with migration tests

* feat(A03): introduce v7 audit and correction stores with unique command indices * feat(A03): add append-only transactional audit writer and admin-scoped reader * feat(A03): atomically audit manual journal posting, reversal and fiscal closing * feat(A03): persist retail journal and append-only audit event atomically * fix(A03/A04): retain and protect audit history during company restores * fix(A04): accept v7 backup manifest while rejecting future schemas * test(A03): upgrade schema-version assertions to IndexedDB v7 * test(A03): upgrade schema-version assertions to IndexedDB v7 * test(A03): upgrade schema-version assertions to IndexedDB v7 * test(A03): verify atomic auditing, admin scope, rollback and financial event linkage * test(A03): prove v6 to v7 additive migration preserves records * test(A03/A04): disallow tampering with recovered audit history

davoodmehraban89 committed Oct 14, 2026 at 23:34 UTC 16ed2beb6065f33e402b3c4176a9774eca142aba
11 files changed +250 -14
src/controllers/SettingsController.js
+1 -1
@@ -152,7 +152,7 @@ class SettingsControllerImpl {
152 !['Factor-easyPro', 'Finora Pro'].includes(backup.app) ||
153 backup.scope !== 'company' ||
154 !Number.isSafeInteger(backup.schemaVersion) ||
155 - backup.schemaVersion < 1 || backup.schemaVersion > 6 ||
155 + backup.schemaVersion < 1 || backup.schemaVersion > 7 ||
156 typeof backup.companyId !== 'string' || !backup.companyId.trim() ||
157 !backup.data || typeof backup.data !== 'object' || Array.isArray(backup.data)) {
158 throw new Error('ساختار یا نسخه فایل پشتیبان شرکت نامعتبر است');
src/core/AccountingService.js
+12 -3
@@ -3,6 +3,7 @@
3 import { StorageService } from './StorageService.js';
4 import { DataScope } from './DataScope.js';
5 import { Auth } from './Auth.js';
6 +import { AuditService } from './AuditService.js';
7 import { buildLedgerReports } from './LedgerReports.mjs';
8 import { reconcileFinancialData } from './ReconciliationCore.mjs';
9 import {
@@ -143,7 +144,7 @@ class AccountingServiceImpl {
144 async closePeriod(periodId) {
145 if (!Auth.isAdmin()) throw new Error('بستن دوره مالی فقط برای مدیر مجاز است');
146 const companyId = await DataScope.companyId();
146 - return StorageService.transaction(['fiscal_periods', 'journal_entries'], async tx => {
147 + return StorageService.transaction(['fiscal_periods', 'journal_entries', 'audit_events'], async tx => {
148 const period = await periodFor(tx, companyId, periodId);
149 ensurePeriodOpen(period);
150 const journals = await entriesFor(tx, companyId);
@@ -152,6 +153,8 @@ class AccountingServiceImpl {
153 }
154 const closed = { ...period, status: 'closed', closed: true, closedBy: actor(), closedAt: new Date().toISOString() };
155 await tx.put('fiscal_periods', closed);
156 + await AuditService.append(tx, { companyId, eventType: 'period_closed', sourceType: 'fiscal_period',
157 + sourceId: periodId, commandKey: 'close-period:' + periodId, businessDate: period.endDate });
158 return closed;
159 });
160 }
@@ -247,7 +250,7 @@ class AccountingServiceImpl {
250 const lines = cleanLines(data.lines);
251 const sourceKey = data.sourceType && data.sourceId
252 ? journalSourceKey(companyId, data.sourceType, data.sourceId, data.revision || 1) : undefined;
250 - return StorageService.transaction(['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines'], async tx => {
253 + return StorageService.transaction(['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines', 'audit_events'], async tx => {
254 const period = await periodFor(tx, companyId, data.periodId);
255 const accounts = await tx.getAllByIndex('account_chart', 'companyId', companyId);
256 const totals = validateJournal({ companyId, date: data.date, lines }, accounts, period);
@@ -264,6 +267,9 @@ class AccountingServiceImpl {
267 for (const [position, line] of lines.entries()) {
268 await tx.put('journal_lines', { ...line, id: uid('jl_'), companyId, journalId: id, position });
269 }
270 + await AuditService.append(tx, { companyId, eventType: 'journal_posted', sourceType: 'journal',
271 + sourceId: journal.id, commandKey: 'manual-journal:' + (sourceKey || journal.id),
272 + businessDate: journal.date, lineCount: lines.length });
273 return journal;
274 });
275 }
@@ -300,7 +306,7 @@ class AccountingServiceImpl {
306 async reverseJournal(originalId, { periodId, date, description = '' }) {
307 requireAccountingAdmin();
308 const companyId = await DataScope.companyId();
303 - return StorageService.transaction(['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines'], async tx => {
309 + return StorageService.transaction(['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines', 'audit_events'], async tx => {
310 const original = await tx.get('journal_entries', originalId);
311 if (!original || original.companyId !== companyId || original.status !== 'posted' ||
312 original.reversedById || original.reversalOfId) throw new Error('این سند قابل برگشت نیست');
@@ -327,6 +333,9 @@ class AccountingServiceImpl {
333 await tx.put('journal_lines', { ...line, id: uid('jl_'), companyId, journalId: id, position });
334 }
335 await tx.put('journal_entries', { ...original, reversedById: id, reversedAt: journal.postedAt });
336 + await AuditService.append(tx, { companyId, eventType: 'journal_reversed', sourceType: 'journal',
337 + sourceId: id, commandKey: 'manual-reversal:' + originalId, businessDate: date,
338 + lineCount: lines.length });
339 return journal;
340 });
341 }
src/core/AuditService.js new
+56
@@ -0,0 +1,56 @@
1 +import { Auth } from './Auth.js';
2 +import { DataScope } from './DataScope.js';
3 +import { StorageService } from './StorageService.js';
4 +
5 +const VALID_TYPES = new Set([
6 + 'journal_posted', 'journal_reversed', 'period_closed',
7 + 'commercial_journal_posted', 'draft_posted', 'draft_updated',
8 + 'draft_discarded', 'period_opened'
9 +]);
10 +const validId = value => typeof value === 'string' && value.trim().length > 0;
11 +
12 +class AuditServiceImpl {
13 + /**
14 + * Must execute INSIDE the same readwrite IndexedDB transaction as the
15 + * audited business operation. Never call StorageService.put separately.
16 + */
17 + async append(tx, { companyId, eventType, sourceType, sourceId,
18 + commandKey, businessDate = null, correlationId, lineCount = 0 }) {
19 + const actorId = Auth.current()?.id;
20 + if (!validId(companyId) || !validId(actorId) ||
21 + !VALID_TYPES.has(eventType) || !validId(sourceType) ||
22 + !validId(sourceId) || !validId(commandKey) ||
23 + !Number.isSafeInteger(lineCount) || lineCount < 0) {
24 + throw new Error('داده رویداد ممیزی نامعتبر است');
25 + }
26 + const event = {
27 + id: StorageService.uid('audit_'), companyId, actorId,
28 + eventType, sourceType, sourceId,
29 + occurredAtUtc: new Date().toISOString(), businessDate,
30 + correlationId: validId(correlationId) ? correlationId : StorageService.uid('corr_'),
31 + commandKey: companyId + ':' + commandKey,
32 + schemaVersion: 1, documentVersion: 1,
33 + result: 'committed', createdByService: true,
34 + // No customer name, phone, free-text description, secrets or bank details.
35 + safeSummary: { lineCount }
36 + };
37 + // add() cannot overwrite an earlier event and a unique commandKey makes
38 + // replay fail atomically. No externally mutable audit status is stored.
39 + await tx.add('audit_events', event);
40 + return event;
41 + }
42 +
43 + async list({ limit = 100 } = {}) {
44 + if (!Auth.isAdmin()) throw new Error('مشاهده ردپای حسابرسی فقط برای مدیر مجاز است');
45 + if (!Number.isSafeInteger(limit) || limit < 1 || limit > 500) {
46 + throw new RangeError('محدودیت نمایش رویداد ممیزی نامعتبر است');
47 + }
48 + const companyId = await DataScope.companyId();
49 + const events = await StorageService.getAllByIndex('audit_events', 'companyId', companyId);
50 + // Read-only company scope; no user secrets or private payloads in these events.
51 + return events.sort((a, b) =>
52 + String(b.occurredAtUtc).localeCompare(String(a.occurredAtUtc)) ||
53 + String(b.id).localeCompare(String(a.id))).slice(0, limit);
54 + }
55 +}
56 +export const AuditService = new AuditServiceImpl();
src/core/CompanyBackupService.js
+15 -2
@@ -9,7 +9,8 @@ export const COMPANY_BACKUP_STORES = Object.freeze([
9 'invoices', 'invoice_items', 'stock_movements', 'transactions',
10 'cheques', 'expenses', 'account_chart', 'fiscal_periods',
11 'journal_entries', 'journal_lines', 'warehouses', 'inventory_balances',
12 - 'stocktakes', 'stocktake_lines', 'settlements', 'account_mappings'
12 + 'stocktakes', 'stocktake_lines', 'settlements', 'account_mappings',
13 + 'audit_events', 'document_corrections'
14 ]);
15 const V2_STORES = new Set(['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines']);
16 const isId = id => typeof id === 'string' && id.trim().length > 0;
@@ -38,8 +39,13 @@ export async function restoreCompanyBackup(data, { companyId, userId, mode = 'me
39 return StorageService.transaction([...COMPANY_BACKUP_STORES, 'settings'], async tx => {
40 for (const store of COMPANY_BACKUP_STORES) {
41 for (const incoming of data[store] || []) {
42 + const immutable = store === 'audit_events' || store === 'document_corrections';
43 + // Historical audit/correction events cannot be reassigned to a new company.
44 + if (immutable && incoming.companyId !== companyId) {
45 + throw new Error('رویداد ممیزی یا اصلاح سند متعلق به شرکت دیگری است');
46 + }
47 const row = { ...incoming, companyId };
42 - if (row.ownerUserId) row.ownerUserId = userId;
48 + if (row.ownerUserId && !immutable) row.ownerUserId = userId;
49 if (store === 'journal_entries' && row.sourceType && row.sourceId) {
50 row.sourceKey = journalSourceKey(companyId, row.sourceType, row.sourceId, row.revision || 1);
51 }
@@ -47,6 +53,13 @@ export async function restoreCompanyBackup(data, { companyId, userId, mode = 'me
53 if (existing && existing.companyId !== companyId) {
54 throw new Error(`شناسه رکورد ${store}/${row.id} متعلق به شرکت دیگر است؛ بازیابی متوقف شد`);
55 }
56 + if (existing && immutable) {
57 + if (JSON.stringify(existing) !== JSON.stringify(row)) {
58 + throw new Error('بازنویسی سابقه ممیزی یا اصلاح سند مجاز نیست');
59 + }
60 + counts.skipped++;
61 + continue;
62 + }
63 if (existing && mode === 'merge') {
64 counts.skipped++;
65 continue;
src/core/RetailPostingService.js
+7 -1
@@ -2,6 +2,7 @@
2 import { StorageService } from './StorageService.js';
3 import { DataScope } from './DataScope.js';
4 import { Auth } from './Auth.js';
5 +import { AuditService } from './AuditService.js';
6 import { validateJournal, journalSourceKey, assertJalaliDate } from './AccountingCore.mjs';
7 import { previewSaleReturnSettlement } from './ReturnSettlementCore.mjs';
8 import { LEDGER_CODES, INVOICE_DIRECTIONS, amount, positiveAmount,
@@ -12,7 +13,8 @@ export const FINANCE_STORES = Object.freeze([
13 'account_chart','fiscal_periods','journal_entries','journal_lines',
14 'invoices','invoice_items','stock_movements','products','contacts','treasury',
15 'warehouses','inventory_balances','stocktakes','stocktake_lines',
15 - 'settlements','expenses','cheques','settings','account_mappings'
16 + 'settlements','expenses','cheques','settings','account_mappings',
17 + 'audit_events'
18 ]);
19 const uid=p=>StorageService.uid(p);
20 const actor=()=>Auth.current()?.id||null;
@@ -191,6 +193,10 @@ class RetailPostingServiceImpl {
193 await tx.put('journal_lines',{...line,id:uid('jl_'),journalId:journal.id,
194 companyId:ctx.companyId,position});
195 }
196 + await AuditService.append(tx, { companyId: ctx.companyId,
197 + eventType: 'commercial_journal_posted', sourceType: kind, sourceId: journal.id,
198 + commandKey: 'retail-journal:' + key, businessDate: ctx.date,
199 + lineCount: filtered.length });
200 return journal;
201 }
202 async stock(tx,ctx,warehouseId,item,direction,costValue,refId,refType='invoice') {
src/core/StorageService.js
+7 -3
@@ -4,7 +4,7 @@
4 // ============================================================
5
6 const DB_NAME = 'finora_pro_db';
7 -const DB_VERSION = 6;
7 +const DB_VERSION = 7;
8
9 const STORES = [
10 'users', 'companies', 'contacts', 'products',
@@ -15,7 +15,8 @@ const STORES = [
15 'settings', 'logs',
16 'account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines',
17 'warehouses', 'inventory_balances', 'stocktakes', 'stocktake_lines',
18 - 'settlements', 'account_mappings'
18 + 'settlements', 'account_mappings',
19 + 'audit_events', 'document_corrections'
20 ];
21
22 // جدول‌هایی که ایندکس ownerUserId ندارند
@@ -35,7 +36,9 @@ const INDEXES = {
36 stocktakes: [['companyId', 'companyId'], ['warehouseId', 'warehouseId']],
37 stocktake_lines: [['companyId', 'companyId'], ['stocktakeId', 'stocktakeId']],
38 settlements: [['companyId', 'companyId'], ['invoiceId', 'invoiceId'], ['transactionId', 'transactionId']],
38 - account_mappings: [['companyId', 'companyId']]
39 + account_mappings: [['companyId', 'companyId']],
40 + audit_events: [['companyId', 'companyId'], ['sourceId', 'sourceId'], ['correlationId', 'correlationId'], ['commandKey', 'commandKey', { unique: true }]],
41 + document_corrections: [['companyId', 'companyId'], ['sourceId', 'sourceId'], ['idempotencyKey', 'idempotencyKey', { unique: true }]]
42 };
43
44 // فیلدهای مربوط به رمز عبور کاربران؛ هرگز در فایل پشتیبان نمی‌روند
@@ -181,6 +184,7 @@ class StorageServiceImpl {
184 count: (s) => wrap(os(s).count()),
185 put: (s, obj) => { this._touch(obj); return wrap(os(s).put(obj)).then(() => obj); },
186 putRaw: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(os(s).put(obj)).then(() => obj); },
187 + add: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(os(s).add(obj)).then(() => obj); },
188 delete: (s, id) => wrap(os(s).delete(id)).then(() => undefined),
189 clear: (s) => wrap(os(s).clear()).then(() => undefined)
190 };
tests/a03-audit-integration.test.mjs new
+112
@@ -0,0 +1,112 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import 'fake-indexeddb/auto';
4 +import { StorageService } from '../src/core/StorageService.js';
5 +import { AuditService } from '../src/core/AuditService.js';
6 +import { AccountingService } from '../src/core/AccountingService.js';
7 +import { SettingsController } from '../src/controllers/SettingsController.js';
8 +import { Auth } from '../src/core/Auth.js';
9 +import { CompanyService } from '../src/core/CompanyService.js';
10 +
11 +const company = 'audit-c1';
12 +const businessDate = '1405/07/18';
13 +async function setup() {
14 + await StorageService.clearAll();
15 + Auth.currentUser = { id: 'audit-admin', role: 'admin', username: 'manager' };
16 + await StorageService.put('companies', { id: company, name: 'Synthetic C1' });
17 + await StorageService.put('companies', { id: 'audit-c2', name: 'Synthetic C2' });
18 + CompanyService.activeCompanyId = company;
19 + const period = await AccountingService.createPeriod({
20 + name: '1405', startDate: '1405/01/01', endDate: '1405/12/29'
21 + });
22 + await AccountingService.seedDefaultChart();
23 + const accounts = await AccountingService.listAccounts();
24 + const cash = accounts.find(a => a.code === '101');
25 + const sales = accounts.find(a => a.code === '401');
26 + assert.ok(cash && sales);
27 + return { period, cash, sales };
28 +}
29 +const journal = ({ period, cash, sales }) => ({
30 + periodId: period.id, date: businessDate,
31 + description: 'Sensitive customer name that must not enter audit',
32 + lines: [
33 + { accountId: cash.id, debit: 1000, credit: 0 },
34 + { accountId: sales.id, debit: 0, credit: 1000 }
35 + ]
36 +});
37 +
38 +test('A03: posting and reversal produce immutable-in-service, scoped, minimal audit records', async () => {
39 + const state = await setup();
40 + const posted = await AccountingService.postJournal(journal(state));
41 + let events = await AuditService.list();
42 + assert.equal(events.length, 1);
43 + assert.equal(events[0].eventType, 'journal_posted');
44 + assert.equal(events[0].actorId, 'audit-admin');
45 + assert.equal(events[0].companyId, company);
46 + assert.equal(events[0].sourceId, posted.id);
47 + assert.equal(events[0].safeSummary.lineCount, 2);
48 + assert.equal(events[0].result, 'committed');
49 + assert.ok(!JSON.stringify(events).includes('Sensitive customer name'));
50 +
51 + const reversed = await AccountingService.reverseJournal(posted.id, {
52 + periodId: state.period.id, date: '1405/07/19'
53 + });
54 + events = await AuditService.list();
55 + assert.equal(events.length, 2);
56 + assert.ok(events.some(e => e.eventType === 'journal_reversed' && e.sourceId === reversed.id));
57 + await assert.rejects(AccountingService.reverseJournal(posted.id, {
58 + periodId: state.period.id, date: '1405/07/20'
59 + }), /قابل برگشت/);
60 + assert.equal((await AuditService.list()).length, 2);
61 +
62 + CompanyService.activeCompanyId = 'audit-c2';
63 + assert.deepEqual(await AuditService.list(), []);
64 + Auth.currentUser = { id: 'staff', role: 'user', companyIds: ['audit-c2'] };
65 + await assert.rejects(AuditService.list(), /مدیر/);
66 +});
67 +
68 +test('A03: duplicate audit command aborts unrelated financial writes atomically', async () => {
69 + await setup();
70 + const event = {
71 + companyId: company, eventType: 'journal_posted',
72 + sourceType: 'journal', sourceId: 'source-1',
73 + commandKey: 'request-1', businessDate
74 + };
75 + await StorageService.transaction(['audit_events'], tx => AuditService.append(tx, event));
76 + await assert.rejects(StorageService.transaction(['audit_events', 'products'], async tx => {
77 + await tx.put('products', { id: 'never-written', companyId: company, name: 'rollback' });
78 + await AuditService.append(tx, event);
79 + }));
80 + assert.equal(await StorageService.get('products', 'never-written'), undefined);
81 + assert.equal((await AuditService.list()).length, 1);
82 +});
83 +
84 +test('A03: fiscal closing appends an event and does not permit double close', async () => {
85 + const { period } = await setup();
86 + await AccountingService.closePeriod(period.id);
87 + const events = await AuditService.list();
88 + assert.equal(events.length, 1);
89 + assert.equal(events[0].eventType, 'period_closed');
90 + await assert.rejects(AccountingService.closePeriod(period.id), /بسته/);
91 + assert.equal((await AuditService.list()).length, 1);
92 +});
93 +
94 +test('A03: company backup includes audit store, without ever exporting user credentials', async () => {
95 + const state = await setup();
96 + await AccountingService.postJournal(journal(state));
97 + const backup = await StorageService.exportAll();
98 + assert.equal(backup.version, 7);
99 + assert.equal(backup.data.audit_events.length, 1);
100 + assert.ok(Array.isArray(backup.data.document_corrections));
101 + assert.equal(backup.data.audit_events[0].safeSummary.lineCount, 2);
102 +});
103 +
104 +test('A03: company backup rejects tampered historical audit records even in replace mode', async () => {
105 + const state = await setup();
106 + await AccountingService.postJournal(journal(state));
107 + const backup = await SettingsController.exportBackup();
108 + assert.equal(backup.data.audit_events.length, 1);
109 + backup.data.audit_events[0].eventType = 'period_closed';
110 + await assert.rejects(SettingsController.importBackup(backup, { mode: 'replace' }), /بازنویسی سابقه/);
111 + assert.equal((await AuditService.list())[0].eventType, 'journal_posted');
112 +});
tests/a03-v7-migration.test.mjs new
+36
@@ -0,0 +1,36 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import 'fake-indexeddb/auto';
4 +import { StorageService } from '../src/core/StorageService.js';
5 +
6 +test('A03 migration: v6 invoices and ledgers survive an additive v7 upgrade', async () => {
7 + const raw = await new Promise((resolve, reject) => {
8 + const req = indexedDB.open('finora_pro_db', 6);
9 + req.onupgradeneeded = () => {
10 + const db = req.result;
11 + db.createObjectStore('invoices', { keyPath: 'id' })
12 + .put({ id: 'before-upgrade', companyId: 'c1', grandTotal: 1550 });
13 + db.createObjectStore('journal_entries', { keyPath: 'id' })
14 + .put({ id: 'historic-journal', companyId: 'c1', status: 'posted' });
15 + };
16 + req.onsuccess = () => resolve(req.result);
17 + req.onerror = () => reject(req.error);
18 + });
19 + raw.close();
20 +
21 + const db = await StorageService.init();
22 + assert.equal(db.version, 7);
23 + assert.equal((await StorageService.get('invoices', 'before-upgrade')).grandTotal, 1550);
24 + assert.equal((await StorageService.get('journal_entries', 'historic-journal')).status, 'posted');
25 + assert.ok(db.objectStoreNames.contains('audit_events'));
26 + assert.ok(db.objectStoreNames.contains('document_corrections'));
27 + assert.equal((await StorageService.getAll('audit_events')).length, 0,
28 + 'Existing records must not be falsely presented as historically audited');
29 +
30 + // A v6 snapshot is accepted by the v7 importer without fabricating audit events.
31 + const legacy = { app: 'Factor-easyPro', version: 6,
32 + data: { products: [{ id: 'old-stock', companyId: 'c1', name: 'Old stock' }] } };
33 + await StorageService.importAll(legacy);
34 + assert.equal((await StorageService.get('products', 'old-stock')).name, 'Old stock');
35 + assert.equal((await StorageService.getAll('audit_events')).length, 0);
36 +});
tests/accounting-migration.test.mjs
+1 -1
@@ -17,7 +17,7 @@ test('migration: upgrading legacy IndexedDB v4 preserves invoices and creates V2
17 });
18 db.close();
19 const upgraded = await StorageService.init();
20 - assert.equal(upgraded.version, 6);
20 + assert.equal(upgraded.version, 7);
21 assert.deepEqual((await StorageService.get('invoices', 'legacy-inv-1')).number, 120);
22 assert.equal((await StorageService.get('products', 'legacy-product')).name, 'کالای قبلی');
23 for (const name of ['account_chart', 'fiscal_periods', 'journal_entries', 'journal_lines']) {
tests/backup-restore-integration.test.mjs
+2 -2
@@ -22,7 +22,7 @@ test('A04: an actual IndexedDB company backup round-trip restores records', asyn
22 await StorageService.put('contacts', { id: 'customer-2', companyId: 'c2', name: 'Other company' });
23 const backup = await SettingsController.exportBackup();
24 assert.equal(backup.scope, 'company');
25 - assert.equal(backup.schemaVersion, 6);
25 + assert.equal(backup.schemaVersion, 7);
26 await StorageService.delete('contacts', 'customer-1');
27 assert.equal(await StorageService.get('contacts', 'customer-1'), undefined);
28 const result = await SettingsController.importBackup(JSON.stringify(backup));
@@ -38,7 +38,7 @@ test('A04: malformed or future company backup envelopes never modify IndexedDB',
38 { ...example, app: 'unknown' },
39 { ...example, app: undefined },
40 { ...example, scope: 'global' },
41 - { ...example, schemaVersion: 7 },
41 + { ...example, schemaVersion: 8 },
42 { ...example, schemaVersion: '6' },
43 { ...example, schemaVersion: undefined },
44 { ...example, companyId: '' },
tests/retail-migration.test.mjs
+1 -1
@@ -22,7 +22,7 @@ test('V2 schema upgrade from phase-one v5 preserves ledgers, stock and people',a
22 });
23 raw.close();
24 const db=await StorageService.init();
25 - assert.equal(db.version,6);
25 + assert.equal(db.version,7);
26 assert.equal((await StorageService.get('invoices','old-finance-inv')).number,'119');
27 assert.equal((await StorageService.get('journal_entries','old-journal')).debit,100);
28 for(const store of ['warehouses','inventory_balances','stocktakes','stocktake_lines',