예제 #1
0
        }
        $generator->generate($ormDomain);
    }
    if ($schema) {
        if (!$db && $ormDomain->getDbSchema()) {
            $db = $ormDomain->getDbSchema();
        }
        if ($db) {
            try {
                $dbObject = DBPool::get($db);
            } catch (ArgumentException $e) {
                stop("Unknown database reference: {$db}");
            }
        }
        if ($schemaFile) {
            $schemaFile = $appDir . DIRECTORY_SEPARATOR . $schemaFile;
        } else {
            $schemaFile = $appDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'db' . DIRECTORY_SEPARATOR . strtolower($dbObject->getDialect()->getDBDriver()->getValue()) . '-' . pathinfo($xmlSchema, PATHINFO_FILENAME) . '.sql';
            $dir = dirname($schemaFile);
            if (!is_dir($dir)) {
                mkdir($dir, 0755, true);
            }
        }
        $schemaBuilder = new DBSchemaBuilder($ormDomain);
        $schemaConstructor = new SqlSchemaConstructor($schemaBuilder->build());
        $schemaConstructor->make(new FileWriteStream($schemaFile), $dbObject->getDialect());
    }
} catch (Exception $e) {
    stop($e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine());
}
echo 'Done', PHP_EOL;
예제 #2
0
파일: make.php 프로젝트: phoebius/phoebius
        if (!is_dir($dir)) {
            mkdir($dir, 0755, true);
        }
        if (!$db && $ormDomain->getDbSchema()) {
            $db = $ormDomain->getDbSchema();
        }
        if ($db) {
            try {
                $dbObject = DBPool::get($db);
            } catch (ArgumentException $e) {
                stop("Unknown database reference: {$db}");
            }
        } else {
            stop('You should specify db to use');
        }
        message('Loading diff schema: ' . $diffDomainFile);
        $domainBuilder = new XmlOrmDomainBuilder($diffDomainFile);
        $diffOrmDomain = $domainBuilder->build();
        message('Writing diff to ' . $diffSqlFile);
        $dbDiff = new DBDiff();
        $schemaBuilderOld = new DBSchemaBuilder($diffOrmDomain);
        $schemaOld = $schemaBuilderOld->build();
        $schemaBuilderNew = new DBSchemaBuilder($ormDomain);
        $schemaNew = $schemaBuilderNew->build();
        $dbDiff->make($schemaOld, $schemaNew);
        file_put_contents($diffSqlFile, $dbDiff->toDialectString($dbObject->getDialect()));
    }
} catch (OrmModelIntegrityException $e) {
    stop($e->getMessage());
}
echo 'Done', PHP_EOL;