this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

drizzle

+201 -52
+1 -1
drizzle.config.ts
··· 5 5 config({ path: ".env.local" }); 6 6 7 7 export default defineConfig({ 8 - out: "./drizzle", 9 8 schema: "./src/data/schema.ts", 9 + out: "./migrations", 10 10 dialect: "turso", 11 11 dbCredentials: { 12 12 url: ENV.TURSO_DATABASE_URL,
+20
migrations/0000_overjoyed_whiplash.sql
··· 1 + CREATE TABLE `pokemon` ( 2 + `id` integer PRIMARY KEY NOT NULL, 3 + `name` text NOT NULL, 4 + `dex_id` integer NOT NULL 5 + ); 6 + --> statement-breakpoint 7 + CREATE TABLE `pokemon_types` ( 8 + `id` integer PRIMARY KEY NOT NULL, 9 + `pokemon_id` integer NOT NULL, 10 + `type_id` integer NOT NULL, 11 + FOREIGN KEY (`pokemon_id`) REFERENCES `pokemon`(`id`) ON UPDATE no action ON DELETE no action, 12 + FOREIGN KEY (`type_id`) REFERENCES `types`(`id`) ON UPDATE no action ON DELETE no action 13 + ); 14 + --> statement-breakpoint 15 + CREATE INDEX `idx_pt_pokemon` ON `pokemon_types` (`pokemon_id`);--> statement-breakpoint 16 + CREATE INDEX `idx_pt_type` ON `pokemon_types` (`type_id`);--> statement-breakpoint 17 + CREATE TABLE `types` ( 18 + `id` integer PRIMARY KEY NOT NULL, 19 + `name` text NOT NULL 20 + );
+134
migrations/meta/0000_snapshot.json
··· 1 + { 2 + "version": "6", 3 + "dialect": "sqlite", 4 + "id": "ab4a5db2-40a4-42ef-aed0-67f72bb9e5ef", 5 + "prevId": "00000000-0000-0000-0000-000000000000", 6 + "tables": { 7 + "pokemon": { 8 + "name": "pokemon", 9 + "columns": { 10 + "id": { 11 + "name": "id", 12 + "type": "integer", 13 + "primaryKey": true, 14 + "notNull": true, 15 + "autoincrement": false 16 + }, 17 + "name": { 18 + "name": "name", 19 + "type": "text", 20 + "primaryKey": false, 21 + "notNull": true, 22 + "autoincrement": false 23 + }, 24 + "dex_id": { 25 + "name": "dex_id", 26 + "type": "integer", 27 + "primaryKey": false, 28 + "notNull": true, 29 + "autoincrement": false 30 + } 31 + }, 32 + "indexes": {}, 33 + "foreignKeys": {}, 34 + "compositePrimaryKeys": {}, 35 + "uniqueConstraints": {}, 36 + "checkConstraints": {} 37 + }, 38 + "pokemon_types": { 39 + "name": "pokemon_types", 40 + "columns": { 41 + "id": { 42 + "name": "id", 43 + "type": "integer", 44 + "primaryKey": true, 45 + "notNull": true, 46 + "autoincrement": false 47 + }, 48 + "pokemon_id": { 49 + "name": "pokemon_id", 50 + "type": "integer", 51 + "primaryKey": false, 52 + "notNull": true, 53 + "autoincrement": false 54 + }, 55 + "type_id": { 56 + "name": "type_id", 57 + "type": "integer", 58 + "primaryKey": false, 59 + "notNull": true, 60 + "autoincrement": false 61 + } 62 + }, 63 + "indexes": { 64 + "idx_pt_pokemon": { 65 + "name": "idx_pt_pokemon", 66 + "columns": ["pokemon_id"], 67 + "isUnique": false 68 + }, 69 + "idx_pt_type": { 70 + "name": "idx_pt_type", 71 + "columns": ["type_id"], 72 + "isUnique": false 73 + } 74 + }, 75 + "foreignKeys": { 76 + "pokemon_types_pokemon_id_pokemon_id_fk": { 77 + "name": "pokemon_types_pokemon_id_pokemon_id_fk", 78 + "tableFrom": "pokemon_types", 79 + "tableTo": "pokemon", 80 + "columnsFrom": ["pokemon_id"], 81 + "columnsTo": ["id"], 82 + "onDelete": "no action", 83 + "onUpdate": "no action" 84 + }, 85 + "pokemon_types_type_id_types_id_fk": { 86 + "name": "pokemon_types_type_id_types_id_fk", 87 + "tableFrom": "pokemon_types", 88 + "tableTo": "types", 89 + "columnsFrom": ["type_id"], 90 + "columnsTo": ["id"], 91 + "onDelete": "no action", 92 + "onUpdate": "no action" 93 + } 94 + }, 95 + "compositePrimaryKeys": {}, 96 + "uniqueConstraints": {}, 97 + "checkConstraints": {} 98 + }, 99 + "types": { 100 + "name": "types", 101 + "columns": { 102 + "id": { 103 + "name": "id", 104 + "type": "integer", 105 + "primaryKey": true, 106 + "notNull": true, 107 + "autoincrement": false 108 + }, 109 + "name": { 110 + "name": "name", 111 + "type": "text", 112 + "primaryKey": false, 113 + "notNull": true, 114 + "autoincrement": false 115 + } 116 + }, 117 + "indexes": {}, 118 + "foreignKeys": {}, 119 + "compositePrimaryKeys": {}, 120 + "uniqueConstraints": {}, 121 + "checkConstraints": {} 122 + } 123 + }, 124 + "views": {}, 125 + "enums": {}, 126 + "_meta": { 127 + "schemas": {}, 128 + "tables": {}, 129 + "columns": {} 130 + }, 131 + "internal": { 132 + "indexes": {} 133 + } 134 + }
+13
migrations/meta/_journal.json
··· 1 + { 2 + "version": "7", 3 + "dialect": "sqlite", 4 + "entries": [ 5 + { 6 + "idx": 0, 7 + "version": "6", 8 + "when": 1775133876296, 9 + "tag": "0000_overjoyed_whiplash", 10 + "breakpoints": true 11 + } 12 + ] 13 + }
+4 -2
package.json
··· 8 8 "start": "node .output/server/index.mjs", 9 9 "prepare": "vp config", 10 10 "knip": "knip", 11 - "db:restore": "tsx src/data/seed.ts" 11 + "db:restore": "node src/data/seed.ts", 12 + "db:generate": "drizzle-kit generate", 13 + "db:migrate": "drizzle-kit migrate", 14 + "db:studio": "drizzle-kit studio" 12 15 }, 13 16 "dependencies": { 14 17 "@libsql/client": "^0.17.2", ··· 42 45 "@types/react-dom": "^19.2.3", 43 46 "@vitejs/plugin-react": "^6.0.1", 44 47 "brew": "^0.0.8", 45 - "dotenv": "^17.4.0", 46 48 "drizzle-kit": "^0.31.10", 47 49 "install": "^0.13.0", 48 50 "knip": "^6.2.0",
+8 -10
src/data/db.ts
··· 1 - import { config } from "dotenv"; 2 - 3 - config({ path: ".env.local" }); 4 - 5 - import { createClient } from "@libsql/client"; 6 1 import { sql } from "drizzle-orm"; 7 2 import { drizzle } from "drizzle-orm/libsql"; 8 - import * as schema from "./schema"; 3 + import { ENV } from "varlock/env"; 4 + import * as schema from "~/data/schema.js"; 9 5 10 - const client = createClient({ 11 - url: "file:./db/pokemon-with-types.db", 6 + const db = drizzle({ 7 + connection: { 8 + url: ENV.TURSO_DATABASE_URL, 9 + authToken: ENV.TURSO_AUTH_TOKEN, 10 + }, 11 + schema, 12 12 }); 13 - 14 - const db = drizzle({ client, schema }); 15 13 16 14 const preparedGetPokemonAtOffset = db.query.pokemon 17 15 .findMany({
+19 -38
src/data/seed.ts
··· 1 - import { mkdirSync, readFileSync, rmSync } from "node:fs"; 1 + import { readFileSync } from "node:fs"; 2 2 import { dirname, resolve } from "node:path"; 3 3 import { fileURLToPath } from "node:url"; 4 - import { createClient } from "@libsql/client"; 4 + import { ENV } from "varlock/env"; 5 5 import { drizzle } from "drizzle-orm/libsql"; 6 - import { pokemon, pokemonTypes, types } from "./schema"; 7 - import * as schema from "./schema"; 6 + import * as schema from "./schema.js"; 8 7 9 8 type SeedData = { 10 9 pokemon: Array<{ ··· 24 23 }; 25 24 26 25 const currentDir = dirname(fileURLToPath(import.meta.url)); 27 - const dbPath = resolve(currentDir, "../../db/pokemon-with-types.db"); 28 26 const seedDataPath = resolve(currentDir, "./seed-data.json"); 29 27 30 28 const seedData = JSON.parse(readFileSync(seedDataPath, "utf8")) as SeedData; 31 29 32 - rmSync(dbPath, { force: true }); 33 - mkdirSync(dirname(dbPath), { recursive: true }); 30 + const db = drizzle({ 31 + connection: { 32 + url: ENV.TURSO_DATABASE_URL, 33 + authToken: ENV.TURSO_AUTH_TOKEN, 34 + }, 35 + schema, 36 + }); 34 37 35 - const client = createClient({ url: `file:${dbPath}` }); 36 - const db = drizzle({ client, schema }); 38 + const BATCH_SIZE = 500; 37 39 38 - // const schemaStatements = [ 39 - // `CREATE TABLE "pokemon" ( 40 - // "id" integer PRIMARY KEY NOT NULL, 41 - // "name" text NOT NULL, 42 - // "dex_id" integer NOT NULL 43 - // )`, 44 - // `CREATE TABLE "types" ( 45 - // "id" integer PRIMARY KEY NOT NULL, 46 - // "name" text NOT NULL 47 - // )`, 48 - // `CREATE TABLE "pokemon_types" ( 49 - // "id" integer PRIMARY KEY NOT NULL, 50 - // "pokemon_id" integer NOT NULL REFERENCES "pokemon"("id"), 51 - // "type_id" integer NOT NULL REFERENCES "types"("id") 52 - // )`, 53 - // `CREATE INDEX "idx_pt_pokemon" ON "pokemon_types" ("pokemon_id")`, 54 - // `CREATE INDEX "idx_pt_type" ON "pokemon_types" ("type_id")`, 55 - // ]; 56 - 57 - // for (const statement of schemaStatements) { 58 - // await client.execute(statement); 59 - // } 60 - 61 - const BATCH_SIZE = 500; 40 + await db.delete(schema.pokemon); 41 + await db.delete(schema.types); 42 + await db.delete(schema.pokemonTypes); 62 43 63 44 for (let index = 0; index < seedData.pokemon.length; index += BATCH_SIZE) { 64 - await db.insert(pokemon).values(seedData.pokemon.slice(index, index + BATCH_SIZE)); 45 + await db.insert(schema.pokemon).values(seedData.pokemon.slice(index, index + BATCH_SIZE)); 65 46 } 66 47 67 - await db.insert(types).values(seedData.types); 48 + await db.insert(schema.types).values(seedData.types); 68 49 69 50 for (let index = 0; index < seedData.pokemonTypes.length; index += BATCH_SIZE) { 70 - await db.insert(pokemonTypes).values(seedData.pokemonTypes.slice(index, index + BATCH_SIZE)); 51 + await db 52 + .insert(schema.pokemonTypes) 53 + .values(seedData.pokemonTypes.slice(index, index + BATCH_SIZE)); 71 54 } 72 55 73 56 console.log( 74 57 `Seeded: ${seedData.pokemon.length} pokemon, ${seedData.types.length} types, ${seedData.pokemonTypes.length} pokemon_types`, 75 58 ); 76 - 77 - client.close();
+2 -1
tsconfig.json
··· 21 21 "noFallthroughCasesInSwitch": true, 22 22 "noUncheckedSideEffectImports": true, 23 23 "paths": { 24 - "~/*": ["./src/*"] 24 + "~/*": ["./src/*"], 25 + "~drizzle/*": ["./drizzle/*"] 25 26 } 26 27 } 27 28 }