fix: correct timestamp/boolean types for PostgreSQL schema (Date not int, bool not 0/1)

This commit is contained in:
Marko Djordjevic 2026-02-17 22:50:31 +01:00
parent e00bd4d804
commit 69634909d1
9 changed files with 75 additions and 131 deletions

View file

@ -93,9 +93,9 @@ async function ensureLabelTypes(labels: string[]): Promise<LabelTypeMap> {
display_name: label,
color,
hotkey: null,
is_active: 1,
is_active: true,
sort_order: sortOrder++,
created_at: Math.floor(Date.now() / 1000),
created_at: new Date(),
}).returning();
labelMap[label] = {
@ -135,8 +135,8 @@ async function importAnnotations(
try {
await db.insert(spanAnnotations).values({
chart_id: chartId,
start_time: ann.start_time,
end_time: ann.end_time,
start_time: new Date(ann.start_time * 1000),
end_time: new Date(ann.end_time * 1000),
label: ann.label,
confidence: ann.confidence || null,
outcome: null,
@ -145,7 +145,7 @@ async function importAnnotations(
color: labelInfo.color,
source: ann.source || 'programmatic',
model_prediction: null,
created_at: Math.floor(Date.now() / 1000),
created_at: new Date(),
});
imported++;

View file

@ -19,7 +19,7 @@ async function main() {
} else {
console.log(`Found ${allCharts.length} chart(s):\n`);
for (const chart of allCharts) {
const date = new Date(chart.created_at * 1000).toISOString();
const date = chart.created_at.toISOString();
console.log(` ID: ${chart.id}`);
console.log(` Name: ${chart.name}`);
console.log(` Created: ${date}`);

View file

@ -79,8 +79,13 @@ const stats: MigrationStats[] = [];
/**
* Convert SQLite integer timestamp (Unix seconds) to JavaScript Date
*/
function sqliteTimestampToDate(timestamp: number | null): Date | null {
if (!timestamp) return null;
function sqliteTimestampToDate(timestamp: number | null): Date | undefined {
if (!timestamp) return undefined;
return new Date(timestamp * 1000);
}
function sqliteTimestampToDateRequired(timestamp: number | null): Date {
if (!timestamp) throw new Error(`Required timestamp is null/zero: ${timestamp}`);
return new Date(timestamp * 1000);
}
@ -157,7 +162,7 @@ async function migrateCharts() {
await pg.insert(schema.charts).values({
id: row.id,
name: row.name,
created_at: sqliteTimestampToDate(row.created_at),
created_at: sqliteTimestampToDateRequired(row.created_at),
});
migrated++;
@ -201,7 +206,7 @@ async function migrateCandles() {
await pg.insert(schema.candles).values({
id: row.id,
chart_id: row.chart_id,
time: sqliteTimestampToDate(row.time),
time: sqliteTimestampToDateRequired(row.time),
open: row.open,
high: row.high,
low: row.low,
@ -254,7 +259,7 @@ async function migrateAnnotationTypes() {
category: row.category,
icon: row.icon,
is_active: sqliteBooleanToBoolean(row.is_active),
created_at: sqliteTimestampToDate(row.created_at),
created_at: sqliteTimestampToDateRequired(row.created_at),
});
migrated++;
@ -298,11 +303,11 @@ async function migrateAnnotations() {
await pg.insert(schema.annotations).values({
id: row.id,
chart_id: row.chart_id,
timestamp: sqliteTimestampToDate(row.timestamp),
timestamp: sqliteTimestampToDateRequired(row.timestamp),
label_type: row.label_type,
geometry: sqliteJsonToObject(row.geometry),
color: row.color || '#3b82f6',
created_at: sqliteTimestampToDate(row.created_at),
created_at: sqliteTimestampToDateRequired(row.created_at),
});
migrated++;
@ -351,7 +356,7 @@ async function migrateSpanLabelTypes() {
hotkey: row.hotkey,
is_active: sqliteBooleanToBoolean(row.is_active),
sort_order: row.sort_order || 0,
created_at: sqliteTimestampToDate(row.created_at),
created_at: sqliteTimestampToDateRequired(row.created_at),
});
migrated++;
@ -395,8 +400,8 @@ async function migrateSpanAnnotations() {
await pg.insert(schema.spanAnnotations).values({
id: row.id,
chart_id: row.chart_id,
start_time: sqliteTimestampToDate(row.start_time),
end_time: sqliteTimestampToDate(row.end_time),
start_time: sqliteTimestampToDateRequired(row.start_time),
end_time: sqliteTimestampToDateRequired(row.end_time),
label: row.label,
confidence: row.confidence,
outcome: row.outcome,
@ -405,7 +410,7 @@ async function migrateSpanAnnotations() {
color: row.color || '#2196F3',
source: row.source || 'human',
model_prediction: sqliteJsonToObject(row.model_prediction),
created_at: sqliteTimestampToDate(row.created_at),
created_at: sqliteTimestampToDateRequired(row.created_at),
});
migrated++;