* This is a list of tables where nulls
 * will be converted to an empty string.
 *
 * (no 'sq_' at the start!)
 */
$nulls_convert_list = array('ast_lnk');
/**
 * If it's the first run, we'll do some extra work
 * - drop sequences
 * - drop indexes
 *
 * They are rebuilt as xml files are processed
 */
$first_run = true;
foreach ($xml_files as $xml_filename) {
    $info = parse_tables_xml($xml_filename, $dest_db);
    if (empty($info)) {
        continue;
    }
    /**
     * get sequence values from the source db
     */
    MatrixDAL::changeDb($source_db);
    foreach ($info['sequences'] as $sequence) {
        $sequence_values[$sequence] = getSequenceValue($sequence);
    }
    /**
     * Switch to the destination db to
     * - drop sequences
     * - drop indexes
     * - truncate data tables
/**
* Returns the all the db tables info
*
* @return array
* @access public
*/
function get_tables_info()
{
    require_once SQ_LIB_PATH . '/db_install/db_install.inc';
    $packages_installed = $GLOBALS['SQ_SYSTEM']->getInstalledPackages();
    if (empty($packages_installed)) {
        return array();
    }
    $table_info = array();
    foreach ($packages_installed as $package_array) {
        if ($package_array['code_name'] == '__core__') {
            $table_file = SQ_CORE_PACKAGE_PATH . '/tables.xml';
        } else {
            $table_file = SQ_PACKAGES_PATH . '/' . $package_array['code_name'] . '/tables.xml';
        }
        if (file_exists($table_file)) {
            $table_data = parse_tables_xml($table_file);
            $table_info += $table_data['tables'];
        }
    }
    return $table_info;
}
$packages = $GLOBALS['SQ_SYSTEM']->getInstalledPackages();
foreach ($packages as $_pkgid => $pkg_details) {
    $pkg_name = $pkg_details['code_name'];
    if ($pkg_name == '__core__') {
        $file = $SYSTEM_ROOT . '/core/assets/tables.xml';
    } else {
        $file = SQ_PACKAGES_PATH . '/' . $pkg_name . '/tables.xml';
    }
    /**
     * If the package doesn't have a tables.xml,
     * it doesn't have any particular db tables to check.
     */
    if (!is_file($file)) {
        continue;
    }
    $info = parse_tables_xml($file, $db_conf['db']['type']);
    foreach ($info['tables'] as $tablename => $table_info) {
        $tables = array($tablename);
        if ($table_info['rollback']) {
            $tables[] = 'rb_' . $tablename;
        }
        if (!empty($table_info['primary_key'])) {
            foreach ($tables as $tablename) {
                /**
                 * There are 4 ways a primary key is named:
                 * $tablename . '_pkey',
                 * $tablename . '_pk',
                 * 'sq_' . $tablename . '_pkey',
                 * 'sq_' . $tablename . '_pk',
                 *
                 * we expect the name to be