fix: remove old stale data
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
2026-10-22 01:32:19 +02:00
parent cef6ee5820
commit 48ad82acd1
5 changed files with 69 additions and 60 deletions
+33 -15
View File
@@ -5,13 +5,41 @@ const crypto = require('crypto');
const prisma = new PrismaClient();
// One line with itemCount units, priced so the tab adds up to about totalInCents
async function createTab(venueId, tab) {
const lineId = uuidv4();
const addedAt = tab.reportedAt.toISOString();
await prisma.tab.create({
data: {
venueId,
id: tab.tabId,
customerName: tab.customerName,
openedAt: tab.reportedAt,
version: tab.version,
lines: [{
id: lineId,
productId: null,
productName: 'Pils',
unitPriceInCents: Math.round(tab.totalInCents / tab.itemCount),
units: Array.from({ length: tab.itemCount }, (_, i) => ({ id: `${lineId}:${i}`, addedAt, removedAt: null })),
}],
},
});
}
async function main() {
console.log('Seeding database...');
await prisma.auditLog.deleteMany();
await prisma.tabEvent.deleteMany();
await prisma.tabReminder.deleteMany();
await prisma.plannedTab.deleteMany();
await prisma.remoteCommand.deleteMany();
await prisma.openTabSnapshot.deleteMany();
await prisma.tabOwnership.deleteMany();
await prisma.settlement.deleteMany();
await prisma.tab.deleteMany();
await prisma.stockAdjustment.deleteMany();
await prisma.product.deleteMany();
await prisma.productImage.deleteMany();
await prisma.refreshToken.deleteMany();
await prisma.registrationCode.deleteMany();
await prisma.device.deleteMany();
@@ -92,12 +120,7 @@ async function main() {
];
for (const tab of tabsData) {
await prisma.tabOwnership.create({
data: { tabId: tab.tabId, venueId, deviceId: device1Id, lastReportedAt: tab.reportedAt },
});
await prisma.openTabSnapshot.create({
data: { deviceId: device1Id, tabId: tab.tabId, customerName: tab.customerName, version: tab.version, totalInCents: tab.totalInCents, itemCount: tab.itemCount, reportedAt: tab.reportedAt },
});
await createTab(venueId, tab);
}
const staleTabs = [
@@ -106,15 +129,10 @@ async function main() {
];
for (const tab of staleTabs) {
await prisma.tabOwnership.create({
data: { tabId: tab.tabId, venueId, deviceId: device2Id, lastReportedAt: tab.reportedAt },
});
await prisma.openTabSnapshot.create({
data: { deviceId: device2Id, tabId: tab.tabId, customerName: tab.customerName, version: tab.version, totalInCents: tab.totalInCents, itemCount: tab.itemCount, reportedAt: tab.reportedAt },
});
await createTab(venueId, tab);
}
console.log('Created 6 open tabs across 2 devices');
console.log('Created 6 open tabs');
const now = new Date();