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

add more indices to db tables #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Added

- Reset input when escape key is pressed
- Add more indices to database tables

## [0.26.6] - 2024-06-10

Expand Down
36 changes: 36 additions & 0 deletions lib/Migration/Version16Date20240618183000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace OCA\Money\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version16Date20240618183000 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$accountsTable = $schema->getTable('money_accounts');
$accountsTable->addIndex(['book_id'], 'money_accounts_book_id_idx');

$transactionsTable = $schema->getTable('money_transactions');
$transactionsTable->addIndex(['date'], 'money_transactions_date_idx');

$splitsTable = $schema->getTable('money_splits');
$splitsTable->addIndex(['transaction_id'], 'money_splits_transaction_id_idx');
$splitsTable->addIndex(['dest_account_id'], 'money_splits_dest_account_id_idx');

return $schema;
}

}
31 changes: 31 additions & 0 deletions tests/Migration/Version16Date20240618183000Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace OCA\Money\tests\Migration;

include_once __DIR__ . '/AbstractMigrationTestCase.php';

class Version16Date20240618183000Test extends AbstractMigrationTestCase {

public function testAddIndices() {
$this->migrationService->migrate('16Date20240618183000');
$this->renewSchema();

$accountsTable = $this->schema->getTable('money_accounts');

$this->assertTrue($accountsTable->hasIndex('money_accounts_book_id_idx'));

$transactionsTable = $this->schema->getTable('money_transactions');

$this->assertTrue($transactionsTable->hasIndex('money_transactions_date_idx'));

$splitsTable = $this->schema->getTable('money_splits');

$this->assertTrue($splitsTable->hasIndex('money_splits_transaction_id_idx'));
$this->assertTrue($splitsTable->hasIndex('money_splits_dest_account_id_idx'));
}

protected function getPreviousMigrationName(): ?string {
return '15Date20240102222000';
}

}