1+ ####################
12Database 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
8485There are several things you may wish to do when creating tables. Add
8586fields, 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
148149There is a special exception for creating id fields. A field with type
@@ -156,6 +157,9 @@ Primary Key.
156157Adding Keys
157158===========
158159
160+ $forge->addKey()
161+ ----------------
162+
159163Generally speaking, you'll want your table to have Keys. This is
160164accomplished with ``$forge->addKey('field') ``. The optional second
161165parameter 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+
172182To make code reading more objective it is also possible to add primary
173183and 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
185191Adding 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+
219229Dropping 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****************
264242Modifying 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***************
315337Class 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: \C odeIgniter\D atabase\F orge instance (method chaining)
335357 :rtype: \C odeIgniter\D atabase\F orge
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: \C odeIgniter\D atabase\F orge instance (method chaining)
348370 :rtype: \C odeIgniter\D atabase\F orge
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