示例#1
0
//Set DB connection
//$xmi2db->setConn("dbname=moro user=kvwmap password=kv_Map-12:)");
$xmi2db->setConn($db_conn);
// The table name for the insert queries
$xmi2db->setTable(array("classes" => "uml_classes", "attributes" => "uml_attributes", "association_classes" => "association_classes", "class_generalizations" => "class_generalizations", "packages" => "packages", "stereotypes" => "stereotypes"));
//Create Schema and Table structure if needed
$schema_sql = "\n  SELECT EXISTS(\n    SELECT\n      schema_name\n    FROM\n      information_schema.schemata\n    WHERE\n      schema_name = '" . $_REQUEST['schema'] . "'\n  )\n";
#echo $schema_sql;
//echo "<br>";
$result = pg_query($db_conn, $schema_sql);
$schemaBool = pg_fetch_row($result);
if ($schemaBool[0] == 't') {
    echo "Schema vorhanden<br>";
    //Truncate if wanted
    if ($_REQUEST['truncate'] == 1) {
        $xmi2db->truncateTables();
    }
} else {
    echo "Schema NICHT vorhanden<br>";
    //Load SQL dump file and replace "schema_name" placeholder with desired schema name
    $sql_dump = file_get_contents('sql/db-schema.sql');
    //echo $sql_dump;
    $sql_dump2 = str_replace('schema_name', $_REQUEST['schema'], $sql_dump);
    //echo $sql_dump2;
    pg_query($db_conn, $sql_dump2);
    //Check for additional migration files (e.g. 20150731_mig.sql)
    $migration_files = scandir('sql');
    foreach ($migration_files as $migration_file) {
        if (strpos($migration_file, '_mig')) {
            echo 'mig file ' . $migration_file . ' found';
            //Load SQL migration file and replace "schema_name" placeholder with desired schema name