Files
pc_builder/database/schema.ts
T
Kevin L'Hereec 5854ff8ed1
Build & Deploy / build (push) Failing after 4s
Build & Deploy / docker (push) Skipped
feat: search and import new parts scraped from pc-builder.io
Idealo and PCPartPicker were evaluated and ruled out:
- idealo.fr search pages return 503 (Cloudflare)
- the internal Idealo GraphQL endpoint used by a public scraper
  (app.idealo.de/app-backend/api) is protected by Akamai Bot Manager and
  silently returns empty data even with mobile app headers
- PCPartPicker's product list/search relies on a session-bound CSRF token
  refreshed per page load, against a scraping-hostile ToS

pc-builder.io category pages are server-rendered, include name/price/image
for ~100 products per category, and have no bot protection, so the feature
is built on top of that source only.

- New scraped_parts cache table (type_id, name, price, image_url, source,
  source_url, source_ref unique per source) populated by a batch job
  rather than scraped live per search, since only ~100 first results per
  category are available without reverse-engineering pc-builder.io's
  DataTables/CSRF pagination flow
- part_scraper_service.ts: maps our ComponentType names to pc-builder.io
  category slugs (SSD -> storage, since pc-builder.io has no separate HDD
  category) and parses each category page with cheerio, skipping rows
  without a resolved price (generic 'search on Amazon' links)
- node ace scrape:parts: refreshes the cache for every mapped category
  (upsert on source+source_ref), runnable manually or later via cron
- GET /scraped-parts (authenticated): search the cache by name (LOWER()
  LIKE, avoids a MySQL utf8_bin/utf8mb4 collation mismatch from Lucid's
  whereLike) and optional typeId filter
- NewPartSearch.vue: debounced search widget wired into
  components/create.vue; clicking 'Import' pre-fills the existing
  component creation form (name, price, type, purchase date = today)
  instead of creating the Component directly, so the user still reviews
  and saves it like any manually entered part
- 3 functional tests covering search by name, filter by typeId, and
  unauthenticated access being redirected to login
- Initial scrape run: 989 parts across 10 categories
2026-07-23 12:10:36 +02:00

146 lines
4.2 KiB
TypeScript

/**
* This file is automatically generated
* DO NOT EDIT manually
* Run "node ace migration:run" command to re-generate this file
*/
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { DateTime } from 'luxon'
export class ComponentTypeSchema extends BaseModel {
static $columns = ['id', 'name', 'unique'] as const
$columns = ComponentTypeSchema.$columns
@column({ isPrimary: true })
declare id: number
@column()
declare name: string
@column()
declare unique: boolean
}
export class ComponentSchema extends BaseModel {
static $columns = ['computerId', 'createdAt', 'id', 'name', 'price', 'purchaseDate', 'typeId', 'updatedAt', 'userId'] as const
$columns = ComponentSchema.$columns
@column()
declare computerId: number | null
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime | null
@column({ isPrimary: true })
declare id: number
@column()
declare name: string
@column()
declare price: string
@column.date()
declare purchaseDate: DateTime
@column()
declare typeId: number | null
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
@column()
declare userId: number | null
}
export class ComputerPictureSchema extends BaseModel {
static $columns = ['computerId', 'createdAt', 'id', 'link', 'order', 'updatedAt'] as const
$columns = ComputerPictureSchema.$columns
@column()
declare computerId: number | null
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime | null
@column({ isPrimary: true })
declare id: number
@column()
declare link: string
@column()
declare order: number
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
}
export class ComputerStateSchema extends BaseModel {
static $columns = ['id', 'name'] as const
$columns = ComputerStateSchema.$columns
@column({ isPrimary: true })
declare id: number
@column()
declare name: string
}
export class ComputerSchema extends BaseModel {
static $columns = ['cpuScore', 'createdAt', 'globalScore', 'gpuScore', 'id', 'sellPrice', 'shareEnabled', 'shareShowCost', 'shareShowSellPrice', 'shareToken', 'stateId', 'title', 'updatedAt', 'userId'] as const
$columns = ComputerSchema.$columns
@column()
declare cpuScore: number
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime | null
@column()
declare globalScore: number
@column()
declare gpuScore: number
@column({ isPrimary: true })
declare id: number
@column()
declare sellPrice: number | null
@column()
declare shareEnabled: boolean
@column()
declare shareShowCost: boolean
@column()
declare shareShowSellPrice: boolean
@column()
declare shareToken: string | null
@column()
declare stateId: number
@column()
declare title: string
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
@column()
declare userId: number | null
}
export class ScrapedPartSchema extends BaseModel {
static $columns = ['createdAt', 'id', 'imageUrl', 'name', 'price', 'scrapedAt', 'source', 'sourceRef', 'sourceUrl', 'typeId', 'updatedAt'] as const
$columns = ScrapedPartSchema.$columns
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime | null
@column({ isPrimary: true })
declare id: number
@column()
declare imageUrl: string | null
@column()
declare name: string
@column()
declare price: number
@column.dateTime()
declare scrapedAt: DateTime
@column()
declare source: string
@column()
declare sourceRef: string
@column()
declare sourceUrl: string
@column()
declare typeId: number
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
}
export class UserSchema extends BaseModel {
static $columns = ['createdAt', 'email', 'id', 'name', 'password', 'updatedAt'] as const
$columns = UserSchema.$columns
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column()
declare email: string
@column({ isPrimary: true })
declare id: number
@column()
declare name: string | null
@column({ serializeAs: null })
declare password: string
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
}