|
| 1 | +<?php defined('BASEPATH') OR exit('No direct script access allowed'); |
| 2 | + |
| 3 | +class Migration_Install_ion_auth extends CI_Migration { |
| 4 | + |
| 5 | + public function up() |
| 6 | + { |
| 7 | + // Drop table 'groups' if it exists |
| 8 | + $this->dbforge->drop_table('groups'); |
| 9 | + |
| 10 | + // Table structure for table 'groups' |
| 11 | + $this->dbforge->add_field(array( |
| 12 | + 'id' => array( |
| 13 | + 'type' => 'MEDIUMINT', |
| 14 | + 'constraint' => '8', |
| 15 | + 'unsigned' => TRUE, |
| 16 | + 'auto_increment' => TRUE |
| 17 | + ), |
| 18 | + 'name' => array( |
| 19 | + 'type' => 'VARCHAR', |
| 20 | + 'constraint' => '20', |
| 21 | + ), |
| 22 | + 'description' => array( |
| 23 | + 'type' => 'VARCHAR', |
| 24 | + 'constraint' => '100', |
| 25 | + ) |
| 26 | + )); |
| 27 | + $this->dbforge->add_key('id', TRUE); |
| 28 | + $this->dbforge->create_table('groups'); |
| 29 | + |
| 30 | + // Dumping data for table 'groups' |
| 31 | + $data = array( |
| 32 | + array( |
| 33 | + 'id' => '1', |
| 34 | + 'name' => 'admin', |
| 35 | + 'description' => 'Administrator' |
| 36 | + ), |
| 37 | + array( |
| 38 | + 'id' => '2', |
| 39 | + 'name' => 'members', |
| 40 | + 'description' => 'General User' |
| 41 | + ) |
| 42 | + ); |
| 43 | + $this->db->insert_batch('groups', $data); |
| 44 | + |
| 45 | + |
| 46 | + // Drop table 'users' if it exists |
| 47 | + $this->dbforge->drop_table('users'); |
| 48 | + |
| 49 | + // Table structure for table 'users' |
| 50 | + $this->dbforge->add_field(array( |
| 51 | + 'id' => array( |
| 52 | + 'type' => 'MEDIUMINT', |
| 53 | + 'constraint' => '8', |
| 54 | + 'unsigned' => TRUE, |
| 55 | + 'auto_increment' => TRUE |
| 56 | + ), |
| 57 | + 'ip_address' => array( |
| 58 | + 'type' => 'VARBINARY', |
| 59 | + 'constraint' => '16' |
| 60 | + ), |
| 61 | + 'username' => array( |
| 62 | + 'type' => 'VARCHAR', |
| 63 | + 'constraint' => '100', |
| 64 | + ), |
| 65 | + 'password' => array( |
| 66 | + 'type' => 'VARCHAR', |
| 67 | + 'constraint' => '80', |
| 68 | + ), |
| 69 | + 'salt' => array( |
| 70 | + 'type' => 'VARCHAR', |
| 71 | + 'constraint' => '40' |
| 72 | + ), |
| 73 | + 'email' => array( |
| 74 | + 'type' => 'VARCHAR', |
| 75 | + 'constraint' => '100' |
| 76 | + ), |
| 77 | + 'activation_code' => array( |
| 78 | + 'type' => 'VARCHAR', |
| 79 | + 'constraint' => '40', |
| 80 | + 'null' => TRUE |
| 81 | + ), |
| 82 | + 'forgotten_password_code' => array( |
| 83 | + 'type' => 'VARCHAR', |
| 84 | + 'constraint' => '40', |
| 85 | + 'null' => TRUE |
| 86 | + ), |
| 87 | + 'forgotten_password_time' => array( |
| 88 | + 'type' => 'INT', |
| 89 | + 'constraint' => '11', |
| 90 | + 'unsigned' => TRUE, |
| 91 | + 'null' => TRUE |
| 92 | + ), |
| 93 | + 'remember_code' => array( |
| 94 | + 'type' => 'VARCHAR', |
| 95 | + 'constraint' => '40', |
| 96 | + 'null' => TRUE |
| 97 | + ), |
| 98 | + 'created_on' => array( |
| 99 | + 'type' => 'INT', |
| 100 | + 'constraint' => '11', |
| 101 | + 'unsigned' => TRUE, |
| 102 | + ), |
| 103 | + 'last_login' => array( |
| 104 | + 'type' => 'INT', |
| 105 | + 'constraint' => '11', |
| 106 | + 'unsigned' => TRUE, |
| 107 | + 'null' => TRUE |
| 108 | + ), |
| 109 | + 'active' => array( |
| 110 | + 'type' => 'TINYINT', |
| 111 | + 'constraint' => '1', |
| 112 | + 'unsigned' => TRUE, |
| 113 | + 'null' => TRUE |
| 114 | + ), |
| 115 | + 'first_name' => array( |
| 116 | + 'type' => 'VARCHAR', |
| 117 | + 'constraint' => '50', |
| 118 | + 'null' => TRUE |
| 119 | + ), |
| 120 | + 'last_name' => array( |
| 121 | + 'type' => 'VARCHAR', |
| 122 | + 'constraint' => '50', |
| 123 | + 'null' => TRUE |
| 124 | + ), |
| 125 | + 'company' => array( |
| 126 | + 'type' => 'VARCHAR', |
| 127 | + 'constraint' => '100', |
| 128 | + 'null' => TRUE |
| 129 | + ), |
| 130 | + 'phone' => array( |
| 131 | + 'type' => 'VARCHAR', |
| 132 | + 'constraint' => '20', |
| 133 | + 'null' => TRUE |
| 134 | + ) |
| 135 | + |
| 136 | + )); |
| 137 | + $this->dbforge->add_key('id', TRUE); |
| 138 | + $this->dbforge->create_table('users'); |
| 139 | + |
| 140 | + // Dumping data for table 'users' |
| 141 | + $data = array( |
| 142 | + 'id' => '1', |
| 143 | + 'ip_address' => 0x7f000001, |
| 144 | + 'username' => 'administrator', |
| 145 | + 'password' => '59beecdf7fc966e2f17fd8f65a4a9aeb09d4a3d4', |
| 146 | + 'salt' => '9462e8eee0', |
| 147 | + |
| 148 | + 'activation_code' => '', |
| 149 | + 'forgotten_password_code' => NULL, |
| 150 | + 'created_on' => '1268889823', |
| 151 | + 'last_login' => '1268889823', |
| 152 | + 'active' => '1', |
| 153 | + 'first_name' => 'Admin', |
| 154 | + 'last_name' => 'istrator', |
| 155 | + 'company' => 'ADMIN', |
| 156 | + 'phone' => '0', |
| 157 | + ); |
| 158 | + $this->db->insert('users', $data); |
| 159 | + |
| 160 | + |
| 161 | + // Drop table 'users_groups' if it exists |
| 162 | + $this->dbforge->drop_table('users_groups'); |
| 163 | + |
| 164 | + // Table structure for table 'users_groups' |
| 165 | + $this->dbforge->add_field(array( |
| 166 | + 'id' => array( |
| 167 | + 'type' => 'MEDIUMINT', |
| 168 | + 'constraint' => '8', |
| 169 | + 'unsigned' => TRUE, |
| 170 | + 'auto_increment' => TRUE |
| 171 | + ), |
| 172 | + 'user_id' => array( |
| 173 | + 'type' => 'MEDIUMINT', |
| 174 | + 'constraint' => '8', |
| 175 | + 'unsigned' => TRUE |
| 176 | + ), |
| 177 | + 'group_id' => array( |
| 178 | + 'type' => 'MEDIUMINT', |
| 179 | + 'constraint' => '8', |
| 180 | + 'unsigned' => TRUE |
| 181 | + ) |
| 182 | + )); |
| 183 | + $this->dbforge->add_key('id', TRUE); |
| 184 | + $this->dbforge->create_table('users_groups'); |
| 185 | + |
| 186 | + // Dumping data for table 'users_groups' |
| 187 | + $data = array( |
| 188 | + array( |
| 189 | + 'id' => '1', |
| 190 | + 'user_id' => '1', |
| 191 | + 'group_id' => '1', |
| 192 | + ), |
| 193 | + array( |
| 194 | + 'id' => '2', |
| 195 | + 'user_id' => '1', |
| 196 | + 'group_id' => '2', |
| 197 | + ) |
| 198 | + ); |
| 199 | + $this->db->insert_batch('users_groups', $data); |
| 200 | + |
| 201 | + |
| 202 | + // Drop table 'login_attempts' if it exists |
| 203 | + $this->dbforge->drop_table('login_attempts'); |
| 204 | + |
| 205 | + // Table structure for table 'login_attempts' |
| 206 | + $this->dbforge->add_field(array( |
| 207 | + 'id' => array( |
| 208 | + 'type' => 'MEDIUMINT', |
| 209 | + 'constraint' => '8', |
| 210 | + 'unsigned' => TRUE, |
| 211 | + 'auto_increment' => TRUE |
| 212 | + ), |
| 213 | + 'ip_address' => array( |
| 214 | + 'type' => 'VARBINARY', |
| 215 | + 'constraint' => '16' |
| 216 | + ), |
| 217 | + 'login' => array( |
| 218 | + 'type' => 'VARCHAR', |
| 219 | + 'constraint' => '100', |
| 220 | + 'null', TRUE |
| 221 | + ), |
| 222 | + 'time' => array( |
| 223 | + 'type' => 'INT', |
| 224 | + 'constraint' => '11', |
| 225 | + 'unsigned' => TRUE, |
| 226 | + 'null' => TRUE |
| 227 | + ) |
| 228 | + )); |
| 229 | + $this->dbforge->add_key('id', TRUE); |
| 230 | + $this->dbforge->create_table('login_attempts'); |
| 231 | + |
| 232 | + } |
| 233 | + |
| 234 | + public function down() |
| 235 | + { |
| 236 | + $this->dbforge->drop_table('users'); |
| 237 | + $this->dbforge->drop_table('groups'); |
| 238 | + $this->dbforge->drop_table('users_groups'); |
| 239 | + $this->dbforge->drop_table('login_attempts'); |
| 240 | + } |
| 241 | +} |
0 commit comments