From 912773b88a3b3a1fcdf7cca2000a483c4e542e02 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 8 Nov 2022 13:53:28 +0100 Subject: [PATCH] Follow up on table management tips Signed-off-by: Louis Chemineau --- developer_manual/basics/storage/database.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/developer_manual/basics/storage/database.rst b/developer_manual/basics/storage/database.rst index 5026eead1..13c281a7b 100644 --- a/developer_manual/basics/storage/database.rst +++ b/developer_manual/basics/storage/database.rst @@ -332,18 +332,20 @@ Slugs are used to identify resources in the URL by a string rather than integer $author->slugify('name'); // Some-thing Table management tips -------------------------- +--------------------- It makes sense to apply some general tips from the beginning, so you don't have to migrate your data and schema later on. -1. Don't use table name longer than 23 characters. As Oracle is limited to 30 chars and we need 3 more for `oc_` at the beginning and 5 for the primary key suffix `_pkey`. +1. Don't use table name longer than 23 characters. As Oracle is limited to 30 chars and we need 3 more for ``oc_`` at the beginning and 5 for the primary key suffix ``_pkey``. + +2. Add an auto-incremented ``id`` column. This will ease the use of ``QBMapper`` + ``Entity`` approach: -2. Add an auto-incremented `id` column. This will ease the use of `QBMapper` + `Entity` approach: - https://github.com/nextcloud/server/blob/master/lib/public/AppFramework/Db/QBMapper.php - https://github.com/nextcloud/server/blob/master/lib/public/AppFramework/Db/Entity.php .. code-block:: php + addColumn('id', Types::BIGINT, [ 'autoincrement' => true, 'notnull' => true, @@ -355,12 +357,14 @@ It makes sense to apply some general tips from the beginning, so you don't have .. code-block:: php + setPrimaryKey(['id']); -4. Manually set the name of your indexes. It will help you to manipulate them if needed in the future. Note that the names of the index are "global" database wide in some DBs. So having generic names can create conflicts. +4. Manually set the name of your indexes. It will help you to manipulate them if needed in the future. Note that the names of the index are "global" database wide in some database platforms. So having generic names can create conflicts. .. code-block:: php + addUniqueIndex(['your', 'column', 'names', '...'], 'table_name_uniq_feature'); Supporting more databases