Skip to content

Commit e49ea8f

Browse files
committed
refactor: use migration endpoint instead of script
1 parent 6415448 commit e49ea8f

4 files changed

Lines changed: 41 additions & 59 deletions

File tree

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ RUN apk add --no-cache sqlite
3131
COPY --from=deps /app/node_modules ./node_modules
3232
COPY --from=build /app/src ./src
3333
COPY --from=build /app/prisma ./prisma
34-
COPY --from=build /app/scripts ./scripts
3534
COPY --from=build /app/package.json ./package.json
3635

3736
# Create storage and analytics data directories

scripts/migrate-telemetry-to-duckdb.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/analytics.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DuckDBInstance, type DuckDBValue } from "@duckdb/node-api";
22
import type { SystemInfoPayload } from "@/schemas/telemetry.js";
3+
import { prisma } from "@/db.js";
34

45
const DB_PATH = process.env.ANALYTICS_DB_PATH || "./analytics.duckdb";
56

@@ -103,6 +104,40 @@ export async function upsertSystemInfo(
103104
);
104105
}
105106

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+
106141
export async function deleteUserData(userId: string) {
107142
const conn = getConnection();
108143
await conn.run(

src/routes/v1/admin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
queryRawRows,
55
queryStats,
66
queryAnalytics,
7+
migrateFromSqlite,
78
VALID_GRANULARITIES,
89
ALLOWED_FILTERS,
910
type Granularity,
@@ -71,4 +72,9 @@ admin.get("/analytics", async (c) => {
7172
return c.json({ data, filters, granularity, periods });
7273
});
7374

75+
admin.post("/telemetry/migrate", async (c) => {
76+
const result = await migrateFromSqlite();
77+
return c.json(result);
78+
});
79+
7480
export default admin;

0 commit comments

Comments
 (0)