PHP code example of ruckusing / ruckusing-migrations
1. Go to this page and download the library: Download ruckusing/ruckusing-migrations library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ruckusing / ruckusing-migrations example snippets
# ruckusing.conf.php
return array(
/* ... snip ... */,
'tasks_dir' => RUCKUSING_WORKING_BASE . '/custom_tasks'
);
$this->create_database("my_project");
$this->drop_database("my_project");
$users = $this->create_table("users");
$users->column("first_name", "string");
$users->column("last_name", "string");
$users->finish();
$this->create_table('users', array('options' => 'Engine=InnoDB'));
$this->create_table('users', array('id' => false));
$t = $this->create_table('users', array('id' => false, 'options' => 'Engine=InnoDB'));
$t->column('guid', 'string', array('primary_key' => true, 'limit' => 64));
$t->finish();
$this->drop_table("users");
// rename from "users" to "people"
$this->rename_table("users", "people");
$this->remove_column("users", "age");
$this->rename_column("users", "first_name", "fname");
$this->change_column("users", "first_name", "string", array('limit' => 128) );
$this->add_timestamps("users");
$this->add_timestamps("users", "created", "updated");
$this->add_index("users", "email");
$this->add_index("users", "ssn", array('unique' => true)));
$this->add_index("posts", "blog_id", array('name' => 'index_on_blog_id'));
$this->add_index("users", array('email', 'ssn') );
$this->remove_index("users", "email");
$this->remove_index("users", array("email", "ssn") );
$this->remove_index("users", "email", array('name' => "index_on_email_column") );
$this->execute("UPDATE foo SET name = 'bar' WHERE .... ");
$result = $this->select_one("SELECT SUM(total_price) AS total_price FROM orders");
if($result) {
echo "Your revenue is: " . $result['total_price'];
}
$result = $this->select_all("SELECT email, first_name, last_name FROM users WHERE created_at >= SUBDATE( NOW(), INTERVAL 7 DAY)");
if($result) {
echo "New customers: (" . count($result) . ")\n";
foreach($result as $row) {
printf("(%s) %s %s\n", $row['email'], $row['first_name'], $row['last_name']);
}
}
$ php ruckus.php db:generate create_users_table
Created OK
Created migration: 20121112163653_CreateUsersTable.php
$ php ruckus.php db:generate create_items_table module=module_name
Created OK
Created migration: 20121112163653_CreateItemsTable.php
class CreateUsersTable extends Ruckusing_Migration_Base {
public function up() {
}//up()
public function down() {
}//down()
}
$ ENV=test php db:migrate
$ php ruckus.php db:migrate
$ php ruckus.php db:migrate VERSION=-1
$ php ruckus.php db:migrate VERSION=20121114001742
bash
$ vi config/database.inc.php
$ mysql -uroot -p < tests/test.sql
$ phpunit tests/unit/MySQLAdapterTest.php