feat: add charts table schema and migration with data backfill
- Add charts table with id, name (unique), created_at - Add chart_id FK to candles table with composite unique on (chart_id, time) - Add chart_id FK to annotations table - Custom migration handles existing data: creates 'Imported Data' chart and backfills chart_id - Recreates tables for NOT NULL constraint (SQLite limitation)
This commit is contained in:
parent
178834f3b2
commit
92d3339a48
14 changed files with 913 additions and 3 deletions
|
|
@ -1,13 +1,22 @@
|
|||
import { sqliteTable, integer, real, text } from 'drizzle-orm/sqlite-core';
|
||||
import { sqliteTable, integer, real, text, uniqueIndex } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
export const charts = sqliteTable('charts', {
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
name: text('name').notNull().unique(),
|
||||
created_at: integer('created_at').notNull(),
|
||||
});
|
||||
|
||||
export const candles = sqliteTable('candles', {
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
time: integer('time').notNull().unique(),
|
||||
chart_id: integer('chart_id').notNull().references(() => charts.id),
|
||||
time: integer('time').notNull(),
|
||||
open: real('open').notNull(),
|
||||
high: real('high').notNull(),
|
||||
low: real('low').notNull(),
|
||||
close: real('close').notNull(),
|
||||
});
|
||||
}, (table) => [
|
||||
uniqueIndex('candles_chart_time_unique').on(table.chart_id, table.time),
|
||||
]);
|
||||
|
||||
export const annotationTypes = sqliteTable('annotation_types', {
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
|
|
@ -22,6 +31,7 @@ export const annotationTypes = sqliteTable('annotation_types', {
|
|||
|
||||
export const annotations = sqliteTable('annotations', {
|
||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||
chart_id: integer('chart_id').notNull().references(() => charts.id),
|
||||
timestamp: integer('timestamp').notNull(),
|
||||
label_type: text('label_type').notNull(),
|
||||
geometry: text('geometry'), // JSON string for line coordinates
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue