-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
35 lines (31 loc) · 970 Bytes
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- Create the database
CREATE DATABASE IF NOT EXISTS auction_db;
USE auction_db;
-- Create the users table
CREATE TABLE IF NOT EXISTS users (
id VARCHAR(255) NOT NULL PRIMARY KEY,
username VARCHAR(255),
email VARCHAR(255),
password VARCHAR(255)
);
-- Create the auctions table
CREATE TABLE IF NOT EXISTS auctions (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
start_time DATETIME NOT NULL,
end_time DATETIME NOT NULL
);
-- Create the bids table
CREATE TABLE IF NOT EXISTS bids (
id INT AUTO_INCREMENT PRIMARY KEY,
auction_id INT NOT NULL,
user_id VARCHAR(255) NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
timestamp DATETIME NOT NULL,
FOREIGN KEY (auction_id) REFERENCES auctions(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Add indexes for performance
CREATE INDEX idx_bids_auction_id ON bids (auction_id);
CREATE INDEX idx_bids_user_id ON bids (user_id);