Skip to content

Commit

Permalink
chore(insights): correct DB migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Aug 25, 2023
1 parent fc748da commit 4ddf56f
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 83 deletions.
18 changes: 17 additions & 1 deletion packages/insights/drizzle/0012_omniscient_leader.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ CREATE TABLE `symbolDetailTmp` (
FOREIGN KEY (`public_api_key`) REFERENCES `applications`(`public_api_key`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`public_api_key`,`manifest_hash`) REFERENCES `manifests`(`public_api_key`,`hash`) ON UPDATE no action ON DELETE no action
);--> statement-breakpoint
INSERT INTO `symbolDetailTmp` SELECT * FROM `symbolDetail`;--> statement-breakpoint
INSERT INTO `symbolDetailTmp` (
`hash`,
`public_api_key`,
`manifest_hash`,
`full_name`,
`origin`,
`lo`,
`hi`
) SELECT
`hash`,
`public_api_key`,
`manifest_hash`,
`full_name`,
`origin`,
`lo`,
`hi`
FROM `symbolDetail`;--> statement-breakpoint
DROP TABLE `symbolDetail`;--> statement-breakpoint
ALTER TABLE `symbolDetailTmp` RENAME TO `symbolDetail`;
6 changes: 3 additions & 3 deletions packages/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"@typescript/analyze-trace": "^0.10.0",
"density-clustering": "^1.3.0",
"dotenv": "^16.3.1",
"drizzle-kit": "^0.19.12",
"drizzle-orm": "^0.28.2",
"drizzle-kit": "^0.19.13",
"drizzle-orm": "0.27.2",
"install": "^0.13.0"
},
"devDependencies": {
Expand All @@ -29,7 +29,7 @@
"eslint-plugin-qwik": "1.2.6",
"netlify-cli": "^15.9.1",
"prettier": "3.0.0",
"typescript": "5.1.6",
"typescript": "5.2.2",
"undici": "5.22.1",
"uvu": "0.5.6",
"vite": "4.4.7",
Expand Down
6 changes: 3 additions & 3 deletions packages/insights/src/db/query-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sql, type InferInsertModel } from 'drizzle-orm';
import { edgeTable, type routesTable } from './schema';
import { sql } from 'drizzle-orm';
import { type DatabaseInsert, edgeTable, type routesTable } from './schema';
import { BUCKETS } from '~/stats/vector';

export type VectorKeys<PREFIX extends string> =
Expand Down Expand Up @@ -81,7 +81,7 @@ export function createEdgeRow({
interaction: boolean;
delayBucket: number;
latencyBucket: number;
}): InferInsertModel<typeof edgeTable> {
}): DatabaseInsert['edgeTable'] {
return {
publicApiKey,
manifestHash,
Expand Down
12 changes: 12 additions & 0 deletions packages/insights/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type InferModel } from 'drizzle-orm';
import {
integer,
sqliteTable,
Expand All @@ -10,6 +11,17 @@ import {
export type DatabaseSchema = {
applicationTable: typeof applicationTable;
symbolTable: typeof symbolTable;
symbolDetailTable: typeof symbolDetailTable;
errorTable: typeof errorTable;
};

export type DatabaseInsert = {
edgeTable: InferModel<typeof edgeTable, 'insert'>;
};

export type DatabaseSelect = {
edgeTable: InferModel<typeof edgeTable, 'select'>;
manifestTable: InferModel<typeof manifestTable, 'select'>;
};

export const applicationTable = sqliteTable(
Expand Down
6 changes: 3 additions & 3 deletions packages/insights/src/db/sql-manifest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { eq, and, type InferSelectModel, sql } from 'drizzle-orm';
import { eq, and, sql } from 'drizzle-orm';
import { type AppDatabase } from './index';
import { edgeTable, manifestTable } from './schema';
import { type DatabaseSelect, edgeTable, manifestTable } from './schema';
import { latencyColumnSums, toVector } from './query-helpers';

export async function dbGetManifests(
db: AppDatabase,
publicApiKey: string
): Promise<InferSelectModel<typeof manifestTable>[]> {
): Promise<DatabaseSelect['manifestTable'][]> {
const manifests = await db
.select()
.from(manifestTable)
Expand Down
7 changes: 6 additions & 1 deletion packages/insights/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig(async () => {
qwikTypes(),
qwikVite(),
tsconfigPaths({ projects: ['.'] }),
qwikInsights({ publicApiKey: loadEnv('', '.', '').PUBLIC_QWIK_INSIGHTS_KEY }),
// qwikInsights({ publicApiKey: loadEnv('', '.', '').PUBLIC_QWIK_INSIGHTS_KEY }),
],
preview: {
headers: {
Expand All @@ -23,5 +23,10 @@ export default defineConfig(async () => {
optimizeDeps: {
include: ['@auth/core'],
},
build: {
rollupOptions: {
external: ['@libsql/client'],
},
},
};
});
Loading

0 comments on commit 4ddf56f

Please sign in to comment.