|
1
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.'); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Load the structure in migrations/schema.sql file to the database, clearing the database in the process. |
|
5
|
|
|
* Will ask for confirmation before proceeding. |
|
6
|
|
|
* |
|
7
|
|
|
* options: |
|
8
|
|
|
* - database: the id of the database to load to from the config/database.php file, 'default' by default, can be overwritten from config |
|
9
|
|
|
* - force: use this flag to skip confirmation |
|
10
|
|
|
* - file: override the schema.sql file to load another sql file |
|
11
|
|
|
*/ |
|
12
|
|
|
class Task_DB_Structure_Load extends Minion_Database { |
|
13
|
|
|
|
|
14
|
|
|
protected $_options = array( |
|
15
|
|
|
'database' => 'default', |
|
16
|
|
|
'force' => FALSE, |
|
17
|
|
|
'file' => FALSE |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
protected function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->_options['database'] = Kohana::$config->load("migrations.database"); |
|
23
|
|
|
parent::__construct(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function _execute(array $options) |
|
27
|
|
|
{ |
|
28
|
|
|
$db = $this->db_params($options['database']); |
|
29
|
|
|
$file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path").DIRECTORY_SEPARATOR.'schema.sql'; |
|
30
|
|
|
|
|
31
|
|
|
if ($options['force'] === NULL OR 'yes' === Minion_CLI::read("This will destroy database ".$db['database']." Are you sure? [yes/NO]")) |
|
32
|
|
|
{ |
|
33
|
|
|
$command = strtr("mysql -u:username :password -h :hostname :database < :file ", array( |
|
34
|
|
|
':username' => $db['username'], |
|
35
|
|
|
':password' => $db['password'] ? '-p'.$db['password'] : '', |
|
36
|
|
|
':database' => $db['database'], |
|
37
|
|
|
':hostname' => $db['hostname'], |
|
38
|
|
|
':file' => $file |
|
39
|
|
|
)); |
|
40
|
|
|
|
|
41
|
|
|
Minion_CLI::write(Minion_CLI::color('Loading data from '.Debug::path($file).' to '.$db['database'], 'green')); |
|
42
|
|
|
system($command); |
|
43
|
|
|
} |
|
44
|
|
|
else |
|
45
|
|
|
{ |
|
46
|
|
|
Minion_CLI::write(Minion_CLI::color('Nothing done', 'brown')); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|