· 8 years ago · Jun 10, 2018, 05:36 PM
1<?php
2
3defined('BASEPATH') OR exit('No direct script access allowed');
4
5class Migration_Install extends CI_Migration
6{
7 function up()
8 {
9
10 if (!$this->db->table_exists($this->db->dbprefix('ci_sessions')))
11 {
12 $this->db->query(
13 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('ci_sessions') . "` (
14 session_id varchar(40) DEFAULT '0' NOT NULL,
15 ip_address varchar(16) DEFAULT '0' NOT NULL,
16 user_agent varchar(120) NOT NULL,
17 last_activity int(10) unsigned DEFAULT 0 NOT NULL,
18 user_data text NOT NULL,
19 PRIMARY KEY (session_id),
20 KEY `last_activity_idx` (`last_activity`)
21 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"
22 );
23 }
24
25 if (!$this->db->table_exists($this->db->dbprefix('preferences')))
26 {
27 $this->db->query(
28 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('preferences') . "` (
29 `name` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
30 `value` varchar(2048) COLLATE utf8_unicode_ci NOT NULL,
31 `group` int(11) NOT NULL,
32 PRIMARY KEY (`name`)
33 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
34 );
35
36 $this->db->query(
37 "INSERT INTO `" . $this->db->dbprefix('preferences') . "` (`name`, `value`, `group`) VALUES
38 ('fs_ads_bottom_banner', '', 0),
39 ('fs_ads_bottom_banner_active', '', 0),
40 ('fs_ads_bottom_banner_reload', '', 0),
41 ('fs_ads_left_banner', '', 0),
42 ('fs_ads_left_banner_active', '', 0),
43 ('fs_ads_left_banner_reload', '', 0),
44 ('fs_ads_top_banner', '', 0),
45 ('fs_ads_top_banner_active', '', 0),
46 ('fs_ads_top_banner_reload', '', 0),
47 ('fs_gen_anon_team_show', '1', 0),
48 ('fs_gen_back_url', '', 0),
49 ('fs_gen_default_lang', 'en', 0),
50 ('fs_gen_default_team', 'Anonymous', 0),
51 ('fs_gen_footer_text', 'All the manga featured in this website are property of their publishers. The translations are fanmade and meant to be a preview of material unavailable for western countries.\nDo not try to profit from this material.<br/>If you liked any of the manga you obtained here, consider buying the Japanese versions, or the local translation, where available. Thanks for your support.', 0),
52 ('fs_gen_site_title', 'A fresh FoOlSlide', 0),
53 ('fs_priv_version', '" . FOOLSLIDE_VERSION . "', 0),
54 ('fs_srv_servers', '', 0);"
55 );
56 }
57
58 if (!$this->db->table_exists($this->db->dbprefix('comics')))
59 {
60 $this->db->query(
61 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('comics') . "` (
62 `id` int(11) NOT NULL AUTO_INCREMENT,
63 `name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
64 `stub` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
65 `uniqid` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
66 `hidden` int(11) NOT NULL,
67 `description` text COLLATE utf8_unicode_ci NOT NULL,
68 `thumbnail` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
69 `created` datetime NOT NULL,
70 `lastseen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
71 `updated` datetime NOT NULL,
72 `creator` int(11) NOT NULL,
73 `editor` int(11) NOT NULL,
74 PRIMARY KEY (`id`)
75 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
76 );
77 }
78
79 if (!$this->db->table_exists($this->db->dbprefix('chapters')))
80 {
81 $this->db->query(
82 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('chapters') . "` (
83 `id` int(11) NOT NULL AUTO_INCREMENT,
84 `comic_id` int(11) NOT NULL,
85 `team_id` int(11) NOT NULL,
86 `joint_id` int(11) NOT NULL,
87 `chapter` int(11) NOT NULL,
88 `subchapter` int(11) NOT NULL,
89 `volume` int(11) NOT NULL,
90 `language` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
91 `name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
92 `stub` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
93 `uniqid` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
94 `hidden` int(11) NOT NULL,
95 `description` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
96 `thumbnail` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
97 `created` datetime NOT NULL,
98 `lastseen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
99 `updated` datetime NOT NULL,
100 `creator` int(11) NOT NULL,
101 `editor` int(11) NOT NULL,
102 PRIMARY KEY (`id`)
103 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
104 );
105 }
106
107 if (!$this->db->table_exists($this->db->dbprefix('pages')))
108 {
109 $this->db->query(
110 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('pages') . "` (
111 `id` int(11) NOT NULL AUTO_INCREMENT,
112 `chapter_id` int(11) NOT NULL,
113 `filename` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
114 `hidden` int(11) NOT NULL,
115 `description` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
116 `thumbnail` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
117 `created` datetime NOT NULL,
118 `lastseen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
119 `updated` datetime NOT NULL,
120 `creator` int(11) NOT NULL,
121 `editor` int(11) NOT NULL,
122 `height` int(11) NOT NULL,
123 `width` int(11) NOT NULL,
124 `mime` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
125 `grayscale` int(11) NOT NULL,
126 `thumbheight` int(11) NOT NULL,
127 `thumbwidth` int(11) NOT NULL,
128 `size` int(11) NOT NULL,
129 `thumbsize` int(11) NOT NULL,
130 PRIMARY KEY (`id`)
131 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
132 );
133 }
134
135 if (!$this->db->table_exists($this->db->dbprefix('teams')))
136 {
137 $this->db->query(
138 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('teams') . "` (
139 `id` int(11) NOT NULL AUTO_INCREMENT,
140 `name` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
141 `stub` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
142 `url` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
143 `forum` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
144 `irc` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
145 `twitter` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
146 `facebook` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
147 `facebookid` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
148 `created` datetime NOT NULL,
149 `lastseen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
150 `updated` datetime NOT NULL,
151 `creator` int(11) NOT NULL,
152 `editor` int(11) NOT NULL,
153 PRIMARY KEY (`id`)
154 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
155 );
156
157 $this->db->query(
158 "INSERT INTO `" . $this->db->dbprefix('teams') . "` (`id`, `name`, `stub`, `url`, `forum`, `irc`, `twitter`, `facebook`, `facebookid`, `created`, `lastseen`, `updated`, `creator`, `editor`) VALUES
159 (1, 'Anonymous', 'anonymous', '', '', '', '', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 1, 1);"
160 );
161 }
162
163 if (!$this->db->table_exists($this->db->dbprefix('joints')))
164 {
165 $this->db->query(
166 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('joints') . "` (
167 `id` int(11) NOT NULL AUTO_INCREMENT,
168 `joint_id` int(11) NOT NULL,
169 `team_id` int(11) NOT NULL,
170 `created` datetime NOT NULL,
171 `updated` datetime NOT NULL,
172 `creator` int(11) NOT NULL,
173 `editor` int(11) NOT NULL,
174 PRIMARY KEY (`id`)
175 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
176 );
177 }
178
179 if (!$this->db->table_exists($this->db->dbprefix('licenses')))
180 {
181 $this->db->query(
182 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('licenses') . "` (
183 `id` int(11) NOT NULL AUTO_INCREMENT,
184 `comic_id` int(11) NOT NULL,
185 `nation` varchar(8) COLLATE utf8_unicode_ci NOT NULL,
186 PRIMARY KEY (`id`)
187 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
188 );
189 }
190
191 if (!$this->db->table_exists($this->db->dbprefix('memberships')))
192 {
193 $this->db->query(
194 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('memberships') . "` (
195 `id` int(11) NOT NULL AUTO_INCREMENT,
196 `team_id` int(11) NOT NULL,
197 `user_id` int(11) NOT NULL,
198 `is_leader` int(11) NOT NULL,
199 `accepted` int(11) NOT NULL,
200 `requested` int(11) NOT NULL,
201 `applied` int(11) NOT NULL,
202 `created` datetime NOT NULL,
203 `edited` datetime NOT NULL,
204 PRIMARY KEY (`id`)
205 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
206 );
207 }
208
209 if (!$this->db->table_exists($this->db->dbprefix('groups')))
210 {
211 $this->db->query(
212 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('groups') . "` (
213 `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
214 `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
215 `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
216 PRIMARY KEY (`id`)
217 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"
218 );
219
220 $this->db->query(
221 "INSERT INTO `" . $this->db->dbprefix('groups') . "` (`id`, `name`, `description`) VALUES
222 (1, 'admin', 'Administrator'),
223 (2, 'members', 'Users or Team member'),
224 (3, 'mod', 'Moderator');"
225 );
226 }
227
228 if (!$this->db->table_exists($this->db->dbprefix('users')))
229 {
230 $this->db->query(
231 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('users') . "` (
232 `id` int(11) NOT NULL AUTO_INCREMENT,
233 `username` varchar(50) COLLATE utf8_bin NOT NULL,
234 `password` varchar(255) COLLATE utf8_bin NOT NULL,
235 `email` varchar(100) COLLATE utf8_bin NOT NULL,
236 `activated` tinyint(1) NOT NULL DEFAULT '1',
237 `banned` tinyint(1) NOT NULL DEFAULT '0',
238 `ban_reason` varchar(255) COLLATE utf8_bin DEFAULT NULL,
239 `new_password_key` varchar(50) COLLATE utf8_bin DEFAULT NULL,
240 `new_password_requested` datetime DEFAULT NULL,
241 `new_email` varchar(100) COLLATE utf8_bin DEFAULT NULL,
242 `new_email_key` varchar(50) COLLATE utf8_bin DEFAULT NULL,
243 `last_ip` varchar(40) COLLATE utf8_bin NOT NULL,
244 `last_login` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
245 `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
246 `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
247 `updated` datetime NOT NULL,
248 PRIMARY KEY (`id`)
249 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;"
250 );
251 }
252
253 if (!$this->db->table_exists($this->db->dbprefix('profiles')))
254 {
255 $this->db->query(
256 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('profiles') . "` (
257 `id` int(11) NOT NULL AUTO_INCREMENT,
258 `user_id` int(11) NOT NULL,
259 `group_id` int(11) NOT NULL,
260 `display_name` varchar(32) COLLATE utf8_bin NOT NULL,
261 `twitter` varchar(32) COLLATE utf8_bin NOT NULL,
262 `bio` text COLLATE utf8_bin NOT NULL,
263 PRIMARY KEY (`id`)
264 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;"
265 );
266 }
267
268 if (!$this->db->table_exists($this->db->dbprefix('login_attempts')))
269 {
270 $this->db->query(
271 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('login_attempts') . "` (
272 `id` int(11) NOT NULL AUTO_INCREMENT,
273 `ip_address` varchar(40) COLLATE utf8_bin NOT NULL,
274 `login` varchar(50) COLLATE utf8_bin NOT NULL,
275 `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
276 PRIMARY KEY (`id`)
277 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;"
278 );
279 }
280
281 if (!$this->db->table_exists($this->db->dbprefix('user_autologin')))
282 {
283 $this->db->query(
284 "CREATE TABLE IF NOT EXISTS `" . $this->db->dbprefix('user_autologin') . "` (
285 `key_id` char(32) COLLATE utf8_bin NOT NULL,
286 `user_id` int(11) NOT NULL DEFAULT '0',
287 `user_agent` varchar(150) COLLATE utf8_bin NOT NULL,
288 `last_ip` varchar(40) COLLATE utf8_bin NOT NULL,
289 `last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
290 PRIMARY KEY (`key_id`,`user_id`)
291 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"
292 );
293 }
294 }
295
296
297}