SchemaInterface.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace PhpDevCommunity\PaperORM\Schema;
  3. use PhpDevCommunity\PaperORM\Mapping\Column\Column;
  4. use PhpDevCommunity\PaperORM\Metadata\ForeignKeyMetadata;
  5. use PhpDevCommunity\PaperORM\Metadata\ColumnMetadata;
  6. use PhpDevCommunity\PaperORM\Metadata\IndexMetadata;
  7. /**
  8. * Interface SchemaInterface
  9. *
  10. * Defines methods for managing database schema operations.
  11. */
  12. interface SchemaInterface
  13. {
  14. /**
  15. * Shows all databases.
  16. *
  17. * @return string Returns the SQL query for showing all databases.
  18. */
  19. public function showDatabases(): string;
  20. /**
  21. * Shows all tables in the database.
  22. *
  23. * @return string Returns the SQL query for showing all tables.
  24. */
  25. public function showTables(): string;
  26. public function showTableColumns(string $tableName): string;
  27. public function showForeignKeys(string $tableName): string;
  28. public function showTableIndexes(string $tableName): string;
  29. /**
  30. * Creates a new database.
  31. *
  32. * @param string $databaseName The name of the database to create.
  33. * @return string Returns the SQL query for creating the database.
  34. */
  35. public function createDatabase(string $databaseName): string;
  36. /**
  37. * Creates a new database if it does not exist.
  38. *
  39. * @param string $databaseName The name of the database to create.
  40. * @return string Returns the SQL query for creating the database if not exists.
  41. */
  42. public function createDatabaseIfNotExists(string $databaseName): string;
  43. /**
  44. * Drops an existing database.
  45. *
  46. * @param string $databaseName The name of the database to drop.
  47. * @return string Returns the SQL query for dropping the database.
  48. */
  49. public function dropDatabase(string $databaseName): string;
  50. /**
  51. * Creates a new table.
  52. *
  53. * @param string $tableName The name of the table to create.
  54. * @param array<ColumnMetadata> $columns An array of ColumnMetadata objects.
  55. * @param array $options Additional options for table creation.
  56. * @return string Returns the SQL query for creating the table.
  57. */
  58. public function createTable(string $tableName, array $columns, array $options = []): string;
  59. /**
  60. * Creates a new table if it does not exist.
  61. *
  62. * @param string $tableName The name of the table to create.
  63. * @param array<ColumnMetadata> $columns An array of ColumnMetadata objects.
  64. * @param array $options Additional options for table creation.
  65. * @return string Returns the SQL query for creating the table if not exists.
  66. */
  67. public function createTableIfNotExists(string $tableName, array $columns, array $options = []): string;
  68. /**
  69. * Adds a new foreign key constraint.
  70. *
  71. * @param string $tableName The name of the table to modify.
  72. * @param ForeignKeyMetadata $foreignKey The instance of the foreign key.
  73. * @return string Returns the SQL query for adding the foreign key constraint.
  74. */
  75. public function createForeignKeyConstraint(string $tableName, ForeignKeyMetadata $foreignKey) :string;
  76. /**
  77. * Drops an existing foreign key constraint.
  78. *
  79. * @param string $tableName The name of the table to modify.
  80. * @param string $foreignKeyName The name of the foreign key to drop.
  81. * @return string Returns the SQL query for dropping the foreign key constraint.
  82. */
  83. public function dropForeignKeyConstraints( string $tableName, string $foreignKeyName): string;
  84. /**
  85. * Drops an existing table.
  86. *
  87. * @param string $tableName The name of the table to drop.
  88. * @return string Returns the SQL query for dropping the table.
  89. */
  90. public function dropTable(string $tableName): string;
  91. /**
  92. * Renames an existing table.
  93. *
  94. * @param string $oldTableName The current name of the table.
  95. * @param string $newTableName The new name for the table.
  96. * @return string Returns the SQL query for renaming the table.
  97. */
  98. public function renameTable(string $oldTableName, string $newTableName): string;
  99. /**
  100. * Adds a new column to an existing table.
  101. *
  102. * @param string $tableName The name of the table to modify.
  103. * @param ColumnMetadata $columnMetadata The name of the new column.
  104. * @return string Returns the SQL query for adding the column.
  105. */
  106. public function addColumn(string $tableName, ColumnMetadata $columnMetadata): string;
  107. /**
  108. * Drops an existing column from a table.
  109. *
  110. * @param string $tableName The name of the table to modify.
  111. * @param ColumnMetadata $columnMetadata The column to drop.
  112. * @return string Returns the SQL query for dropping the column.
  113. */
  114. public function dropColumn(string $tableName, ColumnMetadata $columnMetadata): string;
  115. /**
  116. * Modifies the definition of an existing column in a table.
  117. *
  118. * @param string $tableName The name of the table to modify.
  119. * @param ColumnMetadata $columnMetadata The column to modify.
  120. * @return string Returns the SQL query for modifying the column.
  121. */
  122. public function modifyColumn(string $tableName, ColumnMetadata $columnMetadata): string;
  123. /**
  124. * Creates a new index on a table.
  125. *
  126. * @param IndexMetadata $indexMetadata
  127. * @return string Returns the SQL query for creating the index.
  128. */
  129. public function createIndex(IndexMetadata $indexMetadata): string;
  130. /**
  131. * Drops an existing index from a table.
  132. *
  133. * @param IndexMetadata $indexMetadata
  134. * @return string Returns the SQL query for dropping the index.
  135. */
  136. public function dropIndex(IndexMetadata $indexMetadata): string;
  137. /**
  138. * Returns the format string for DateTime objects.
  139. *
  140. * @return string The format string.
  141. */
  142. public function getDateTimeFormatString(): string;
  143. /**
  144. * Returns the format string for Date objects.
  145. *
  146. * @return string The format string.
  147. */
  148. public function getDateFormatString(): string;
  149. /**
  150. * Checks if the database supports foreign key constraints.
  151. *
  152. * @return bool True if supported, false otherwise.
  153. */
  154. public function supportsForeignKeyConstraints(): bool;
  155. /**
  156. * Checks if the database supports indexes.
  157. *
  158. * @return bool True if supported, false otherwise.
  159. */
  160. public function supportsIndexes(): bool;
  161. /**
  162. * Checks if the database supports transactions.
  163. *
  164. * @return bool True if supported, false otherwise.
  165. */
  166. public function supportsTransactions(): bool;
  167. /**
  168. * Checks if the database supports dropping columns from a table.
  169. *
  170. * @return bool True if supported, false otherwise.
  171. */
  172. public function supportsDropColumn(): bool;
  173. /**
  174. * Checks if the database supports modifying the type of a column.
  175. *
  176. * @return bool True if supported, false otherwise.
  177. */
  178. public function supportsModifyColumn(): bool;
  179. /**
  180. * Checks if the database supports adding foreign keys.
  181. *
  182. * @return bool True if supported, false otherwise.
  183. */
  184. public function supportsAddForeignKey(): bool;
  185. public function supportsDropForeignKey(): bool;
  186. }