Skip to content

Commit 8fadb29

Browse files
authored
Merge pull request #7163 from kenjis/fix-docs-dbmgmt/forge.rst
docs: improve dbmgmt/forge.rst
2 parents 29c3117 + 0bcaf14 commit 8fadb29

2 files changed

Lines changed: 76 additions & 53 deletions

File tree

user_guide_src/source/changelogs/v4.3.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Query Builder
240240
Forge
241241
-----
242242

243-
- Added ``Forge::processIndexes()`` allowing the creation of indexes on an existing table. See :ref:`adding-keys` for the details.
243+
- Added ``Forge::processIndexes()`` allowing the creation of indexes on an existing table. See :ref:`db-forge-adding-keys-to-a-table` for the details.
244244
- Added the ability to manually set index names. These methods include: ``Forge::addKey()``, ``Forge::addPrimaryKey()``, and ``Forge::addUniqueKey()``
245245
- The new method ``Forge::dropPrimaryKey()`` allows dropping the primary key on a table. See :ref:`dropping-a-primary-key`.
246246
- Fixed ``Forge::dropKey()`` to allow dropping unique indexes. This required the ``DROP CONSTRAINT`` SQL command.

user_guide_src/source/dbmgmt/forge.rst

Lines changed: 75 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
####################
12
Database Forge Class
23
####################
34

@@ -77,9 +78,9 @@ for the file where the database will be created using the ``--ext`` option. Vali
7778
produce a success message but no database file is created. This is because SQLite3 will just use
7879
an in-memory database.
7980

80-
****************************
81-
Creating and Dropping Tables
82-
****************************
81+
***************
82+
Creating Tables
83+
***************
8384

8485
There are several things you may wish to do when creating tables. Add
8586
fields, add keys to the table, alter columns. CodeIgniter provides a
@@ -142,7 +143,7 @@ string into the field definitions with ``addField()``:
142143

143144
.. note:: Multiple calls to ``addField()`` are cumulative.
144145

145-
Creating an id field
146+
Creating an id Field
146147
--------------------
147148

148149
There is a special exception for creating id fields. A field with type
@@ -156,6 +157,9 @@ Primary Key.
156157
Adding Keys
157158
===========
158159

160+
$forge->addKey()
161+
----------------
162+
159163
Generally speaking, you'll want your table to have Keys. This is
160164
accomplished with ``$forge->addKey('field')``. The optional second
161165
parameter set to true will make it a primary key and the third
@@ -169,17 +173,19 @@ below is for MySQL.
169173

170174
.. literalinclude:: forge/010.php
171175

176+
$forge->addPrimaryKey()
177+
-----------------------
178+
179+
$forge->addUniqueKey()
180+
----------------------
181+
172182
To make code reading more objective it is also possible to add primary
173183
and unique keys with specific methods:
174184

175185
.. literalinclude:: forge/011.php
176186

177187
.. note:: When you add a primary key, MySQL and SQLite will assume the name ``PRIMARY`` even if a name is provided.
178188

179-
You may add keys to an existing table by using ``processIndexes()``:
180-
181-
.. literalinclude:: forge/029.php
182-
183189
.. _adding-foreign-keys:
184190

185191
Adding Foreign Keys
@@ -216,6 +222,10 @@ You could also pass optional table attributes, such as MySQL's ``ENGINE``:
216222
``createTable()`` will always add them with your configured *charset*
217223
and *DBCollat* values, as long as they are not empty (MySQL only).
218224

225+
***************
226+
Dropping Tables
227+
***************
228+
219229
Dropping a Table
220230
================
221231

@@ -228,44 +238,12 @@ drivers to handle removal of tables with foreign keys.
228238

229239
.. literalinclude:: forge/018.php
230240

231-
Dropping a Foreign Key
232-
======================
233-
234-
Execute a DROP FOREIGN KEY.
235-
236-
.. literalinclude:: forge/019.php
237-
238-
Dropping a Key
239-
======================
240-
241-
Execute a DROP KEY.
242-
243-
.. literalinclude:: forge/020.php
244-
245-
.. _dropping-a-primary-key:
246-
247-
Dropping a Primary Key
248-
======================
249-
250-
.. versionadded:: 4.3.0
251-
252-
Execute a DROP PRIMARY KEY.
253-
254-
.. literalinclude:: forge/028.php
255-
256-
Renaming a Table
257-
================
258-
259-
Executes a TABLE rename
260-
261-
.. literalinclude:: forge/021.php
262-
263241
****************
264242
Modifying Tables
265243
****************
266244

267-
Adding a Column to a Table
268-
==========================
245+
Adding a Field to a Table
246+
=========================
269247

270248
$forge->addColumn()
271249
-------------------
@@ -283,8 +261,8 @@ Examples:
283261

