fix: correct timestamp/boolean types for PostgreSQL schema (Date not int, bool not 0/1)
This commit is contained in:
parent
e00bd4d804
commit
69634909d1
9 changed files with 75 additions and 131 deletions
|
|
@ -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++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue