-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitAudio-tables.sql
executable file
·115 lines (92 loc) · 4.08 KB
/
TwitAudio-tables.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* TwitAudio tables
* Rewritten in May 27, 2016
* Because they sucked
* I'm glad I did this when the site wasn't visited :)
*/
CREATE TABLE IF NOT EXISTS `users` (
`id` int(20) unsigned NOT NULL,
`username` varchar(15) NOT NULL,
`name` varchar(20) NOT NULL,
`bio` varchar(160) NOT NULL,
`avatar` varchar(100) NOT NULL,
`access_token` varchar(50) NOT NULL,
`access_token_secret` varchar(50) NOT NULL,
`status` enum('1', '0') NOT NULL
COMMENT '1 ok 0 banned' DEFAULT '1',
`is_verified` enum('1', '0') NOT NULL,
`favs_privacy` enum('public', 'private') NOT NULL,
`audios_privacy` enum('public', 'private') NOT NULL,
/* a unix timestamp that will fail on 2038 */
`date_added` int(32) NOT NULL COMMENT 'Unix timestamp',
`upload_limit` int(3) NOT NULL DEFAULT 120
COMMENT 'In seconds',
`premium_until` int(32) NOT NULL DEFAULT 0
COMMENT 'unix timestamp',
`register_ip` int unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE (`username`),
FULLTEXT (`username`, `name`, `bio`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `audios` (
`id` char(6) NOT NULL,
`user_id` int(20) unsigned NOT NULL,
`audio_url` char(36), -- NULL when is a reply :)
`reply_to` char(6), -- null means not reply and filled means replying
`description` varchar(160) NOT NULL,
`twitter_id` varchar(25) NOT NULL DEFAULT 0,
`date_added` int(32) unsigned NOT NULL COMMENT 'Unix Timestamp',
`plays` int(8) unsigned NOT NULL DEFAULT 0,
`favorites` int(8) unsigned NOT NULL DEFAULT 0,
`duration` int(3) unsigned NOT NULL,
`status` enum('1', '0') NOT NULL DEFAULT '1' COMMENT '1ok 0deleted',
`is_voice` enum('1', '0') NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE,
FULLTEXT (`description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `plays` (
`user_ip` int unsigned NOT NULL,
`audio_id` char(6) NOT NULL,
`date_added` int(32) unsigned NOT NULL,
PRIMARY KEY (`user_ip`, `audio_id`),
FOREIGN KEY (`audio_id`) REFERENCES audios(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `favorites` (
`user_id` int(20) unsigned NOT NULL,
`audio_id` char(6) NOT NULL,
`date_added` int(32) unsigned NOT NULL,
PRIMARY KEY (`user_id`, `audio_id`),
FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE,
FOREIGN KEY (`audio_id`) REFERENCES audios(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `sessions` (
`id` char(32) NOT NULL,
`user_id` int(20) unsigned NOT NULL,
`user_ip` int unsigned NOT NULL,
`date_added` int(32) unsigned NOT NULL,
`is_mobile` enum('1', '0') NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `following_cache` (
`user_id` int(20) unsigned NOT NULL,
/** is ^ following ↓ ? */
`following` int(20) unsigned NOT NULL,
`date_added` int(32) unsigned NOT NULL,
`result` enum('1', '0') NOT NULL,
PRIMARY KEY (`user_id`, `following`),
FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE,
FOREIGN KEY (`following`) REFERENCES users(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `payments` (
`id` int(6) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(20) unsigned NOT NULL,
`method` enum('paypal', 'stripe') NOT NULL,
/** fucking user agents this is the max I'll take */
`user_agent` varchar(2000) NOT NULL,
`user_ip` int unsigned NOT NULL,
`date_added` int(32) unsigned NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;