Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Mock_Database_Schema_Skeleton { |
| 4 | |
| 5 | /** |
| 6 | * Create the dummy tables |
| 7 | * |
| 8 | * @return void |
| 9 | */ |
Taufan Aditya | b0703b0 | 2012-04-05 02:31:52 +0700 | [diff] [blame] | 10 | public static function create_tables($forge, $driver) |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 11 | { |
| 12 | // Job Table |
| 13 | $forge->add_field(array( |
| 14 | 'id' => array( |
Taufan Aditya | 1bfc0d9 | 2012-04-05 02:25:25 +0700 | [diff] [blame] | 15 | 'type' => 'INTEGER', |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 16 | 'constraint' => 3, |
| 17 | ), |
| 18 | 'name' => array( |
| 19 | 'type' => 'VARCHAR', |
| 20 | 'constraint' => 40, |
| 21 | ), |
| 22 | 'description' => array( |
| 23 | 'type' => 'TEXT', |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 24 | ), |
| 25 | )); |
| 26 | $forge->add_key('id', TRUE); |
Taufan Aditya | b0703b0 | 2012-04-05 02:31:52 +0700 | [diff] [blame] | 27 | $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE)); |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Create the dummy datas |
| 32 | * |
| 33 | * @return void |
| 34 | */ |
| 35 | public static function create_data($db) |
| 36 | { |
| 37 | // Job Data |
| 38 | $data = array( |
| 39 | 'job' => array( |
| 40 | array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), |
| 41 | array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'), |
| 42 | array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'), |
| 43 | array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'), |
| 44 | ), |
| 45 | ); |
| 46 | |
| 47 | foreach ($data as $table => $dummy_data) |
| 48 | { |
| 49 | $db->truncate($table); |
Taufan Aditya | 024098d | 2012-04-05 01:51:57 +0700 | [diff] [blame] | 50 | |
| 51 | foreach ($dummy_data as $single_dummy_data) |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 52 | { |
Taufan Aditya | 024098d | 2012-04-05 01:51:57 +0700 | [diff] [blame] | 53 | $db->insert($table, $single_dummy_data); |
Taufan Aditya | 5b42166 | 2012-04-05 01:24:50 +0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |