junxiong
(Garry3peace)
March 15, 2011, 2:10am
1
On the db migration I’ve got perfect script from Leric for dumping the DB schema, so the developer doesn’t need to write manually when the db is big already. That script is very useful, but beside schema, I also need some script to dump the db records (e.g: records on lookup table, rbac tables or even user tables)
Is there any script for dumping db records like that?
schmunk
(Schmunk)
April 3, 2011, 10:01pm
2
Hi junxiong,
I am working with this at the moment, please have a look:
public function run($args) {
$schema = $args[0];
$tables = Yii::app()->db->schema->getTables($schema);
$result = '';
foreach ($tables as $def) {
$result .= '$this->createTable("' . $def->name . '", array(' . "\n";
foreach ($def->columns as $col) {
$result .= ' "' . $col->name . '"=>"' . $this->getColType($col) . '",' . "\n";
}
$result .= '), "");' . "\n\n";
$data = Yii::app()->db->createCommand()
->from($def->name)
->query();
foreach ($data AS $row) {
$result .= '$this->insert("' . $def->name . '", array(' . "\n";
foreach($row AS $column => $value) {
$result .= ' "' . $column . '"=>"' . $value . '",' . "\n";
}
$result .= ') );' . "\n\n";
}
}
echo $result;
}
Still very simple, but works
Best regards,
schmunk
codevarun
(Codevarun)
August 5, 2013, 10:50pm
4
Hi
I was also looking for solution, couldn’t find any thing that absolutely worked for me, So I wrote mine:
Please feel free to use it (Under MIT License)
It is in GIT here Deftmigrations
Thanks