From d9a200cd35a3d06173846a45c9f58acb1adf61aa Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Mon, 27 Jul 2026 21:07:48 +0200 Subject: refactor: rename brand to reference everywhere --- drizzle/0000_greedy_masked_marvel.sql | 25 +++++ drizzle/0000_youthful_mercury.sql | 16 --- drizzle/0001_dry_meteorite.sql | 9 -- drizzle/meta/0000_snapshot.json | 64 +++++++++++- drizzle/meta/0001_snapshot.json | 172 -------------------------------- drizzle/meta/_journal.json | 11 +- src/lib/server/db/schema.ts | 2 +- src/routes/+page.svelte | 2 +- src/routes/catalog/+page.svelte | 2 +- src/routes/grocery/[id]/+page.server.ts | 8 +- src/routes/grocery/[id]/+page.svelte | 10 +- 11 files changed, 102 insertions(+), 219 deletions(-) create mode 100644 drizzle/0000_greedy_masked_marvel.sql delete mode 100644 drizzle/0000_youthful_mercury.sql delete mode 100644 drizzle/0001_dry_meteorite.sql delete mode 100644 drizzle/meta/0001_snapshot.json diff --git a/drizzle/0000_greedy_masked_marvel.sql b/drizzle/0000_greedy_masked_marvel.sql new file mode 100644 index 0000000..45556f1 --- /dev/null +++ b/drizzle/0000_greedy_masked_marvel.sql @@ -0,0 +1,25 @@ +CREATE TABLE `categories` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text NOT NULL +); +--> statement-breakpoint +CREATE UNIQUE INDEX `categories_name_unique` ON `categories` (`name`);--> statement-breakpoint +CREATE TABLE `groceries` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text NOT NULL, + `checked` integer DEFAULT false NOT NULL, + `created_at` text NOT NULL, + `category_id` integer, + FOREIGN KEY (`category_id`) REFERENCES `categories`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +CREATE UNIQUE INDEX `groceries_name_unique` ON `groceries` (`name`);--> statement-breakpoint +CREATE TABLE `references` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `grocery_id` integer NOT NULL, + `reference` text NOT NULL, + `price` real, + `unit` text, + `quality_score` integer, + FOREIGN KEY (`grocery_id`) REFERENCES `groceries`(`id`) ON UPDATE no action ON DELETE cascade +); diff --git a/drizzle/0000_youthful_mercury.sql b/drizzle/0000_youthful_mercury.sql deleted file mode 100644 index 6dde7ff..0000000 --- a/drizzle/0000_youthful_mercury.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE `categories` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `name` text NOT NULL -); ---> statement-breakpoint -CREATE UNIQUE INDEX `categories_name_unique` ON `categories` (`name`);--> statement-breakpoint -CREATE TABLE `groceries` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `name` text NOT NULL, - `checked` integer DEFAULT false NOT NULL, - `created_at` text NOT NULL, - `category_id` integer, - FOREIGN KEY (`category_id`) REFERENCES `categories`(`id`) ON UPDATE no action ON DELETE no action -); ---> statement-breakpoint -CREATE UNIQUE INDEX `groceries_name_unique` ON `groceries` (`name`); \ No newline at end of file diff --git a/drizzle/0001_dry_meteorite.sql b/drizzle/0001_dry_meteorite.sql deleted file mode 100644 index ae22f4b..0000000 --- a/drizzle/0001_dry_meteorite.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE `references` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `grocery_id` integer NOT NULL, - `brand` text NOT NULL, - `price` real, - `unit` text, - `quality_score` integer, - FOREIGN KEY (`grocery_id`) REFERENCES `groceries`(`id`) ON UPDATE no action ON DELETE cascade -); diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json index 6e33354..5f30c67 100644 --- a/drizzle/meta/0000_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,7 +1,7 @@ { "version": "6", "dialect": "sqlite", - "id": "54c7ae45-9838-4ffb-ad46-29995def7272", + "id": "be05d3e6-4ab4-4a59-a592-6459b19b440f", "prevId": "00000000-0000-0000-0000-000000000000", "tables": { "categories": { @@ -95,6 +95,68 @@ "compositePrimaryKeys": {}, "uniqueConstraints": {}, "checkConstraints": {} + }, + "references": { + "name": "references", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "grocery_id": { + "name": "grocery_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reference": { + "name": "reference", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "price": { + "name": "price", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quality_score": { + "name": "quality_score", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "references_grocery_id_groceries_id_fk": { + "name": "references_grocery_id_groceries_id_fk", + "tableFrom": "references", + "tableTo": "groceries", + "columnsFrom": ["grocery_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} } }, "views": {}, diff --git a/drizzle/meta/0001_snapshot.json b/drizzle/meta/0001_snapshot.json deleted file mode 100644 index 21f509e..0000000 --- a/drizzle/meta/0001_snapshot.json +++ /dev/null @@ -1,172 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "52dffa39-fdb4-4a7c-8688-136e0ad485fc", - "prevId": "54c7ae45-9838-4ffb-ad46-29995def7272", - "tables": { - "categories": { - "name": "categories", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "categories_name_unique": { - "name": "categories_name_unique", - "columns": ["name"], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "groceries": { - "name": "groceries", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "checked": { - "name": "checked", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": false - }, - "created_at": { - "name": "created_at", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category_id": { - "name": "category_id", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "groceries_name_unique": { - "name": "groceries_name_unique", - "columns": ["name"], - "isUnique": true - } - }, - "foreignKeys": { - "groceries_category_id_categories_id_fk": { - "name": "groceries_category_id_categories_id_fk", - "tableFrom": "groceries", - "tableTo": "categories", - "columnsFrom": ["category_id"], - "columnsTo": ["id"], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "references": { - "name": "references", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "grocery_id": { - "name": "grocery_id", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "brand": { - "name": "brand", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "price": { - "name": "price", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "unit": { - "name": "unit", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quality_score": { - "name": "quality_score", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "references_grocery_id_groceries_id_fk": { - "name": "references_grocery_id_groceries_id_fk", - "tableFrom": "references", - "tableTo": "groceries", - "columnsFrom": ["grocery_id"], - "columnsTo": ["id"], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 9872346..10dce89 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -5,15 +5,8 @@ { "idx": 0, "version": "6", - "when": 1785169427572, - "tag": "0000_youthful_mercury", - "breakpoints": true - }, - { - "idx": 1, - "version": "6", - "when": 1785170535526, - "tag": "0001_dry_meteorite", + "when": 1785179210259, + "tag": "0000_greedy_masked_marvel", "breakpoints": true } ] diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts index 9cd6af8..9113d9b 100644 --- a/src/lib/server/db/schema.ts +++ b/src/lib/server/db/schema.ts @@ -18,7 +18,7 @@ export const references = sqliteTable('references', { groceryId: integer('grocery_id') .notNull() .references(() => groceries.id, { onDelete: 'cascade' }), - brand: text('brand').notNull(), + reference: text('reference').notNull(), price: real('price'), unit: text('unit'), qualityScore: integer('quality_score'), diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 767c87e..b0398af 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -47,7 +47,7 @@ {item.name} {#if item.bestRef} {item.bestRef.brand} + >{item.bestRef.reference} {#if item.bestRef.price && item.bestRef.unit}  {item.bestRef.price.toFixed(2)} {item.bestRef.unit} {/if} diff --git a/src/routes/catalog/+page.svelte b/src/routes/catalog/+page.svelte index 0e1106c..1ac558f 100644 --- a/src/routes/catalog/+page.svelte +++ b/src/routes/catalog/+page.svelte @@ -30,7 +30,7 @@ {item.name} {#if item.bestRef} {item.bestRef.brand} + >{item.bestRef.reference} {#if item.bestRef.price && item.bestRef.unit}  {item.bestRef.price.toFixed(2)} {item.bestRef.unit} {/if} diff --git a/src/routes/grocery/[id]/+page.server.ts b/src/routes/grocery/[id]/+page.server.ts index 88aa137..e434e9f 100644 --- a/src/routes/grocery/[id]/+page.server.ts +++ b/src/routes/grocery/[id]/+page.server.ts @@ -34,18 +34,18 @@ export const load: PageServerLoad = async ({ params }) => { export const actions: Actions = { add: async ({ request, params }) => { const data = await request.formData(); - const brand = data.get('brand')?.toString().trim(); + const reference = data.get('reference')?.toString().trim(); const price = data.get('price')?.toString().trim(); const unit = data.get('unit')?.toString().trim(); const qualityScore = data.get('quality_score')?.toString().trim(); - if (!brand) { - return fail(400, { error: 'Brand is required' }); + if (!reference) { + return fail(400, { error: 'Reference is required' }); } await db.insert(references).values({ groceryId: Number(params.id), - brand, + reference, price: price ? Number(price) : null, unit: unit || null, qualityScore: qualityScore ? Number(qualityScore) : null, diff --git a/src/routes/grocery/[id]/+page.svelte b/src/routes/grocery/[id]/+page.svelte index 15c4e8b..35cf33a 100644 --- a/src/routes/grocery/[id]/+page.svelte +++ b/src/routes/grocery/[id]/+page.svelte @@ -4,7 +4,7 @@ import { page } from '$app/stores'; let { data, form } = $props(); - let brand = $state(''); + let reference = $state(''); let price = $state(''); let unit = $state('€/kg'); let qualityScore = $state(''); @@ -22,11 +22,11 @@