Skip to content

Instantly share code, notes, and snippets.

View omartech's full-sized avatar

Omar Ali Ibrahim omartech

View GitHub Profile
@bmarston
bmarston / InitialDbMigrationCommand.php
Created May 8, 2013 16:23
Let's say you're starting a new Yii project and you've already created the database schema for it using something like phpMyAdmin or MySQL Workbench. Now you want to create an initial database migration so you can put the schema under version control, but you don't want to manually write the Yii code to create the tables, indexes, and foreign ke…
<?php
class InitialDbMigrationCommand extends CConsoleCommand
{
public function run($args) {
$schema = $args[0];
$tables = Yii::app()->db->schema->getTables($schema);
$addForeignKeys = '';
$dropForeignKeys = '';