Example #1
0
 /**
  * Helper function for executing a single query and saving all the
  * boilerplate code in migrations
  */
 public static function exec_query($sql)
 {
     $db = self::instance()->obj;
     try {
         $db->beginTransaction();
         $db->exec($sql);
         $db->commit();
         helpers\printout('Ok');
     } catch (\PDOException $e) {
         //Something went wrong rollback!
         $db->rollBack();
         throw new MysqlException($e->getMessage());
     }
 }
Example #2
0
function showhelp()
{
    helpers\printout("\nAvailable commands:\n\n    create -n <migration name>\n    migrate [-n <migration name>] [--fake, --recover]\n\n");
}
Example #3
0
/**
 * Function to check whether the migration table exists or not
 * If table does't exists it will be created.
 */
function check_migration_table()
{
    try {
        $db = PDOWrapper::instance()->obj;
        $query = $db->query("SELECT 1 FROM " . HISTORY_TABLENAME);
        $check = $query->fetch();
    } catch (\Exception $e) {
        try {
            helpers\printout("Table " . HISTORY_TABLENAME . " doesn't exist. " . "\n");
            helpers\printout("Creating table now..." . "\n");
            $count = $db->exec("CREATE TABLE IF NOT EXISTS `db_migrationhistory` (\n                               `id` int(11) NOT NULL AUTO_INCREMENT,\n                               `migration` varchar(255) NOT NULL,\n                               `applied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n                               PRIMARY KEY (`id`),\n                               UNIQUE KEY `migration` (`migration`)\n                               ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
            helpers\printout($count . "\n");
        } catch (\Exception $e) {
            helpers\printout($e->getMessage());
            exit;
        }
    }
}