Skip to content

Commit

Permalink
Tea\Database fixes.
Browse files Browse the repository at this point in the history
Fixed syntax issue in Tea\Database.
Added Tea\Database::seed command.
  • Loading branch information
mloberg committed Jan 9, 2012
1 parent 656f811 commit d1ad21a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/db/seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
)
*/
return array(

);
21 changes: 20 additions & 1 deletion tfd/tea/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function __flags(){
'drop-column' => 'remove_column',
'add-key' => 'add_key',
'drop-key' => 'remove_key',
's' => 'seed',
);
}

Expand Down Expand Up @@ -249,7 +250,7 @@ public static function remove_column($arg){ // --drop-columns > Worker::drop_col
}
do{
echo 'Which table would you like to drop columns from? ';
$table = tables[Tea::response()])){
$table = $tables[Tea::response()];
}while(empty($table));
}

Expand Down Expand Up @@ -384,6 +385,24 @@ public static function remove_key($arg){ // --drop-key > Worker::drop_key

Worker::drop_key($table, $col);
}

public static function seed(){
$seed = include(CONTENT_DIR.'db/seed'.EXT);
if(!empty($seed)){
foreach($seed as $table => $fields){
echo "Seeding {$table}...\n";
if($fields['clear_data'] === true){
MySQL::table($table)->delete(true);
MySQL::query(sprintf("ALTER TABLE `%s` AUTO_INCREMENT = 1", $table));
unset($fields['clear_data']);
}
foreach($fields as $field){
MySQL::table($table)->insert($field);
}
}
echo "Database seeded.\n";
}
}

}

Expand Down

0 comments on commit d1ad21a

Please sign in to comment.