mirror of
https://github.com/Oreolek/kohana-migrations.git
synced 2024-06-16 15:01:08 +03:00
Ensure the migrations table exists before running migrations, fixes #9
This commit is contained in:
parent
74eeb0aa3d
commit
5648f47110
|
@ -83,6 +83,9 @@ class Minion_Task_Db_Migrate extends Minion_Task
|
|||
$db = Database::instance();
|
||||
$model = new Model_Minion_Migration($db);
|
||||
|
||||
|
||||
$model->ensure_table_exists();
|
||||
|
||||
$manager = new Minion_Migration_Manager($db, $model);
|
||||
|
||||
$manager
|
||||
|
|
|
@ -40,6 +40,24 @@ class Model_Minion_Migration extends Model
|
|||
return Minion_Migration_Util::compile_migrations_from_files($files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the minion migrations table exists and attempts to
|
||||
* create it if it doesn't
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function ensure_table_exists()
|
||||
{
|
||||
$query = $this->_db->query(Database::SELECT, "SHOW TABLES like '".$this->_table."'");
|
||||
|
||||
if( ! count($query))
|
||||
{
|
||||
$sql = file_get_contents(Kohana::find_file('', 'minion_schema', 'sql'));
|
||||
|
||||
$this->_db->query(NULL, $sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status of all locations, whether they're in the db or not.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `minion_migrations` (
|
||||
`timestamp` varchar(14) NOT NULL,
|
||||
`description` varchar(100) NOT NULL,
|
||||
|
@ -8,4 +6,3 @@ CREATE TABLE `minion_migrations` (
|
|||
PRIMARY KEY (`timestamp`,`location`),
|
||||
UNIQUE KEY `MIGRATION_ID` (`timestamp`,`description`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
|
Loading…
Reference in a new issue