|
1 | 1 | import { DuckDBInstance, type DuckDBValue } from "@duckdb/node-api"; |
2 | 2 | import type { SystemInfoPayload } from "@/schemas/telemetry.js"; |
| 3 | +import { prisma } from "@/db.js"; |
3 | 4 |
|
4 | 5 | const DB_PATH = process.env.ANALYTICS_DB_PATH || "./analytics.duckdb"; |
5 | 6 |
|
@@ -103,6 +104,40 @@ export async function upsertSystemInfo( |
103 | 104 | ); |
104 | 105 | } |
105 | 106 |
|
| 107 | +export async function migrateFromSqlite() { |
| 108 | + const rows = await prisma.telemetrySystemInfo.findMany(); |
| 109 | + if (rows.length === 0) { |
| 110 | + return { migrated: 0, message: "No rows to migrate." }; |
| 111 | + } |
| 112 | + |
| 113 | + let migrated = 0; |
| 114 | + for (const row of rows) { |
| 115 | + const desktops = JSON.parse(row.desktops) as string[]; |
| 116 | + const screens = JSON.parse(row.screens); |
| 117 | + |
| 118 | + await upsertSystemInfo({ |
| 119 | + userId: row.userId, |
| 120 | + date: row.date, |
| 121 | + desktops, |
| 122 | + vicinaeVersion: row.vicinaeVersion, |
| 123 | + displayProtocol: row.displayProtocol, |
| 124 | + architecture: row.architecture, |
| 125 | + operatingSystem: row.operatingSystem, |
| 126 | + buildProvenance: row.buildProvenance, |
| 127 | + locale: row.locale, |
| 128 | + screens, |
| 129 | + chassisType: row.chassisType, |
| 130 | + kernelVersion: row.kernelVersion, |
| 131 | + productId: row.productId, |
| 132 | + productVersion: row.productVersion, |
| 133 | + qtVersion: row.qtVersion ?? undefined, |
| 134 | + }); |
| 135 | + migrated++; |
| 136 | + } |
| 137 | + |
| 138 | + return { migrated, message: `Migrated ${migrated} rows from SQLite to DuckDB.` }; |
| 139 | +} |
| 140 | + |
106 | 141 | export async function deleteUserData(userId: string) { |
107 | 142 | const conn = getConnection(); |
108 | 143 | await conn.run( |
|
0 commit comments