284262
.. literalinclude:: forge/023.php
285263

286-
Dropping Columns From a Table
287-
==============================
264+
Dropping Fields From a Table
265+
============================
288266

289267
.. _db-forge-dropColumn:
290268

@@ -299,8 +277,8 @@ Used to remove multiple columns from a table.
299277

300278
.. literalinclude:: forge/025.php
301279

302-
Modifying a Column in a Table
303-
=============================
280+
Modifying a Field in a Table
281+
============================
304282

305283
$forge->modifyColumn()
306284
----------------------
@@ -311,6 +289,50 @@ change the name, you can add a "name" key into the field defining array.
311289

312290
.. literalinclude:: forge/026.php
313291

292+
.. _db-forge-adding-keys-to-a-table:
293+
294+
Adding Keys to a Table
295+
======================
296+
297+
.. versionadded:: 4.3.0
298+
299+
You may add keys to an existing table by using ``addKey()``, ``addPrimaryKey()``,
300+
``addUniqueKey()`` or ``addForeignKey()`` and ``processIndexes()``:
301+
302+
.. literalinclude:: forge/029.php
303+
304+
.. _dropping-a-primary-key:
305+
306+
Dropping a Primary Key
307+
======================
308+
309+
.. versionadded:: 4.3.0
310+
311+
Execute a DROP PRIMARY KEY.
312+
313+
.. literalinclude:: forge/028.php
314+
315+
Dropping a Key
316+
===============
317+
318+
Execute a DROP KEY.
319+
320+
.. literalinclude:: forge/020.php
321+
322+
Dropping a Foreign Key
323+
======================
324+
325+
Execute a DROP FOREIGN KEY.
326+
327+
.. literalinclude:: forge/019.php
328+
329+
Renaming a Table
330+
================
331+
332+
Executes a TABLE rename
333+
334+
.. literalinclude:: forge/021.php
335+
314336
***************
315337
Class Reference
316338
***************
@@ -326,15 +348,15 @@ Class Reference
326348
:returns: true on success, false on failure
327349
:rtype: bool
328350

329-
Adds a column to a table. Usage: See `Adding a Column to a Table`_.
351+
Adds a column to a table. Usage: See `Adding a Field to a Table`_.
330352

331353
.. php:method:: addField($field)
332354
333355
:param array $field: Field definition to add
334356
:returns: \CodeIgniter\Database\Forge instance (method chaining)
335357
:rtype: \CodeIgniter\Database\Forge
336358

337-
Adds a field to the set that will be used to create a table. Usage: See `Adding Fields`_.
359+
Adds a field to the set that will be used to create a table. Usage: See `Adding Fields`_.
338360

339361
.. php:method:: addForeignKey($fieldName, $tableName, $tableField[, $onUpdate = '', $onDelete = '', $fkName = ''])
340362
@@ -347,8 +369,6 @@ Class Reference
347369
:returns: \CodeIgniter\Database\Forge instance (method chaining)
348370
:rtype: \CodeIgniter\Database\Forge
349371

350-
.. note:: ``$fkName`` can be used since v4.3.0.
351-
352372
Adds a foreign key to the set that will be used to create a table. Usage: See `Adding Foreign Keys`_.
353373

354374
.. note:: ``$fkName`` can be used since v4.3.0.
@@ -414,7 +434,7 @@ Class Reference
414434
:returns: true on success, false on failure
415435
:rtype: bool
416436

417-
Drops single or multiple columns from a table. Usage: See `Dropping Columns From a Table`_.
437+
Drops single or multiple columns from a table. Usage: See `Dropping Fields From a Table`_.
418438

419439
.. php:method:: dropDatabase($dbName)
420440
@@ -458,12 +478,15 @@ Class Reference
458478

459479
.. php:method:: processIndexes($table)
460480
481+
.. versionadded:: 4.3.0
482+
461483
:param string $table: Name of the table to add indexes to
462484
:returns: true on success, false on failure
463485
:rtype: bool
464486

465487
Used following ``addKey()``, ``addPrimaryKey()``, ``addUniqueKey()``,
466488
and ``addForeignKey()`` to add indexes to an existing table.
489+
See `Adding Keys to a Table`_.
467490

468491
.. php:method:: modifyColumn($table, $field)
469492
@@ -472,7 +495,7 @@ Class Reference
472495
:returns: true on success, false on failure
473496
:rtype: bool
474497

475-
Modifies a table column. Usage: See `Modifying a Column in a Table`_.
498+
Modifies a table column. Usage: See `Modifying a Field in a Table`_.
476499

477500
.. php:method:: renameTable($table_name, $new_table_name)
478501

0 commit comments

Comments
 (0)