feat: implement database layer and rename auction -> listing

Major Changes:
- Set up SQLx database connection and migration system
- Create complete initial database schema with all tables
- Rename 'auction' to 'listing' throughout codebase for better terminology
- Update bot commands: /newauction -> /newlisting, /myauctions -> /mylistings
- Update all database tables: auctions -> listings, auction_medias -> listing_medias
- Update foreign key relationships and indexes
- Add automatic database migration on startup
- Update documentation and README
- Complete backlog tasks: task-001, task-002, task-010

The bot now has a solid database foundation ready for implementing core business logic.
All tests pass and code compiles successfully.
This commit is contained in:
Dylan Knutson
2025-08-27 19:24:15 +00:00
parent 30751181e4
commit 348fa416e8
13 changed files with 312 additions and 77 deletions

View File

@@ -6,18 +6,18 @@ A Telegram bot for managing various types of auctions, built in Rust using SQLit
## Core Features
### Auction Types
### Listing Types
1. **Standard Auctions**: Traditional time-based bidding with anti-sniping protection
2. **Multi-slot Auctions**: Multiple winners (e.g., 3 commission slots available)
3. **Fixed Price Sales**: Set price with limited quantity
4. **Blind Auctions**: Bidders submit amounts with descriptions; seller chooses winner (not necessarily highest bid)
### Key Functionality
- **Telegram Bot**: The bot is interacted with primarily through Telegram. Sellers can create auctions, and view bids on auctions. Buyers can bid on auctions and view their bids.
- **Telegram Bot**: The bot is interacted with primarily through Telegram. Sellers can create listings, and view bids on listings. Buyers can bid on listings and view their bids.
- **Proxy/Automatic Bidding**: Users set maximum bid; system auto-bids up to that amount
- **Anti-sniping Protection**: Configurable time extension if bid placed in last N minutes
- **Buy-now Option**: Instant purchase at fixed price
- **Media Support**: Multiple images/videos per auction on the telegram post.
- **Media Support**: Multiple images/videos per listing on the telegram post.
- **Outbid Notifications**: Configurable user notifications
- **Non-payment Handling**: Track failed payments, allow selection of next highest bidder
- **Localization Support**: Multi-language structure (to be implemented)
@@ -37,11 +37,11 @@ CREATE TABLE users (
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Main auction table (handles all auction types)
CREATE TABLE auctions (
-- Main listing table (handles all listing types)
CREATE TABLE listings (
id INTEGER PRIMARY KEY,
seller_id INTEGER NOT NULL,
auction_type TEXT NOT NULL, -- 'standard', 'multi_slot', 'fixed_price', 'blind'
listing_type TEXT NOT NULL, -- 'standard', 'multi_slot', 'fixed_price', 'blind'
title TEXT NOT NULL,
description TEXT,
@@ -66,7 +66,7 @@ CREATE TABLE auctions (
-- Proxy bid strategies (NOT actual bids, but bidding strategies)
CREATE TABLE proxy_bids (
id INTEGER PRIMARY KEY,
auction_id INTEGER NOT NULL,
listing_id INTEGER NOT NULL,
buyer_id INTEGER NOT NULL,
max_amount DECIMAL(10,2) NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
@@ -74,45 +74,45 @@ CREATE TABLE proxy_bids (
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (auction_id) REFERENCES auctions(id),
FOREIGN KEY (listing_id) REFERENCES listings(id),
FOREIGN KEY (buyer_id) REFERENCES users(id),
UNIQUE(auction_id, buyer_id) -- One active proxy per user per auction
UNIQUE(listing_id, buyer_id) -- One active proxy per user per listing
);
-- Actual bids that happened (events)
CREATE TABLE bids (
id INTEGER PRIMARY KEY,
auction_id INTEGER NOT NULL,
listing_id INTEGER NOT NULL,
buyer_id INTEGER NOT NULL,
bid_amount DECIMAL(10,2) NOT NULL,
-- For blind auctions
-- For blind listings
description TEXT,
-- Status
is_cancelled BOOLEAN DEFAULT FALSE,
slot_number INTEGER, -- For multi-slot auctions
slot_number INTEGER, -- For multi-slot listings
-- NULL = manual bid, NOT NULL = generated from proxy
proxy_bid_id INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (auction_id) REFERENCES auctions(id),
FOREIGN KEY (listing_id) REFERENCES listings(id),
FOREIGN KEY (buyer_id) REFERENCES users(id),
FOREIGN KEY (proxy_bid_id) REFERENCES proxy_bids(id)
);
-- Media attachments
CREATE TABLE auction_medias (
CREATE TABLE listing_medias (
id INTEGER PRIMARY KEY,
auction_id INTEGER NOT NULL,
listing_id INTEGER NOT NULL,
telegram_file_id TEXT NOT NULL,
media_type TEXT NOT NULL, -- 'photo', 'video'
position INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (auction_id) REFERENCES auctions(id)
FOREIGN KEY (listing_id) REFERENCES listings(id)
);
-- User preferences
@@ -233,8 +233,8 @@ TZ=UTC
```
start - Show welcome message
help - Show help message
newauction - Create a new auction
myauctions - View your auctions as a seller
newlisting - Create a new listing
mylistings - View your listings as a seller
mybids - View your active bids
settings - Configure notifications
```
@@ -248,11 +248,11 @@ settings - Configure notifications
## Next Implementation Steps (Priority Order)
### 1. Complete Auction Creation Flow
### 1. Complete Listing Creation Flow
- Implement multi-step wizard state machine
- Handle media uploads (store Telegram file_ids)
- Add validation for each field
- Create auction in database
- Create listing in database
### 2. Implement Bidding System
- Place manual bid function
@@ -265,10 +265,10 @@ settings - Configure notifications
- Auction expiry processing
- Notification sending
### 4. Auction Browsing
### 4. Listing Browsing
- Paginated list with filters
- Search functionality
- Detailed auction view with bid history
- Detailed listing view with bid history
### 5. Admin Interface
- Axum web server in same binary