@rawdash/adapter-libsql 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/libsql-storage.ts","../src/migrations-bundle.ts","../src/migrate.ts"],"sourcesContent":["import type { Client, InValue } from '@libsql/client/web';\nimport type {\n Distribution,\n DistributionQuery,\n Edge,\n EdgeQuery,\n Entity,\n EntityQuery,\n Event,\n EventQuery,\n JSONValue,\n MetricQuery,\n MetricSample,\n ServerStorage,\n StorageHandle,\n SyncState,\n} from '@rawdash/core';\nimport { type CompiledQuery, type Insertable, Kysely } from 'kysely';\nimport { LibsqlDialect } from 'kysely-libsql';\n\nimport type {\n Database,\n EdgesTable,\n EntitiesTable,\n EventsTable,\n MetricsTable,\n} from './db-schema';\nimport { applyMigrations } from './migrate';\n\ntype Attrs = Record<string, JSONValue>;\n\nconst SYNC_STATE_ID = 1;\n\nexport async function initLibsqlSchema(client: Client): Promise<void> {\n await applyMigrations(client);\n await client.execute({\n sql: \"INSERT OR IGNORE INTO sync_state (id, status, last_sync_at, last_error) VALUES (?, 'idle', NULL, NULL)\",\n args: [SYNC_STATE_ID],\n });\n}\n\nfunction parseJson<T>(value: unknown, fallback: T): T {\n if (typeof value !== 'string') {\n return fallback;\n }\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction createDb(client: Client): Kysely<Database> {\n return new Kysely<Database>({\n dialect: new LibsqlDialect({ client }),\n });\n}\n\nfunction toBatchStmt(q: CompiledQuery): { sql: string; args: InValue[] } {\n return { sql: q.sql, args: q.parameters as InValue[] };\n}\n\nexport interface LibsqlStorageOptions {\n client: Client;\n initSchema?: boolean;\n}\n\nexport class LibsqlStorage implements ServerStorage {\n private client: Client;\n private db: Kysely<Database>;\n private ready: Promise<void>;\n private initError: string | null = null;\n\n constructor(options: LibsqlStorageOptions) {\n this.client = options.client;\n this.db = createDb(options.client);\n this.ready = options.initSchema === false ? Promise.resolve() : this.init();\n }\n\n private async init(): Promise<void> {\n try {\n await initLibsqlSchema(this.client);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n this.initError = `init failed: ${message}`;\n throw err;\n }\n }\n\n async waitUntilReady(): Promise<void> {\n return this.ready;\n }\n\n getStorageHandle(connectorId: string): StorageHandle {\n const ready = this.ready;\n const db = this.db;\n const client = this.client;\n\n const eventRow = (e: Event): Insertable<EventsTable> => ({\n connector_id: connectorId,\n name: e.name,\n start_ts: e.start_ts,\n end_ts: e.end_ts,\n attributes: JSON.stringify(e.attributes),\n });\n\n const entityRow = (e: Entity): Insertable<EntitiesTable> => ({\n connector_id: connectorId,\n type: e.type,\n id: e.id,\n attributes: JSON.stringify(e.attributes),\n updated_at: e.updated_at,\n });\n\n const metricRow = (m: MetricSample): Insertable<MetricsTable> => ({\n connector_id: connectorId,\n name: m.name,\n ts: m.ts,\n value: m.value,\n attributes: JSON.stringify(m.attributes),\n });\n\n const edgeRow = (e: Edge): Insertable<EdgesTable> => ({\n connector_id: connectorId,\n from_type: e.from_type,\n from_id: e.from_id,\n kind: e.kind,\n to_type: e.to_type,\n to_id: e.to_id,\n attributes: JSON.stringify(e.attributes),\n updated_at: e.updated_at,\n });\n\n const distributionRow = (d: Distribution) => ({\n connector_id: connectorId,\n name: d.name,\n ts: d.ts,\n kind: d.kind,\n data: JSON.stringify(d.data),\n attributes: JSON.stringify(d.attributes),\n });\n\n return {\n event: async (e) => {\n await ready;\n await db.insertInto('events').values(eventRow(e)).execute();\n },\n\n entity: async (e) => {\n await ready;\n await db\n .insertInto('entities')\n .values(entityRow(e))\n .onConflict((oc) =>\n oc.columns(['connector_id', 'type', 'id']).doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .execute();\n },\n\n metric: async (m) => {\n await ready;\n await db.insertInto('metrics').values(metricRow(m)).execute();\n },\n\n edge: async (e) => {\n await ready;\n await db\n .insertInto('edges')\n .values(edgeRow(e))\n .onConflict((oc) =>\n oc\n .columns([\n 'connector_id',\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n ])\n .doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .execute();\n },\n\n distribution: async (d) => {\n await ready;\n await db\n .insertInto('distributions')\n .values(distributionRow(d))\n .execute();\n },\n\n events: async (es, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? es.map((e) => e.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('events')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db.insertInto('events').values(es.map(eventRow)).compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n entities: async (es, scope) => {\n await ready;\n const types = Array.from(\n new Set(scope?.types ?? es.map((e) => e.type)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (types.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('entities')\n .where('connector_id', '=', connectorId)\n .where('type', 'in', types)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('entities')\n .values(es.map(entityRow))\n .onConflict((oc) =>\n oc.columns(['connector_id', 'type', 'id']).doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n metrics: async (ms, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? ms.map((m) => m.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('metrics')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (ms.length > 0) {\n stmts.push(\n toBatchStmt(\n db.insertInto('metrics').values(ms.map(metricRow)).compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n edges: async (es, scope) => {\n await ready;\n const kinds = Array.from(\n new Set(scope?.kinds ?? es.map((e) => e.kind)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (kinds.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('edges')\n .where('connector_id', '=', connectorId)\n .where('kind', 'in', kinds)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('edges')\n .values(es.map(edgeRow))\n .onConflict((oc) =>\n oc\n .columns([\n 'connector_id',\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n ])\n .doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n distributions: async (ds, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? ds.map((d) => d.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('distributions')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (ds.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('distributions')\n .values(ds.map(distributionRow))\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n queryEvents: async (q: EventQuery) => {\n await ready;\n let qb = db\n .selectFrom('events')\n .select(['name', 'start_ts', 'end_ts', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('start_ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('start_ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): Event => ({\n name: r.name,\n start_ts: Number(r.start_ts),\n end_ts: r.end_ts === null ? null : Number(r.end_ts),\n attributes: parseJson<Attrs>(r.attributes, {}),\n }),\n );\n },\n\n getEntity: async (type, id) => {\n await ready;\n const r = await db\n .selectFrom('entities')\n .select(['type', 'id', 'attributes', 'updated_at'])\n .where('connector_id', '=', connectorId)\n .where('type', '=', type)\n .where('id', '=', id)\n .limit(1)\n .executeTakeFirst();\n if (!r) {\n return null;\n }\n return {\n type: r.type,\n id: r.id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n };\n },\n\n queryEntities: async (q: EntityQuery) => {\n await ready;\n const rows = await db\n .selectFrom('entities')\n .select(['type', 'id', 'attributes', 'updated_at'])\n .where('connector_id', '=', connectorId)\n .where('type', '=', q.type)\n .execute();\n return rows.map(\n (r): Entity => ({\n type: r.type,\n id: r.id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n }),\n );\n },\n\n queryMetrics: async (q: MetricQuery) => {\n await ready;\n let qb = db\n .selectFrom('metrics')\n .select(['name', 'ts', 'value', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): MetricSample => ({\n name: r.name,\n ts: Number(r.ts),\n value: Number(r.value),\n attributes: parseJson<Attrs>(r.attributes, {}),\n }),\n );\n },\n\n traverse: async (q: EdgeQuery) => {\n await ready;\n let qb = db\n .selectFrom('edges')\n .select([\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n 'attributes',\n 'updated_at',\n ])\n .where('connector_id', '=', connectorId);\n if (q.fromType !== undefined) {\n qb = qb.where('from_type', '=', q.fromType);\n }\n if (q.fromId !== undefined) {\n qb = qb.where('from_id', '=', q.fromId);\n }\n if (q.kind !== undefined) {\n qb = qb.where('kind', '=', q.kind);\n }\n if (q.toType !== undefined) {\n qb = qb.where('to_type', '=', q.toType);\n }\n if (q.toId !== undefined) {\n qb = qb.where('to_id', '=', q.toId);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): Edge => ({\n from_type: r.from_type,\n from_id: r.from_id,\n kind: r.kind,\n to_type: r.to_type,\n to_id: r.to_id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n }),\n );\n },\n\n queryDistributions: async (q: DistributionQuery) => {\n await ready;\n let qb = db\n .selectFrom('distributions')\n .select(['name', 'ts', 'kind', 'data', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map((r) => {\n const base = {\n name: r.name,\n ts: Number(r.ts),\n attributes: parseJson<Attrs>(r.attributes, {}),\n };\n const data = parseJson<Distribution['data']>(r.data, {\n count: 0,\n sum: 0,\n } as unknown as Distribution['data']);\n if (r.kind === 'histogram') {\n return { ...base, kind: 'histogram', data } as Distribution;\n }\n if (r.kind === 'summary') {\n return { ...base, kind: 'summary', data } as Distribution;\n }\n throw new Error(\n `Unknown distribution kind: ${r.kind} (name=${base.name})`,\n );\n });\n },\n\n deleteOlderThan: async (shape, tsUnixMs) => {\n await ready;\n if (shape === 'events') {\n const r = await db\n .deleteFrom('events')\n .where('connector_id', '=', connectorId)\n .where('start_ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n if (shape === 'metrics') {\n const r = await db\n .deleteFrom('metrics')\n .where('connector_id', '=', connectorId)\n .where('ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n if (shape === 'distributions') {\n const r = await db\n .deleteFrom('distributions')\n .where('connector_id', '=', connectorId)\n .where('ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n throw new Error(\n `Unsupported shape for deleteOlderThan: ${String(shape)}`,\n );\n },\n };\n }\n\n async getSyncState(): Promise<SyncState> {\n if (this.initError !== null) {\n return { status: 'error', lastSyncAt: null, lastError: this.initError };\n }\n await this.ready;\n const r = await this.db\n .selectFrom('sync_state')\n .select(['status', 'last_sync_at', 'last_error'])\n .where('id', '=', SYNC_STATE_ID)\n .limit(1)\n .executeTakeFirst();\n if (!r) {\n return { status: 'idle', lastSyncAt: null, lastError: null };\n }\n return {\n status: r.status as SyncState['status'],\n lastSyncAt: r.last_sync_at,\n lastError: r.last_error,\n };\n }\n\n async setSyncing(): Promise<boolean> {\n await this.ready;\n const r = await this.db\n .updateTable('sync_state')\n .set({ status: 'syncing' })\n .where('id', '=', SYNC_STATE_ID)\n .where('status', '!=', 'syncing')\n .executeTakeFirst();\n return Number(r.numUpdatedRows) > 0;\n }\n\n async setSyncSuccess(): Promise<void> {\n await this.ready;\n await this.db\n .updateTable('sync_state')\n .set({\n status: 'idle',\n last_sync_at: new Date().toISOString(),\n last_error: null,\n })\n .where('id', '=', SYNC_STATE_ID)\n .execute();\n }\n\n async setSyncError(error: string): Promise<void> {\n await this.ready;\n await this.db\n .updateTable('sync_state')\n .set({ status: 'error', last_error: error })\n .where('id', '=', SYNC_STATE_ID)\n .execute();\n }\n\n async close(): Promise<void> {\n await this.ready.catch(() => undefined);\n this.client.close();\n }\n}\n","// AUTO-GENERATED by scripts/bundle-migrations.mjs — do not edit by hand.\n// Regenerate with: pnpm db:bundle (or pnpm db:generate).\n\nexport interface BundledMigration {\n tag: string;\n statements: string[];\n}\n\nexport const MIGRATIONS: readonly BundledMigration[] = [\n {\n tag: '0000_nosy_wendell_vaughn',\n statements: [\n \"CREATE TABLE `distributions` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`ts` integer NOT NULL,\\n\\t`kind` text NOT NULL,\\n\\t`data` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `distributions_conn_name_ts` ON `distributions` (`connector_id`,`name`,`ts`);',\n \"CREATE TABLE `edges` (\\n\\t`connector_id` text NOT NULL,\\n\\t`from_type` text NOT NULL,\\n\\t`from_id` text NOT NULL,\\n\\t`kind` text NOT NULL,\\n\\t`to_type` text NOT NULL,\\n\\t`to_id` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL,\\n\\t`updated_at` integer NOT NULL,\\n\\tPRIMARY KEY(`connector_id`, `from_type`, `from_id`, `kind`, `to_type`, `to_id`)\\n);\",\n 'CREATE INDEX `edges_conn_kind` ON `edges` (`connector_id`,`kind`);',\n 'CREATE INDEX `edges_conn_from` ON `edges` (`connector_id`,`from_type`,`from_id`);',\n \"CREATE TABLE `entities` (\\n\\t`connector_id` text NOT NULL,\\n\\t`type` text NOT NULL,\\n\\t`id` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL,\\n\\t`updated_at` integer NOT NULL,\\n\\tPRIMARY KEY(`connector_id`, `type`, `id`)\\n);\",\n 'CREATE INDEX `entities_conn_type` ON `entities` (`connector_id`,`type`);',\n \"CREATE TABLE `events` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`start_ts` integer NOT NULL,\\n\\t`end_ts` integer,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `events_conn_name_start` ON `events` (`connector_id`,`name`,`start_ts`);',\n \"CREATE TABLE `metrics` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`ts` integer NOT NULL,\\n\\t`value` real NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `metrics_conn_name_ts` ON `metrics` (`connector_id`,`name`,`ts`);',\n ],\n },\n {\n tag: '0001_clumsy_siren',\n statements: [\n 'CREATE TABLE `sync_state` (\\n\\t`id` integer PRIMARY KEY NOT NULL,\\n\\t`status` text NOT NULL,\\n\\t`last_sync_at` text,\\n\\t`last_error` text\\n);',\n ],\n },\n] as const;\n","import type { Client, InStatement } from '@libsql/client/web';\n\nimport { MIGRATIONS } from './migrations-bundle';\n\nconst SCHEMA_MIGRATIONS_TABLE = 'schema_migrations';\n\nconst LEGACY_BASELINE_TABLE = 'events';\n\nasync function tableExists(client: Client, name: string): Promise<boolean> {\n const result = await client.execute({\n sql: \"SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1\",\n args: [name],\n });\n return result.rows.length > 0;\n}\n\nasync function readAppliedTags(client: Client): Promise<Set<string>> {\n const result = await client.execute(\n `SELECT tag FROM ${SCHEMA_MIGRATIONS_TABLE}`,\n );\n return new Set(result.rows.map((r) => String(r['tag'])));\n}\n\nexport async function applyMigrations(client: Client): Promise<void> {\n const hadSchemaTable = await tableExists(client, SCHEMA_MIGRATIONS_TABLE);\n\n await client.execute(\n `CREATE TABLE IF NOT EXISTS ${SCHEMA_MIGRATIONS_TABLE} (\n tag TEXT PRIMARY KEY,\n applied_at INTEGER NOT NULL\n )`,\n );\n\n if (!hadSchemaTable) {\n const hasLegacySchema = await tableExists(client, LEGACY_BASELINE_TABLE);\n if (hasLegacySchema) {\n const now = Date.now();\n for (const migration of MIGRATIONS) {\n await client.execute({\n sql: `INSERT OR IGNORE INTO ${SCHEMA_MIGRATIONS_TABLE} (tag, applied_at) VALUES (?, ?)`,\n args: [migration.tag, now],\n });\n }\n return;\n }\n }\n\n let applied = await readAppliedTags(client);\n\n for (const migration of MIGRATIONS) {\n if (applied.has(migration.tag)) {\n continue;\n }\n const batch: InStatement[] = [\n {\n sql: `INSERT INTO ${SCHEMA_MIGRATIONS_TABLE} (tag, applied_at) VALUES (?, ?)`,\n args: [migration.tag, Date.now()],\n },\n ...migration.statements,\n ];\n try {\n await client.batch(batch, 'write');\n } catch (err) {\n applied = await readAppliedTags(client);\n if (!applied.has(migration.tag)) {\n throw err;\n }\n }\n }\n}\n"],"mappings":";AAiBA,SAA8C,cAAc;AAC5D,SAAS,qBAAqB;;;ACVvB,IAAM,aAA0C;AAAA,EACrD;AAAA,IACE,KAAK;AAAA,IACL,YAAY;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,YAAY;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;;;AC3BA,IAAM,0BAA0B;AAEhC,IAAM,wBAAwB;AAE9B,eAAe,YAAY,QAAgB,MAAgC;AACzE,QAAM,SAAS,MAAM,OAAO,QAAQ;AAAA,IAClC,KAAK;AAAA,IACL,MAAM,CAAC,IAAI;AAAA,EACb,CAAC;AACD,SAAO,OAAO,KAAK,SAAS;AAC9B;AAEA,eAAe,gBAAgB,QAAsC;AACnE,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B,mBAAmB,uBAAuB;AAAA,EAC5C;AACA,SAAO,IAAI,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AACzD;AAEA,eAAsB,gBAAgB,QAA+B;AACnE,QAAM,iBAAiB,MAAM,YAAY,QAAQ,uBAAuB;AAExE,QAA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AM,MAAM,KAAK,aAAa,EAC9B,MAAM,UAAU,MAAM,SAAS,EAC/B,iBAAiB;AACpB,WAAO,OAAO,EAAE,cAAc,IAAI;AAAA,EACpC;AAAA,EAEA,MAAM,iBAAgC;AACpC,UAAM,KAAK;AACX,UAAM,KAAK,GACR,YAAY,YAAY,EACxB,IAAI;AAAA,MACH,QAAQ;AAAA,MACR,eAAc,oBAAI,KAAK,GAAE,YAAY;AAAA,MACrC,YAAY;AAAA,IACd,CAAC,EACA,MAAM,MAAM,KAAK,aAAa,EAC9B,QAAQ;AAAA,EACb;AAAA,EAEA,MAAM,aAAa,OAA8B;AAC/C,UAAM,KAAK;AACX,UAAM,KAAK,GACR,YAAY,YAAY,EACxB,IAAI,EAAE,QAAQ,SAAS,YAAY,MAAM,CAAC,EAC1C,MAAM,MAAM,KAAK,aAAa,EAC9B,QAAQ;AAAA,EACb;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK,MAAM,MAAM,MAAM,MAAS;AACtC,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;","names":[]}
@@ -0,0 +1,55 @@
1
+ CREATE TABLE `distributions` (
2
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3
+ `connector_id` text NOT NULL,
4
+ `name` text NOT NULL,
5
+ `ts` integer NOT NULL,
6
+ `kind` text NOT NULL,
7
+ `data` text NOT NULL,
8
+ `attributes` text DEFAULT '{}' NOT NULL
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE INDEX `distributions_conn_name_ts` ON `distributions` (`connector_id`,`name`,`ts`);--> statement-breakpoint
12
+ CREATE TABLE `edges` (
13
+ `connector_id` text NOT NULL,
14
+ `from_type` text NOT NULL,
15
+ `from_id` text NOT NULL,
16
+ `kind` text NOT NULL,
17
+ `to_type` text NOT NULL,
18
+ `to_id` text NOT NULL,
19
+ `attributes` text DEFAULT '{}' NOT NULL,
20
+ `updated_at` integer NOT NULL,
21
+ PRIMARY KEY(`connector_id`, `from_type`, `from_id`, `kind`, `to_type`, `to_id`)
22
+ );
23
+ --> statement-breakpoint
24
+ CREATE INDEX `edges_conn_kind` ON `edges` (`connector_id`,`kind`);--> statement-breakpoint
25
+ CREATE INDEX `edges_conn_from` ON `edges` (`connector_id`,`from_type`,`from_id`);--> statement-breakpoint
26
+ CREATE TABLE `entities` (
27
+ `connector_id` text NOT NULL,
28
+ `type` text NOT NULL,
29
+ `id` text NOT NULL,
30
+ `attributes` text DEFAULT '{}' NOT NULL,
31
+ `updated_at` integer NOT NULL,
32
+ PRIMARY KEY(`connector_id`, `type`, `id`)
33
+ );
34
+ --> statement-breakpoint
35
+ CREATE INDEX `entities_conn_type` ON `entities` (`connector_id`,`type`);--> statement-breakpoint
36
+ CREATE TABLE `events` (
37
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
38
+ `connector_id` text NOT NULL,
39
+ `name` text NOT NULL,
40
+ `start_ts` integer NOT NULL,
41
+ `end_ts` integer,
42
+ `attributes` text DEFAULT '{}' NOT NULL
43
+ );
44
+ --> statement-breakpoint
45
+ CREATE INDEX `events_conn_name_start` ON `events` (`connector_id`,`name`,`start_ts`);--> statement-breakpoint
46
+ CREATE TABLE `metrics` (
47
+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
48
+ `connector_id` text NOT NULL,
49
+ `name` text NOT NULL,
50
+ `ts` integer NOT NULL,
51
+ `value` real NOT NULL,
52
+ `attributes` text DEFAULT '{}' NOT NULL
53
+ );
54
+ --> statement-breakpoint
55
+ CREATE INDEX `metrics_conn_name_ts` ON `metrics` (`connector_id`,`name`,`ts`);
@@ -0,0 +1,6 @@
1
+ CREATE TABLE `sync_state` (
2
+ `id` integer PRIMARY KEY NOT NULL,
3
+ `status` text NOT NULL,
4
+ `last_sync_at` text,
5
+ `last_error` text
6
+ );
@@ -0,0 +1,349 @@
1
+ {
2
+ "version": "6",
3
+ "dialect": "sqlite",
4
+ "id": "efd9fbb0-84e0-4a66-863e-614fbd940135",
5
+ "prevId": "00000000-0000-0000-0000-000000000000",
6
+ "tables": {
7
+ "distributions": {
8
+ "name": "distributions",
9
+ "columns": {
10
+ "id": {
11
+ "name": "id",
12
+ "type": "integer",
13
+ "primaryKey": true,
14
+ "notNull": true,
15
+ "autoincrement": true
16
+ },
17
+ "connector_id": {
18
+ "name": "connector_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true,
22
+ "autoincrement": false
23
+ },
24
+ "name": {
25
+ "name": "name",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true,
29
+ "autoincrement": false
30
+ },
31
+ "ts": {
32
+ "name": "ts",
33
+ "type": "integer",
34
+ "primaryKey": false,
35
+ "notNull": true,
36
+ "autoincrement": false
37
+ },
38
+ "kind": {
39
+ "name": "kind",
40
+ "type": "text",
41
+ "primaryKey": false,
42
+ "notNull": true,
43
+ "autoincrement": false
44
+ },
45
+ "data": {
46
+ "name": "data",
47
+ "type": "text",
48
+ "primaryKey": false,
49
+ "notNull": true,
50
+ "autoincrement": false
51
+ },
52
+ "attributes": {
53
+ "name": "attributes",
54
+ "type": "text",
55
+ "primaryKey": false,
56
+ "notNull": true,
57
+ "autoincrement": false,
58
+ "default": "'{}'"
59
+ }
60
+ },
61
+ "indexes": {
62
+ "distributions_conn_name_ts": {
63
+ "name": "distributions_conn_name_ts",
64
+ "columns": ["connector_id", "name", "ts"],
65
+ "isUnique": false
66
+ }
67
+ },
68
+ "foreignKeys": {},
69
+ "compositePrimaryKeys": {},
70
+ "uniqueConstraints": {},
71
+ "checkConstraints": {}
72
+ },
73
+ "edges": {
74
+ "name": "edges",
75
+ "columns": {
76
+ "connector_id": {
77
+ "name": "connector_id",
78
+ "type": "text",
79
+ "primaryKey": false,
80
+ "notNull": true,
81
+ "autoincrement": false
82
+ },
83
+ "from_type": {
84
+ "name": "from_type",
85
+ "type": "text",
86
+ "primaryKey": false,
87
+ "notNull": true,
88
+ "autoincrement": false
89
+ },
90
+ "from_id": {
91
+ "name": "from_id",
92
+ "type": "text",
93
+ "primaryKey": false,
94
+ "notNull": true,
95
+ "autoincrement": false
96
+ },
97
+ "kind": {
98
+ "name": "kind",
99
+ "type": "text",
100
+ "primaryKey": false,
101
+ "notNull": true,
102
+ "autoincrement": false
103
+ },
104
+ "to_type": {
105
+ "name": "to_type",
106
+ "type": "text",
107
+ "primaryKey": false,
108
+ "notNull": true,
109
+ "autoincrement": false
110
+ },
111
+ "to_id": {
112
+ "name": "to_id",
113
+ "type": "text",
114
+ "primaryKey": false,
115
+ "notNull": true,
116
+ "autoincrement": false
117
+ },
118
+ "attributes": {
119
+ "name": "attributes",
120
+ "type": "text",
121
+ "primaryKey": false,
122
+ "notNull": true,
123
+ "autoincrement": false,
124
+ "default": "'{}'"
125
+ },
126
+ "updated_at": {
127
+ "name": "updated_at",
128
+ "type": "integer",
129
+ "primaryKey": false,
130
+ "notNull": true,
131
+ "autoincrement": false
132
+ }
133
+ },
134
+ "indexes": {
135
+ "edges_conn_kind": {
136
+ "name": "edges_conn_kind",
137
+ "columns": ["connector_id", "kind"],
138
+ "isUnique": false
139
+ },
140
+ "edges_conn_from": {
141
+ "name": "edges_conn_from",
142
+ "columns": ["connector_id", "from_type", "from_id"],
143
+ "isUnique": false
144
+ }
145
+ },
146
+ "foreignKeys": {},
147
+ "compositePrimaryKeys": {
148
+ "edges_connector_id_from_type_from_id_kind_to_type_to_id_pk": {
149
+ "columns": [
150
+ "connector_id",
151
+ "from_type",
152
+ "from_id",
153
+ "kind",
154
+ "to_type",
155
+ "to_id"
156
+ ],
157
+ "name": "edges_connector_id_from_type_from_id_kind_to_type_to_id_pk"
158
+ }
159
+ },
160
+ "uniqueConstraints": {},
161
+ "checkConstraints": {}
162
+ },
163
+ "entities": {
164
+ "name": "entities",
165
+ "columns": {
166
+ "connector_id": {
167
+ "name": "connector_id",
168
+ "type": "text",
169
+ "primaryKey": false,
170
+ "notNull": true,
171
+ "autoincrement": false
172
+ },
173
+ "type": {
174
+ "name": "type",
175
+ "type": "text",
176
+ "primaryKey": false,
177
+ "notNull": true,
178
+ "autoincrement": false
179
+ },
180
+ "id": {
181
+ "name": "id",
182
+ "type": "text",
183
+ "primaryKey": false,
184
+ "notNull": true,
185
+ "autoincrement": false
186
+ },
187
+ "attributes": {
188
+ "name": "attributes",
189
+ "type": "text",
190
+ "primaryKey": false,
191
+ "notNull": true,
192
+ "autoincrement": false,
193
+ "default": "'{}'"
194
+ },
195
+ "updated_at": {
196
+ "name": "updated_at",
197
+ "type": "integer",
198
+ "primaryKey": false,
199
+ "notNull": true,
200
+ "autoincrement": false
201
+ }
202
+ },
203
+ "indexes": {
204
+ "entities_conn_type": {
205
+ "name": "entities_conn_type",
206
+ "columns": ["connector_id", "type"],
207
+ "isUnique": false
208
+ }
209
+ },
210
+ "foreignKeys": {},
211
+ "compositePrimaryKeys": {
212
+ "entities_connector_id_type_id_pk": {
213
+ "columns": ["connector_id", "type", "id"],
214
+ "name": "entities_connector_id_type_id_pk"
215
+ }
216
+ },
217
+ "uniqueConstraints": {},
218
+ "checkConstraints": {}
219
+ },
220
+ "events": {
221
+ "name": "events",
222
+ "columns": {
223
+ "id": {
224
+ "name": "id",
225
+ "type": "integer",
226
+ "primaryKey": true,
227
+ "notNull": true,
228
+ "autoincrement": true
229
+ },
230
+ "connector_id": {
231
+ "name": "connector_id",
232
+ "type": "text",
233
+ "primaryKey": false,
234
+ "notNull": true,
235
+ "autoincrement": false
236
+ },
237
+ "name": {
238
+ "name": "name",
239
+ "type": "text",
240
+ "primaryKey": false,
241
+ "notNull": true,
242
+ "autoincrement": false
243
+ },
244
+ "start_ts": {
245
+ "name": "start_ts",
246
+ "type": "integer",
247
+ "primaryKey": false,
248
+ "notNull": true,
249
+ "autoincrement": false
250
+ },
251
+ "end_ts": {
252
+ "name": "end_ts",
253
+ "type": "integer",
254
+ "primaryKey": false,
255
+ "notNull": false,
256
+ "autoincrement": false
257
+ },
258
+ "attributes": {
259
+ "name": "attributes",
260
+ "type": "text",
261
+ "primaryKey": false,
262
+ "notNull": true,
263
+ "autoincrement": false,
264
+ "default": "'{}'"
265
+ }
266
+ },
267
+ "indexes": {
268
+ "events_conn_name_start": {
269
+ "name": "events_conn_name_start",
270
+ "columns": ["connector_id", "name", "start_ts"],
271
+ "isUnique": false
272
+ }
273
+ },
274
+ "foreignKeys": {},
275
+ "compositePrimaryKeys": {},
276
+ "uniqueConstraints": {},
277
+ "checkConstraints": {}
278
+ },
279
+ "metrics": {
280
+ "name": "metrics",
281
+ "columns": {
282
+ "id": {
283
+ "name": "id",
284
+ "type": "integer",
285
+ "primaryKey": true,
286
+ "notNull": true,
287
+ "autoincrement": true
288
+ },
289
+ "connector_id": {
290
+ "name": "connector_id",
291
+ "type": "text",
292
+ "primaryKey": false,
293
+ "notNull": true,
294
+ "autoincrement": false
295
+ },
296
+ "name": {
297
+ "name": "name",
298
+ "type": "text",
299
+ "primaryKey": false,
300
+ "notNull": true,
301
+ "autoincrement": false
302
+ },
303
+ "ts": {
304
+ "name": "ts",
305
+ "type": "integer",
306
+ "primaryKey": false,
307
+ "notNull": true,
308
+ "autoincrement": false
309
+ },
310
+ "value": {
311
+ "name": "value",
312
+ "type": "real",
313
+ "primaryKey": false,
314
+ "notNull": true,
315
+ "autoincrement": false
316
+ },
317
+ "attributes": {
318
+ "name": "attributes",
319
+ "type": "text",
320
+ "primaryKey": false,
321
+ "notNull": true,
322
+ "autoincrement": false,
323
+ "default": "'{}'"
324
+ }
325
+ },
326
+ "indexes": {
327
+ "metrics_conn_name_ts": {
328
+ "name": "metrics_conn_name_ts",
329
+ "columns": ["connector_id", "name", "ts"],
330
+ "isUnique": false
331
+ }
332
+ },
333
+ "foreignKeys": {},
334
+ "compositePrimaryKeys": {},
335
+ "uniqueConstraints": {},
336
+ "checkConstraints": {}
337
+ }
338
+ },
339
+ "views": {},
340
+ "enums": {},
341
+ "_meta": {
342
+ "schemas": {},
343
+ "tables": {},
344
+ "columns": {}
345
+ },
346
+ "internal": {
347
+ "indexes": {}
348
+ }
349
+ }