Skip to content

Commit

Permalink
add more indices to db tables
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpaul17 committed Jun 18, 2024
1 parent 1e23d78 commit d70615d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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';
}

}

0 comments on commit d70615d

Please sign in to comment.