Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve query performance for find*() #1192

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Upgrade Guide

## Version 1.1.0 to 1.1.1

## Added Index to `deleted_at` Column

In the new version, an `index` has been added to the **deleted_at** column in the **users** table. This change improves the performance of queries related to soft deletions.To apply the changes, execute the following command:

```console
php spark migrate
```

This will add the new index to your database and enhance query performance.

## Version 1.0.0-beta.8 to 1.0.0

## Removed Deprecated Items
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter Shield.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Shield\Database\Migrations;

use CodeIgniter\Database\Forge;
use CodeIgniter\Database\Migration;
use CodeIgniter\Shield\Config\Auth;

class AddIndexToDeletedAtInUsers extends Migration
{
/**
* Auth Table names
*/
private array $tables;

public function __construct(?Forge $forge = null)
{
/** @var Auth $authConfig */
$authConfig = config('Auth');

if ($authConfig->DBGroup !== null) {
$this->DBGroup = $authConfig->DBGroup;
}

parent::__construct($forge);

$this->tables = $authConfig->tables;
}

/**
* Apply the migration.
*
* This method adds an index to the `deleted_at` column of the `users` table.
* It is called when running the `php spark migrate --all` command.
*/
public function up(): void
{
$this->forge->addKey('deleted_at', false, false, 'deleted_at');
$this->forge->processIndexes($this->tables['users']);
}

/**
* Revert the migration.
*
* This method removes the index from the `deleted_at` column of the `users` table.
* It is called when rolling back the migration using the `php spark migrate:rollback AddIndexToDeletedAtInUsers` command.
*/
public function down(): void
{
// Drop index from the `deleted_at` field
$this->forge->dropKey($this->tables['users'], 'deleted_at');
}
}
Loading