You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
64 lines
1.6 KiB
<?php
|
|
|
|
require('vendor/autoload.php');
|
|
|
|
if (!isset($argv[1]) || !file_exists($argv[1]))
|
|
{
|
|
die('Config file not specified or not found'.PHP_EOL);
|
|
}
|
|
|
|
$config = json_decode(file_get_contents($argv[1]), true);
|
|
|
|
if (!isset($config))
|
|
{
|
|
die('Invalid config file'.PHP_EOL);
|
|
}
|
|
|
|
$source_driver = $config['source']['driver'];
|
|
$source_config = $config['source']['config'];
|
|
$class = '\\DbCopy\\Driver\\'.$source_driver;
|
|
$source = new $class();
|
|
$source->open($source_config);
|
|
|
|
$target_driver = $config['target']['driver'];
|
|
$target_config = $config['target']['config'];
|
|
$class = '\\DbCopy\\Driver\\'.$target_driver;
|
|
$target = new $class();
|
|
$target->open($target_config);
|
|
|
|
$transforms = [];
|
|
if (isset($config['transform']))
|
|
{
|
|
foreach ($config['transform'] as $transform)
|
|
{
|
|
$transform_type = $transform['type'];
|
|
$transform_config = $transform['config'];
|
|
$class = '\\DbCopy\\Transform\\'.$transform_type;
|
|
$transforms[] = new $class($transform_config);
|
|
}
|
|
}
|
|
|
|
$filter_column = $config['filter']['column'];
|
|
$filter_values = $config['filter']['values'];
|
|
|
|
$copy_options = $config['options'];
|
|
|
|
$results = [];
|
|
|
|
foreach ($filter_values as $filter_value)
|
|
{
|
|
echo "===== COPYING $filter_column=$filter_value =====".PHP_EOL;
|
|
|
|
$copy = \DbCopy\Copy::create($copy_options);
|
|
// FIXME: This query thing is ES-specific
|
|
$copy->source($source, ['query'=>[$filter_column=>$filter_value]]);
|
|
$copy->destination($target);
|
|
if (!empty($transforms))
|
|
$copy->transform(\DbCopy\Transform\Group::create($transforms));
|
|
$count = $copy->execute();
|
|
echo "Copied: $count records".PHP_EOL;
|
|
$results[$filter_value] = $count;
|
|
}
|
|
|
|
var_dump($results);
|
|
|
|
|