1- Schema-Manager
1+ Schema manager
22==============
33
4- A Schema Manager instance helps you with the abstraction of the
5- generation of SQL assets such as Tables, Sequences, Foreign Keys
6- and Indexes .
4+ A schema manager instance helps you with the abstraction of the
5+ generation of SQL objects such as tables, sequences, foreign key
6+ constraints and indexes .
77
88To instantiate a ``SchemaManager `` for your connection you can use
99the ``createSchemaManager() `` method:
@@ -14,46 +14,30 @@ the ``createSchemaManager()`` method:
1414 $schemaManager = $conn->createSchemaManager();
1515
1616 Now with the ``SchemaManager `` instance in ``$schemaManager `` you can use the
17- available methods to learn about your database schema:
17+ available methods to learn about your database schema.
1818
19- .. note ::
19+ Introspecting database names
20+ ----------------------------
2021
21- Parameters containing identifiers passed to the SchemaManager
22- methods are *NOT * quoted automatically! Identifier quoting is
23- really difficult to do manually in a consistent way across
24- different databases. You have to manually quote the identifiers
25- when you accept data from user or other sources not under your
26- control.
27-
28- listDatabases()
29- ---------------
30-
31- Retrieve an array of databases on the configured connection:
22+ Retrieve a list of the names of available databases:
3223
3324.. code-block :: php
3425
3526 <?php
36- $databases = $sm->listDatabases();
37-
38- listSequences()
39- ---------------
40-
41- Retrieve an array of ``Doctrine\DBAL\Schema\Sequence `` instances
42- that exist for a database:
27+ $databaseNames = $schemaManager->introspectDatabaseNames();
4328
44- .. code-block :: php
45-
46- <?php
47- $sequences = $sm->listSequences();
29+ Introspecting sequences
30+ -----------------------
4831
49- Or if you want to manually specify a database name:
32+ Retrieve a list of ``Doctrine\DBAL\Schema\Sequence `` instances
33+ that exist in the current database:
5034
5135.. code-block :: php
5236
5337 <?php
54- $sequences = $sm->listSequences('dbname' );
38+ $sequences = $schemaManager->introspectSequences( );
5539
56- Now you can loop over the array inspecting each sequence object:
40+ Now you can loop over the list inspecting each sequence object:
5741
5842.. code-block :: php
5943
@@ -62,18 +46,25 @@ Now you can loop over the array inspecting each sequence object:
6246 echo $sequence->getObjectName()->toString() . PHP_EOL;
6347 }
6448
65- listTableColumns()
66- ------------------
49+ Introspecting table columns
50+ ---------------------------
6751
68- Retrieve an array of ``Doctrine\DBAL\Schema\Column `` instances that
52+ Retrieve a list of ``Doctrine\DBAL\Schema\Column `` instances that
6953exist for the given table:
7054
7155.. code-block :: php
7256
7357 <?php
74- $columns = $sm->listTableColumns ('user');
58+ $columns = $schemaManager->introspectTableColumnsByUnquotedName ('user');
7559
76- Now you can loop over the array inspecting each column object:
60+ Or if the table name should be represented as a quoted identifier:
61+
62+ .. code-block :: php
63+
64+ <?php
65+ $columns = $schemaManager->introspectTableColumnsByQuotedName('user');
66+
67+ Now you can loop over the list inspecting each column object:
7768
7869.. code-block :: php
7970
@@ -82,16 +73,23 @@ Now you can loop over the array inspecting each column object:
8273 echo $column->getObjectName()->toString() . ': ' . $column->getType() . PHP_EOL;
8374 }
8475
85- introspectTable()
86- -----------------
76+ Introspecting a table
77+ ---------------------
8778
8879Retrieve a single ``Doctrine\DBAL\Schema\Table `` instance that
8980encapsulates the definition of the given table:
9081
9182.. code-block :: php
9283
9384 <?php
94- $table = $sm->introspectTable('user');
85+ $table = $schemaManager->introspectTableByUnquotedName('user');
86+
87+ Or if the table name should be represented as a quoted identifier:
88+
89+ .. code-block :: php
90+
91+ <?php
92+ $columns = $schemaManager->introspectTableByQuotedName('user');
9593
9694 Now you can call methods on the table to manipulate the in memory
9795schema for that table. For example we can add a new column:
@@ -101,39 +99,52 @@ schema for that table. For example we can add a new column:
10199 <?php
102100 $table->addColumn('email_address', 'string');
103101
104- listTableForeignKeys()
105- ----------------------
102+ Introspecting foreign key constraints of a table
103+ ------------------------------------------------
106104
107- Retrieve an array of ``Doctrine\DBAL\Schema\ForeignKeyConstraint ``
105+ Retrieve a list of ``Doctrine\DBAL\Schema\ForeignKeyConstraint ``
108106instances that exist for the given table:
109107
110108.. code-block :: php
111109
112110 <?php
113- $foreignKeys = $sm->listTableForeignKeys ('user');
111+ $foreignKeyConstraints = $schemaManager->introspectTableForeignKeyConstraintsByUnquotedName ('user');
114112
115- Now you can loop over the array inspecting each foreign key
116- object:
113+ Or if the table name should be represented as a quoted identifier:
117114
118115.. code-block :: php
119116
120117 <?php
121- foreach ($foreignKeys as $foreignKey) {
122- echo $foreignKey->getObjectName()->toString() . PHP_EOL;
118+ $foreignKeyConstraints = $schemaManager->introspectTableForeignKeyConstraintsByQuotedName('user');
119+
120+ Now you can loop over the list inspecting each foreign key constraint object:
121+
122+ .. code-block :: php
123+
124+ <?php
125+ foreach ($foreignKeyConstraints as $foreignKeyConstraint) {
126+ echo $foreignKeyConstraint->getObjectName()->toString() . PHP_EOL;
123127 }
124128
125- listTableIndexes()
126- ------------------
129+ Introspecting table indexes
130+ ---------------------------
127131
128- Retrieve an array of ``Doctrine\DBAL\Schema\Index `` instances that
132+ Retrieve a list of ``Doctrine\DBAL\Schema\Index `` instances that
129133exist for the given table:
130134
131135.. code-block :: php
132136
133137 <?php
134- $indexes = $sm->listTableIndexes('user');
138+ $indexes = $schemaManager->introspectTableIndexesByUnquotedName('user');
139+
140+ Or if the table name should be represented as a quoted identifier:
141+
142+ .. code-block :: php
143+
144+ <?php
145+ $indexes = $schemaManager->introspectTableIndexesByQuotedName('user');
135146
136- Now you can loop over the array inspecting each index object:
147+ Now you can loop over the list inspecting each index object:
137148
138149.. code-block :: php
139150
@@ -147,20 +158,20 @@ Now you can loop over the array inspecting each index object:
147158 } . PHP_EOL;
148159 }
149160
150- listTables()
151- ------------
161+ Introspecting all tables in the database
162+ ----------------------------------------
152163
153- Retrieve an array of ``Doctrine\DBAL\Schema\Table `` instances that
154- exist in the connections database:
164+ Retrieve a list of ``Doctrine\DBAL\Schema\Table `` instances that
165+ exist in the current database:
155166
156167.. code-block :: php
157168
158169 <?php
159- $tables = $sm->listTables ();
170+ $tables = $schemaManager->introspectTables ();
160171
161172 Each ``Doctrine\DBAl\Schema\Table `` instance is populated with
162173information provided by all the above methods. So it encapsulates
163- an array of ``Doctrine\DBAL\Schema\Column `` instances that can be
174+ a list of ``Doctrine\DBAL\Schema\Column `` instances that can be
164175retrieved with the ``getColumns() `` method:
165176
166177.. code-block :: php
@@ -173,18 +184,18 @@ retrieved with the ``getColumns()`` method:
173184 }
174185 }
175186
176- listViews()
177- -----------
187+ Introspecting all views in the database
188+ ---------------------------------------
178189
179- Retrieve an array of ``Doctrine\DBAL\Schema\View `` instances that
180- exist in the connections database:
190+ Retrieve a list of ``Doctrine\DBAL\Schema\View `` instances that
191+ exist in the current database:
181192
182193.. code-block :: php
183194
184195 <?php
185- $views = $sm->listViews ();
196+ $views = $schemaManager->introspectViews ();
186197
187- Now you can loop over the array inspecting each view object:
198+ Now you can loop over the list inspecting each view object:
188199
189200.. code-block :: php
190201
@@ -193,18 +204,18 @@ Now you can loop over the array inspecting each view object:
193204 echo $view->getObjectName()->toString() . ': ' . $view->getSql() . PHP_EOL;
194205 }
195206
196- introspectSchema()
197- ------------------
207+ Introspecting the database schema
208+ ---------------------------------
198209
199- For a complete representation of the current database you can use
210+ For a complete representation of the schema of current database you can use
200211the ``introspectSchema() `` method which returns an instance of
201212``Doctrine\DBAL\Schema\Schema ``, which you can use in conjunction
202- with the SchemaTool or Schema Comparator .
213+ with a schema comparator .
203214
204215.. code-block :: php
205216
206217 <?php
207- $fromSchema = $sm ->introspectSchema();
218+ $fromSchema = $schemaManager ->introspectSchema();
208219
209220 Now we can clone the ``$fromSchema `` to ``$toSchema `` and drop a
210221table:
@@ -222,9 +233,11 @@ the changes on the database:
222233.. code-block :: php
223234
224235 <?php
225- $sql = $sm->createComparator()->compareSchemas($fromSchema, $toSchema)->toSql($conn->getDatabasePlatform());
236+ $statements = $schemaManager->createComparator()
237+ ->compareSchemas($fromSchema, $toSchema)
238+ ->toSql($conn->getDatabasePlatform());
226239
227- The ``$sql `` array should give you a SQL query to drop the user
240+ The ``$statements `` list should give you the SQL statements to drop the user
228241table:
229242
230243.. code-block :: php
@@ -238,8 +251,8 @@ table:
238251 )
239252 */
240253
241- createComparator()
242- ------------------
254+ Creating a schema comparator
255+ ----------------------------
243256
244257To create a comparator that can be used to compare two schemas use the
245258``createComparator() `` method which returns an instance of
@@ -248,7 +261,7 @@ To create a comparator that can be used to compare two schemas use the
248261.. code-block :: php
249262
250263 <?php
251- $comparator = $sm ->createComparator();
264+ $comparator = $schemaManager ->createComparator();
252265 $schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
253266
254267 To change the configuration of the comparator, you can pass a
@@ -258,7 +271,7 @@ To change the configuration of the comparator, you can pass a
258271
259272 <?php
260273 $config = (new ComparatorConfig())->withDetectRenamedColumns(false);
261- $comparator = $sm ->createComparator($config);
274+ $comparator = $schemaManager ->createComparator($config);
262275 $schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
263276
264277 Overriding the schema manager
0 commit comments