AbstractSchemaManager.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Schema;
  20. use Doctrine\DBAL\Types;
  21. use Doctrine\DBAL\DBALException;
  22. use Doctrine\DBAL\Platforms\AbstractPlatform;
  23. /**
  24. * Base class for schema managers. Schema managers are used to inspect and/or
  25. * modify the database schema/structure.
  26. *
  27. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
  29. * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  30. * @author Roman Borschel <roman@code-factory.org>
  31. * @author Jonathan H. Wage <jonwage@gmail.com>
  32. * @author Benjamin Eberlei <kontakt@beberlei.de>
  33. * @since 2.0
  34. */
  35. abstract class AbstractSchemaManager
  36. {
  37. /**
  38. * Holds instance of the Doctrine connection for this schema manager
  39. *
  40. * @var \Doctrine\DBAL\Connection
  41. */
  42. protected $_conn;
  43. /**
  44. * Holds instance of the database platform used for this schema manager
  45. *
  46. * @var \Doctrine\DBAL\Platforms\AbstractPlatform
  47. */
  48. protected $_platform;
  49. /**
  50. * Constructor. Accepts the Connection instance to manage the schema for
  51. *
  52. * @param \Doctrine\DBAL\Connection $conn
  53. */
  54. public function __construct(\Doctrine\DBAL\Connection $conn)
  55. {
  56. $this->_conn = $conn;
  57. $this->_platform = $this->_conn->getDatabasePlatform();
  58. }
  59. /**
  60. * Return associated platform.
  61. *
  62. * @return \Doctrine\DBAL\Platform\AbstractPlatform
  63. */
  64. public function getDatabasePlatform()
  65. {
  66. return $this->_platform;
  67. }
  68. /**
  69. * Try any method on the schema manager. Normally a method throws an
  70. * exception when your DBMS doesn't support it or if an error occurs.
  71. * This method allows you to try and method on your SchemaManager
  72. * instance and will return false if it does not work or is not supported.
  73. *
  74. * <code>
  75. * $result = $sm->tryMethod('dropView', 'view_name');
  76. * </code>
  77. *
  78. * @return mixed
  79. */
  80. public function tryMethod()
  81. {
  82. $args = func_get_args();
  83. $method = $args[0];
  84. unset($args[0]);
  85. $args = array_values($args);
  86. try {
  87. return call_user_func_array(array($this, $method), $args);
  88. } catch (\Exception $e) {
  89. return false;
  90. }
  91. }
  92. /**
  93. * List the available databases for this connection
  94. *
  95. * @return array $databases
  96. */
  97. public function listDatabases()
  98. {
  99. $sql = $this->_platform->getListDatabasesSQL();
  100. $databases = $this->_conn->fetchAll($sql);
  101. return $this->_getPortableDatabasesList($databases);
  102. }
  103. /**
  104. * List the available sequences for this connection
  105. *
  106. * @return Sequence[]
  107. */
  108. public function listSequences($database = null)
  109. {
  110. if (is_null($database)) {
  111. $database = $this->_conn->getDatabase();
  112. }
  113. $sql = $this->_platform->getListSequencesSQL($database);
  114. $sequences = $this->_conn->fetchAll($sql);
  115. return $this->_getPortableSequencesList($sequences);
  116. }
  117. /**
  118. * List the columns for a given table.
  119. *
  120. * In contrast to other libraries and to the old version of Doctrine,
  121. * this column definition does try to contain the 'primary' field for
  122. * the reason that it is not portable accross different RDBMS. Use
  123. * {@see listTableIndexes($tableName)} to retrieve the primary key
  124. * of a table. We're a RDBMS specifies more details these are held
  125. * in the platformDetails array.
  126. *
  127. * @param string $table The name of the table.
  128. * @param string $database
  129. * @return Column[]
  130. */
  131. public function listTableColumns($table, $database = null)
  132. {
  133. if (!$database) {
  134. $database = $this->_conn->getDatabase();
  135. }
  136. $sql = $this->_platform->getListTableColumnsSQL($table, $database);
  137. $tableColumns = $this->_conn->fetchAll($sql);
  138. return $this->_getPortableTableColumnList($tableColumns);
  139. }
  140. /**
  141. * List the indexes for a given table returning an array of Index instances.
  142. *
  143. * Keys of the portable indexes list are all lower-cased.
  144. *
  145. * @param string $table The name of the table
  146. * @return Index[] $tableIndexes
  147. */
  148. public function listTableIndexes($table)
  149. {
  150. $sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
  151. $tableIndexes = $this->_conn->fetchAll($sql);
  152. return $this->_getPortableTableIndexesList($tableIndexes, $table);
  153. }
  154. /**
  155. * Return true if all the given tables exist.
  156. *
  157. * @param array $tableNames
  158. * @return bool
  159. */
  160. public function tablesExist($tableNames)
  161. {
  162. $tableNames = array_map('strtolower', (array)$tableNames);
  163. return count($tableNames) == count(\array_intersect($tableNames, array_map('strtolower', $this->listTableNames())));
  164. }
  165. /**
  166. * Return a list of all tables in the current database
  167. *
  168. * @return array
  169. */
  170. public function listTableNames()
  171. {
  172. $sql = $this->_platform->getListTablesSQL();
  173. $tables = $this->_conn->fetchAll($sql);
  174. return $this->_getPortableTablesList($tables);
  175. }
  176. /**
  177. * List the tables for this connection
  178. *
  179. * @return Table[]
  180. */
  181. public function listTables()
  182. {
  183. $tableNames = $this->listTableNames();
  184. $tables = array();
  185. foreach ($tableNames AS $tableName) {
  186. $tables[] = $this->listTableDetails($tableName);
  187. }
  188. return $tables;
  189. }
  190. /**
  191. * @param string $tableName
  192. * @return Table
  193. */
  194. public function listTableDetails($tableName)
  195. {
  196. $columns = $this->listTableColumns($tableName);
  197. $foreignKeys = array();
  198. if ($this->_platform->supportsForeignKeyConstraints()) {
  199. $foreignKeys = $this->listTableForeignKeys($tableName);
  200. }
  201. $indexes = $this->listTableIndexes($tableName);
  202. return new Table($tableName, $columns, $indexes, $foreignKeys, false, array());
  203. }
  204. /**
  205. * List the views this connection has
  206. *
  207. * @return View[]
  208. */
  209. public function listViews()
  210. {
  211. $database = $this->_conn->getDatabase();
  212. $sql = $this->_platform->getListViewsSQL($database);
  213. $views = $this->_conn->fetchAll($sql);
  214. return $this->_getPortableViewsList($views);
  215. }
  216. /**
  217. * List the foreign keys for the given table
  218. *
  219. * @param string $table The name of the table
  220. * @return ForeignKeyConstraint[]
  221. */
  222. public function listTableForeignKeys($table, $database = null)
  223. {
  224. if (is_null($database)) {
  225. $database = $this->_conn->getDatabase();
  226. }
  227. $sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
  228. $tableForeignKeys = $this->_conn->fetchAll($sql);
  229. return $this->_getPortableTableForeignKeysList($tableForeignKeys);
  230. }
  231. /* drop*() Methods */
  232. /**
  233. * Drops a database.
  234. *
  235. * NOTE: You can not drop the database this SchemaManager is currently connected to.
  236. *
  237. * @param string $database The name of the database to drop
  238. */
  239. public function dropDatabase($database)
  240. {
  241. $this->_execSql($this->_platform->getDropDatabaseSQL($database));
  242. }
  243. /**
  244. * Drop the given table
  245. *
  246. * @param string $table The name of the table to drop
  247. */
  248. public function dropTable($table)
  249. {
  250. $this->_execSql($this->_platform->getDropTableSQL($table));
  251. }
  252. /**
  253. * Drop the index from the given table
  254. *
  255. * @param Index|string $index The name of the index
  256. * @param string|Table $table The name of the table
  257. */
  258. public function dropIndex($index, $table)
  259. {
  260. if($index instanceof Index) {
  261. $index = $index->getQuotedName($this->_platform);
  262. }
  263. $this->_execSql($this->_platform->getDropIndexSQL($index, $table));
  264. }
  265. /**
  266. * Drop the constraint from the given table
  267. *
  268. * @param Constraint $constraint
  269. * @param string $table The name of the table
  270. */
  271. public function dropConstraint(Constraint $constraint, $table)
  272. {
  273. $this->_execSql($this->_platform->getDropConstraintSQL($constraint, $table));
  274. }
  275. /**
  276. * Drops a foreign key from a table.
  277. *
  278. * @param ForeignKeyConstraint|string $table The name of the table with the foreign key.
  279. * @param Table|string $name The name of the foreign key.
  280. * @return boolean $result
  281. */
  282. public function dropForeignKey($foreignKey, $table)
  283. {
  284. $this->_execSql($this->_platform->getDropForeignKeySQL($foreignKey, $table));
  285. }
  286. /**
  287. * Drops a sequence with a given name.
  288. *
  289. * @param string $name The name of the sequence to drop.
  290. */
  291. public function dropSequence($name)
  292. {
  293. $this->_execSql($this->_platform->getDropSequenceSQL($name));
  294. }
  295. /**
  296. * Drop a view
  297. *
  298. * @param string $name The name of the view
  299. * @return boolean $result
  300. */
  301. public function dropView($name)
  302. {
  303. $this->_execSql($this->_platform->getDropViewSQL($name));
  304. }
  305. /* create*() Methods */
  306. /**
  307. * Creates a new database.
  308. *
  309. * @param string $database The name of the database to create.
  310. */
  311. public function createDatabase($database)
  312. {
  313. $this->_execSql($this->_platform->getCreateDatabaseSQL($database));
  314. }
  315. /**
  316. * Create a new table.
  317. *
  318. * @param Table $table
  319. * @param int $createFlags
  320. */
  321. public function createTable(Table $table)
  322. {
  323. $createFlags = AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS;
  324. $this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
  325. }
  326. /**
  327. * Create a new sequence
  328. *
  329. * @param Sequence $sequence
  330. * @throws Doctrine\DBAL\ConnectionException if something fails at database level
  331. */
  332. public function createSequence($sequence)
  333. {
  334. $this->_execSql($this->_platform->getCreateSequenceSQL($sequence));
  335. }
  336. /**
  337. * Create a constraint on a table
  338. *
  339. * @param Constraint $constraint
  340. * @param string|Table $table
  341. */
  342. public function createConstraint(Constraint $constraint, $table)
  343. {
  344. $this->_execSql($this->_platform->getCreateConstraintSQL($constraint, $table));
  345. }
  346. /**
  347. * Create a new index on a table
  348. *
  349. * @param Index $index
  350. * @param string $table name of the table on which the index is to be created
  351. */
  352. public function createIndex(Index $index, $table)
  353. {
  354. $this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
  355. }
  356. /**
  357. * Create a new foreign key
  358. *
  359. * @param ForeignKeyConstraint $foreignKey ForeignKey instance
  360. * @param string|Table $table name of the table on which the foreign key is to be created
  361. */
  362. public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
  363. {
  364. $this->_execSql($this->_platform->getCreateForeignKeySQL($foreignKey, $table));
  365. }
  366. /**
  367. * Create a new view
  368. *
  369. * @param View $view
  370. */
  371. public function createView(View $view)
  372. {
  373. $this->_execSql($this->_platform->getCreateViewSQL($view->getQuotedName($this->_platform), $view->getSql()));
  374. }
  375. /* dropAndCreate*() Methods */
  376. /**
  377. * Drop and create a constraint
  378. *
  379. * @param Constraint $constraint
  380. * @param string $table
  381. * @see dropConstraint()
  382. * @see createConstraint()
  383. */
  384. public function dropAndCreateConstraint(Constraint $constraint, $table)
  385. {
  386. $this->tryMethod('dropConstraint', $constraint, $table);
  387. $this->createConstraint($constraint, $table);
  388. }
  389. /**
  390. * Drop and create a new index on a table
  391. *
  392. * @param string|Table $table name of the table on which the index is to be created
  393. * @param Index $index
  394. */
  395. public function dropAndCreateIndex(Index $index, $table)
  396. {
  397. $this->tryMethod('dropIndex', $index->getQuotedName($this->_platform), $table);
  398. $this->createIndex($index, $table);
  399. }
  400. /**
  401. * Drop and create a new foreign key
  402. *
  403. * @param ForeignKeyConstraint $foreignKey associative array that defines properties of the foreign key to be created.
  404. * @param string|Table $table name of the table on which the foreign key is to be created
  405. */
  406. public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
  407. {
  408. $this->tryMethod('dropForeignKey', $foreignKey, $table);
  409. $this->createForeignKey($foreignKey, $table);
  410. }
  411. /**
  412. * Drop and create a new sequence
  413. *
  414. * @param Sequence $sequence
  415. * @throws Doctrine\DBAL\ConnectionException if something fails at database level
  416. */
  417. public function dropAndCreateSequence(Sequence $sequence)
  418. {
  419. $this->tryMethod('dropSequence', $sequence->getQuotedName($this->_platform));
  420. $this->createSequence($sequence);
  421. }
  422. /**
  423. * Drop and create a new table.
  424. *
  425. * @param Table $table
  426. */
  427. public function dropAndCreateTable(Table $table)
  428. {
  429. $this->tryMethod('dropTable', $table->getQuotedName($this->_platform));
  430. $this->createTable($table);
  431. }
  432. /**
  433. * Drop and creates a new database.
  434. *
  435. * @param string $database The name of the database to create.
  436. */
  437. public function dropAndCreateDatabase($database)
  438. {
  439. $this->tryMethod('dropDatabase', $database);
  440. $this->createDatabase($database);
  441. }
  442. /**
  443. * Drop and create a new view
  444. *
  445. * @param View $view
  446. */
  447. public function dropAndCreateView(View $view)
  448. {
  449. $this->tryMethod('dropView', $view->getQuotedName($this->_platform));
  450. $this->createView($view);
  451. }
  452. /* alterTable() Methods */
  453. /**
  454. * Alter an existing tables schema
  455. *
  456. * @param TableDiff $tableDiff
  457. */
  458. public function alterTable(TableDiff $tableDiff)
  459. {
  460. $queries = $this->_platform->getAlterTableSQL($tableDiff);
  461. if (is_array($queries) && count($queries)) {
  462. foreach ($queries AS $ddlQuery) {
  463. $this->_execSql($ddlQuery);
  464. }
  465. }
  466. }
  467. /**
  468. * Rename a given table to another name
  469. *
  470. * @param string $name The current name of the table
  471. * @param string $newName The new name of the table
  472. */
  473. public function renameTable($name, $newName)
  474. {
  475. $tableDiff = new TableDiff($name);
  476. $tableDiff->newName = $newName;
  477. $this->alterTable($tableDiff);
  478. }
  479. /**
  480. * Methods for filtering return values of list*() methods to convert
  481. * the native DBMS data definition to a portable Doctrine definition
  482. */
  483. protected function _getPortableDatabasesList($databases)
  484. {
  485. $list = array();
  486. foreach ($databases as $key => $value) {
  487. if ($value = $this->_getPortableDatabaseDefinition($value)) {
  488. $list[] = $value;
  489. }
  490. }
  491. return $list;
  492. }
  493. protected function _getPortableDatabaseDefinition($database)
  494. {
  495. return $database;
  496. }
  497. protected function _getPortableFunctionsList($functions)
  498. {
  499. $list = array();
  500. foreach ($functions as $key => $value) {
  501. if ($value = $this->_getPortableFunctionDefinition($value)) {
  502. $list[] = $value;
  503. }
  504. }
  505. return $list;
  506. }
  507. protected function _getPortableFunctionDefinition($function)
  508. {
  509. return $function;
  510. }
  511. protected function _getPortableTriggersList($triggers)
  512. {
  513. $list = array();
  514. foreach ($triggers as $key => $value) {
  515. if ($value = $this->_getPortableTriggerDefinition($value)) {
  516. $list[] = $value;
  517. }
  518. }
  519. return $list;
  520. }
  521. protected function _getPortableTriggerDefinition($trigger)
  522. {
  523. return $trigger;
  524. }
  525. protected function _getPortableSequencesList($sequences)
  526. {
  527. $list = array();
  528. foreach ($sequences as $key => $value) {
  529. if ($value = $this->_getPortableSequenceDefinition($value)) {
  530. $list[] = $value;
  531. }
  532. }
  533. return $list;
  534. }
  535. /**
  536. * @param array $sequence
  537. * @return Sequence
  538. */
  539. protected function _getPortableSequenceDefinition($sequence)
  540. {
  541. throw DBALException::notSupported('Sequences');
  542. }
  543. /**
  544. * Independent of the database the keys of the column list result are lowercased.
  545. *
  546. * The name of the created column instance however is kept in its case.
  547. *
  548. * @param array $tableColumns
  549. * @return array
  550. */
  551. protected function _getPortableTableColumnList($tableColumns)
  552. {
  553. $list = array();
  554. foreach ($tableColumns as $key => $column) {
  555. if ($column = $this->_getPortableTableColumnDefinition($column)) {
  556. $name = strtolower($column->getQuotedName($this->_platform));
  557. $list[$name] = $column;
  558. }
  559. }
  560. return $list;
  561. }
  562. /**
  563. * Get Table Column Definition
  564. *
  565. * @param array $tableColumn
  566. * @return Column
  567. */
  568. abstract protected function _getPortableTableColumnDefinition($tableColumn);
  569. /**
  570. * Aggregate and group the index results according to the required data result.
  571. *
  572. * @param array $tableIndexRows
  573. * @param string $tableName
  574. * @return array
  575. */
  576. protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null)
  577. {
  578. $result = array();
  579. foreach($tableIndexRows AS $tableIndex) {
  580. $indexName = $keyName = $tableIndex['key_name'];
  581. if($tableIndex['primary']) {
  582. $keyName = 'primary';
  583. }
  584. $keyName = strtolower($keyName);
  585. if(!isset($result[$keyName])) {
  586. $result[$keyName] = array(
  587. 'name' => $indexName,
  588. 'columns' => array($tableIndex['column_name']),
  589. 'unique' => $tableIndex['non_unique'] ? false : true,
  590. 'primary' => $tableIndex['primary'],
  591. );
  592. } else {
  593. $result[$keyName]['columns'][] = $tableIndex['column_name'];
  594. }
  595. }
  596. $indexes = array();
  597. foreach($result AS $indexKey => $data) {
  598. $indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
  599. }
  600. return $indexes;
  601. }
  602. protected function _getPortableTablesList($tables)
  603. {
  604. $list = array();
  605. foreach ($tables as $key => $value) {
  606. if ($value = $this->_getPortableTableDefinition($value)) {
  607. $list[] = $value;
  608. }
  609. }
  610. return $list;
  611. }
  612. protected function _getPortableTableDefinition($table)
  613. {
  614. return $table;
  615. }
  616. protected function _getPortableUsersList($users)
  617. {
  618. $list = array();
  619. foreach ($users as $key => $value) {
  620. if ($value = $this->_getPortableUserDefinition($value)) {
  621. $list[] = $value;
  622. }
  623. }
  624. return $list;
  625. }
  626. protected function _getPortableUserDefinition($user)
  627. {
  628. return $user;
  629. }
  630. protected function _getPortableViewsList($views)
  631. {
  632. $list = array();
  633. foreach ($views as $key => $value) {
  634. if ($view = $this->_getPortableViewDefinition($value)) {
  635. $viewName = strtolower($view->getQuotedName($this->_platform));
  636. $list[$viewName] = $view;
  637. }
  638. }
  639. return $list;
  640. }
  641. protected function _getPortableViewDefinition($view)
  642. {
  643. return false;
  644. }
  645. protected function _getPortableTableForeignKeysList($tableForeignKeys)
  646. {
  647. $list = array();
  648. foreach ($tableForeignKeys as $key => $value) {
  649. if ($value = $this->_getPortableTableForeignKeyDefinition($value)) {
  650. $list[] = $value;
  651. }
  652. }
  653. return $list;
  654. }
  655. protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
  656. {
  657. return $tableForeignKey;
  658. }
  659. protected function _execSql($sql)
  660. {
  661. foreach ((array) $sql as $query) {
  662. $this->_conn->executeUpdate($query);
  663. }
  664. }
  665. /**
  666. * Create a schema instance for the current database.
  667. *
  668. * @return Schema
  669. */
  670. public function createSchema()
  671. {
  672. $sequences = array();
  673. if($this->_platform->supportsSequences()) {
  674. $sequences = $this->listSequences();
  675. }
  676. $tables = $this->listTables();
  677. return new Schema($tables, $sequences, $this->createSchemaConfig());
  678. }
  679. /**
  680. * Create the configuration for this schema.
  681. *
  682. * @return SchemaConfig
  683. */
  684. public function createSchemaConfig()
  685. {
  686. $schemaConfig = new SchemaConfig();
  687. $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
  688. return $schemaConfig;
  689. }
  690. /**
  691. * Given a table comment this method tries to extract a typehint for Doctrine Type, or returns
  692. * the type given as default.
  693. *
  694. * @param string $comment
  695. * @param string $currentType
  696. * @return string
  697. */
  698. public function extractDoctrineTypeFromComment($comment, $currentType)
  699. {
  700. if (preg_match("(\(DC2Type:([a-zA-Z0-9]+)\))", $comment, $match)) {
  701. $currentType = $match[1];
  702. }
  703. return $currentType;
  704. }
  705. public function removeDoctrineTypeFromComment($comment, $type)
  706. {
  707. return str_replace('(DC2Type:'.$type.')', '', $comment);
  708. }
  709. }