public function testParse() { $parser = new MysqlSchemaParser(Propel::getConnection('reverse-bookstore')); $parser->setGeneratorConfig(new QuickGeneratorConfig()); $database = new Database(); $database->setPlatform(new DefaultPlatform()); $this->assertEquals(1, $parser->parse($database), 'One table and one view defined should return one as we exclude views'); $tables = $database->getTables(); $this->assertEquals(1, count($tables)); $table = $tables[0]; $this->assertEquals('Book', $table->getPhpName()); $this->assertEquals(4, count($table->getColumns())); }
public function testDescColumn() { $schema = '<database name="reverse_bookstore"><table name="book"><column name="title" type="VARCHAR" size="255" description="Book Title with accent éài" /></table></database>'; $xtad = new XmlToAppData(); $appData = $xtad->parseString($schema); $database = $appData->getDatabase(); $table = $database->getTable('book'); $c1 = $table->getColumn('title'); $parser = new MysqlSchemaParser(Propel::getConnection('reverse-bookstore')); $parser->setGeneratorConfig(new QuickGeneratorConfig()); $database = new Database(); $database->setPlatform(new DefaultPlatform()); $parser->parse($database); $c2 = $database->getTable('book')->getColumn('title'); $this->assertEquals($c1->getDescription(), $c2->getDescription()); }
public function testDecimal() { $t1 = new Table('foo'); $schema = '<database name="reverse_bookstore"><table name="foo"><column name="longitude" type="DECIMAL" scale="7" size="10" /></table></database>'; $xtad = new XmlToAppData(); $appData = $xtad->parseString($schema); $database = $appData->getDatabase(); $table = $database->getTable('foo'); $c1 = $table->getColumn('longitude'); $parser = new MysqlSchemaParser(Propel::getConnection('reverse-bookstore')); $parser->setGeneratorConfig(new QuickGeneratorConfig()); $database = new Database(); $database->setPlatform(new MysqlPlatform()); $parser->parse($database); $table = $database->getTable('foo'); $c2 = $table->getColumn('longitude'); $this->assertEquals($c1->getSize(), $c2->getSize()); $this->assertEquals($c1->getScale(), $c2->getScale()); }
/** * * @param string $module * @param string $action */ public static function update($module, $action = 'create') { $targetDbName = 'centreon'; ini_set('memory_limit', '-1'); $di = Di::getDefault(); $config = $di->get('config'); $targetDb = 'db_centreon'; $db = $di->get($targetDb); // Configuration for Propel $configParams = array('propel.project' => 'centreon', 'propel.database' => 'mysql', 'propel.database.url' => $config->get($targetDb, 'dsn'), 'propel.database.user' => $config->get($targetDb, 'username'), 'propel.database.password' => $config->get($targetDb, 'password')); // Set the Current Platform and DB Connection $platform = new CentreonMysqlPlatform($db); // Initilize Schema Parser $propelDb = new \MysqlSchemaParser($db); $propelDb->setGeneratorConfig(new \GeneratorConfig($configParams)); $propelDb->setPlatform($platform); // get Current Db State $currentDbAppData = new \AppData($platform); $currentDbAppData->setGeneratorConfig(new \GeneratorConfig($configParams)); $currentDb = $currentDbAppData->addDatabase(array('name' => $targetDbName)); $propelDb->parse($currentDb); // Retreive target DB State $updatedAppData = new \AppData($platform); self::getDbFromXml($updatedAppData, 'centreon'); // Get diff between current db state and target db state $diff = \PropelDatabaseComparator::computeDiff($currentDb, $updatedAppData->getDatabase('centreon'), false); if ($diff !== false) { $strDiff = $platform->getModifyDatabaseDDL($diff); $sqlToBeExecuted = \PropelSQLParser::parseString($strDiff); $finalSql = "\nSET FOREIGN_KEY_CHECKS = 0;\n\n"; if ($action == 'create') { $finalSql .= implode(";\n\n", static::keepCreateStatement($sqlToBeExecuted, $module)); } elseif ($action == 'delete') { $finalSql .= implode(";\n\n", static::keepDeleteStatement($sqlToBeExecuted, $module)); } $finalSql .= ";\n\nSET FOREIGN_KEY_CHECKS = 1;\n\n"; \PropelSQLParser::executeString($finalSql, $db); } // Empty Target DB self::deleteTargetDbSchema($targetDbName); }
/** * @return Database */ function getDatabaseSchema() { ClassLoader::import('DATABASE:propel:'); ClassLoader::import('DATABASE:propel:model'); ClassLoader::import('DATABASE:propel:reverse'); ClassLoader::import('DATABASE:propel:reverse:mysql'); ClassLoader::import('DATABASE:propel:platform'); $parser = new MysqlSchemaParser($this); $database = new Database($this->getDBName()); $platform = new MysqlPlatform($this); $platform->setDefaultTableEngine('InnoDB'); $database->setPlatform($platform); $parser->parse($database); $database->doFinalInitialization(); return $database; }
public function readDatabase() { $this->database = new Database(); $this->database->setPlatform(new MysqlPlatform()); $this->parser->parse($this->database); }
protected static function initializeCurrentSchema($platform) { $configParams = array('propel.project' => 'centreon', 'propel.database' => 'mysql', 'propel.database.driver' => 'mysql', 'propel.database.createUrl' => 'mysql://root@localhost/', 'propel.database.url' => 'mysql:dbname=centreon;host=localhost', 'propel.database.user' => 'root', 'propel.database.password' => '', 'propel.database.encoding' => 'utf-8'); // Initilize Schema Parser $db = Di::getDefault()->get('db_centreon'); $propelDb = new \MysqlSchemaParser($db); $propelDb->setGeneratorConfig(new \GeneratorConfig($configParams)); $propelDb->setPlatform($platform); // get Current Db State $currentDbAppData = new \AppData($platform); $currentDbAppData->setGeneratorConfig(new \GeneratorConfig($configParams)); $currentDb = $currentDbAppData->addDatabase(array('name' => 'centreon')); $propelDb->parse($currentDb); return $currentDb; }