Fix database schema: Change auction_id and lot_id from BIGINT to TEXT

The scraper uses TEXT IDs like "A7-40063-2" but DatabaseService was creating
BIGINT columns, causing PRIMARY KEY constraint failures on the server.

Changes:
- auction_id: BIGINT -> TEXT PRIMARY KEY
- lot_id: BIGINT -> TEXT PRIMARY KEY
- sale_id: BIGINT -> TEXT
- Added UNIQUE constraints on URLs
- Added migration script (fix-schema.sql)

This fixes the "UNIQUE constraint failed: auctions.auction_id" errors
and allows bid data to populate correctly on the server.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Former-commit-id: 12c3a732e4
This commit is contained in:
Tour
2025-12-07 13:59:26 +01:00
parent 4f0d5113f5
commit 86b19db30b
3 changed files with 253 additions and 7 deletions

View File

@@ -40,14 +40,15 @@ public class DatabaseService {
stmt.execute("PRAGMA synchronous=NORMAL");
// Auctions table (populated by external scraper)
// auction_id is TEXT to match scraper format (e.g., "A7-40063-2")
stmt.execute("""
CREATE TABLE IF NOT EXISTS auctions (
auction_id BIGINT PRIMARY KEY,
auction_id TEXT PRIMARY KEY,
title TEXT NOT NULL,
location TEXT,
city TEXT,
country TEXT,
url TEXT NOT NULL,
url TEXT NOT NULL UNIQUE,
type TEXT,
lot_count INTEGER DEFAULT 0,
closing_time TEXT,
@@ -55,10 +56,12 @@ public class DatabaseService {
)""");
// Lots table (populated by external scraper)
// lot_id and sale_id are TEXT to match scraper format (e.g., "A1-34732-49")
stmt.execute("""
CREATE TABLE IF NOT EXISTS lots (
lot_id BIGINT PRIMARY KEY,
sale_id BIGINT,
lot_id TEXT PRIMARY KEY,
sale_id TEXT,
auction_id TEXT,
title TEXT,
description TEXT,
manufacturer TEXT,
@@ -67,18 +70,20 @@ public class DatabaseService {
category TEXT,
current_bid REAL,
currency TEXT,
url TEXT,
url TEXT UNIQUE,
closing_time TEXT,
closing_notified INTEGER DEFAULT 0,
FOREIGN KEY (sale_id) REFERENCES auctions(auction_id)
FOREIGN KEY (sale_id) REFERENCES auctions(auction_id),
FOREIGN KEY (auction_id) REFERENCES auctions(auction_id)
)""");
// Images table (populated by external scraper with URLs and local_path)
// This process only adds labels via object detection
// lot_id is TEXT to match scraper format
stmt.execute("""
CREATE TABLE IF NOT EXISTS images (
id INTEGER PRIMARY KEY AUTOINCREMENT,
lot_id INTEGER,
lot_id TEXT,
url TEXT,
local_path TEXT,
labels TEXT,