-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
92 lines (84 loc) · 2.66 KB
/
database.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS photos;
DROP TABLE IF EXISTS artists;
DROP TABLE IF EXISTS comments;
DROP TABLE IF EXISTS tags;
CREATE TABLE users(
username TEXT PRIMARY KEY,
password TEXT,
profilepicurl TEXT,
firstname TEXT,
lastname TEXT,
email TEXT,
country TEXT,
sex TEXT,
age INT,
CONSTRAINT user_check UNIQUE (username,email),
CONSTRAINT gender_check CHECK (sex IN ("M","F"))
);
CREATE TABLE photos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
latitude FLOAT,
longitude FLOAT,
description TEXT,
uploader TEXT,
uploaddate DATETIME,
caption TEXT,
artist TEXT,
url TEXT,
FOREIGN KEY (uploader) REFERENCES users(username)
);
CREATE TABLE comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uploaddate DATETIME,
comstring TEXT,
commenter TEXT,
photoid INTEGER,
FOREIGN KEY (photoid) REFERENCES photos(id)
);
CREATE TABLE friends (
username TEXT,
friend TEXT,
PRIMARY KEY (username, friend)
FOREIGN KEY (username) REFERENCES users(username),
FOREIGN KEY (friend) REFERENCES users(username)
);
CREATE TABLE artists (
/*(if username is null, not registered, if username not null...) registered BOOLEAN,*/
username TEXT,
FOREIGN KEY (username) REFERENCES users(username)
);
CREATE TABLE tags (
tagid INTEGER PRIMARY KEY AUTOINCREMENT,
tagstring TEXT,
id INTEGER
);
/* CREATE TABLE comments (
photoid INT,
FOREIGN KEY (photoid) REFERENCES photos(id)
*/
/*
Photos = URL
Photos = Location
Photos = Description
Photos = Uploader
Photos = Date
Photos = Caption
Photos = Tagging of Artist
Photos = Tagging of Friends
Photos = ID Field
CONSTRAINTS on ID
FOREIGN KEY (Uploader) REFERENCES users(username)
*/
/*
INSERT INTO users VALUES ("Caspar_User", "Caspar_password", "test.com", "Caspar", "Blattmann", "[email protected]", "Turkey", "M", 32);
INSERT INTO users VALUES ("Jess_User", "Jess_password", "test.com", "Jess", "D'Ali", "[email protected]", "France", "F", 18);
INSERT INTO users VALUES ("Alex_User", "Alex_password", "test.com", "Alex", "Harper", "[email protected]", "Germany", "M", 24);
INSERT INTO photos VALUES (1,-33.1,151.2,"blah","Caspar_User",datetime('now'),"blah_short","Tim", "tim.com");
INSERT INTO photos VALUES (2,33,130.5,"this is a cool photo", "Jess_USer",datetime('now'),"sdfakasdf","Smezza", "smezza.com");
*/
/* how to load sql up
login
cd ncss133/databases/project_files/
sqlite3 database.db
.read database.sql */