Repository navigation
Expand file tree
/
Copy pathschema.sql
More file actions
66 lines (54 loc) · 2.09 KB
/
Copy pathschema.sql
File metadata and controls
66 lines (54 loc) · 2.09 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- Animal Detection System - Database Schema
-- Run this to (re)set up MySQL for the app.
-- WARNING: This DROPS the existing database and all its data before recreating it.
--
-- From terminal:
-- mysql -u root -p < schema.sql
--
-- Or inside the MySQL shell:
-- mysql -u root -p
-- SOURCE /path/to/schema.sql;
DROP DATABASE IF EXISTS animal_detection;
CREATE DATABASE animal_detection;
USE animal_detection;
-- ---------------- USERS ----------------
CREATE TABLE IF NOT EXISTS Users (
UserID INT AUTO_INCREMENT PRIMARY KEY,
Username VARCHAR(50) NOT NULL UNIQUE,
Email VARCHAR(100) NOT NULL UNIQUE,
PasswordHash VARCHAR(255) NOT NULL,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- ---------------- UPLOADED IMAGES ----------------
CREATE TABLE IF NOT EXISTS UploadedImages (
ImageID INT AUTO_INCREMENT PRIMARY KEY,
UserID INT NOT NULL,
ImageName VARCHAR(255) NOT NULL,
ImagePath VARCHAR(500) NOT NULL,
UploadedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserID) REFERENCES Users(UserID) ON DELETE CASCADE
);
-- ---------------- DETECTION RESULTS ----------------
CREATE TABLE IF NOT EXISTS DetectionResults (
DetectionID INT AUTO_INCREMENT PRIMARY KEY,
ImageID INT NOT NULL,
AnimalName VARCHAR(100) NOT NULL,
Confidence FLOAT NOT NULL,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ImageID) REFERENCES UploadedImages(ImageID) ON DELETE CASCADE
);
-- Helpful indexes for lookups the app does often
CREATE INDEX idx_uploadedimages_userid ON UploadedImages(UserID);
CREATE INDEX idx_detectionresults_imageid ON DetectionResults(ImageID);
-- ---------------- REFRESH TOKENS ----------------
CREATE TABLE IF NOT EXISTS RefreshTokens (
Id INT AUTO_INCREMENT PRIMARY KEY,
UserId INT NOT NULL,
TokenHash VARCHAR(255) NOT NULL,
ExpiryDate DATETIME NOT NULL,
IsRevoked BOOLEAN DEFAULT FALSE,
IsUsed BOOLEAN DEFAULT FALSE,
CreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserId) REFERENCES Users(UserID) ON DELETE CASCADE
);
CREATE INDEX idx_refreshtokens_tokenhash ON RefreshTokens(TokenHash);