Skip to content

Commit

Permalink
Decrease size for string columns from 128 to 126 for PostgreSQL optim…
Browse files Browse the repository at this point in the history
…ization (#65)
  • Loading branch information
arogachev authored Jan 22, 2024
1 parent ac56329 commit 4f97cb1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Enh #60: Use migrations (@arogachev)
- Enh #43: Remove duplicate code in `ItemsStorage::add()` (@arogachev)
- Enh #53: Use snake case for item attribute names (ease migration from Yii 2) (@arogachev)c
- Enh #45: Decrease size for string columns from 128 to 126 for PostgreSQL optimization (@arogachev)

## 1.0.0 April 20, 2023

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private function createAssignmentsTable(MigrationBuilder $b): void
$b->createTable(
self::ASSIGNMENTS_TABLE,
[
'item_name' => 'string(128) NOT NULL',
'user_id' => 'string(128) NOT NULL',
'item_name' => 'string(126) NOT NULL',
'user_id' => 'string(126) NOT NULL',
'created_at' => 'integer NOT NULL',
'PRIMARY KEY ([[item_name]], [[user_id]])',
],
Expand Down
6 changes: 3 additions & 3 deletions migrations/items/M240118192500CreateItemsTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function createItemsTable(MigrationBuilder $b): void
$b->createTable(
self::ITEMS_TABLE,
[
'name' => 'string(128) NOT NULL PRIMARY KEY',
'name' => 'string(126) NOT NULL PRIMARY KEY',
'type' => 'string(10) NOT NULL',
'description' => 'string(191)',
'rule_name' => 'string(64)',
Expand All @@ -45,8 +45,8 @@ private function createItemsChildrenTable(MigrationBuilder $b): void
$b->createTable(
self::ITEMS_CHILDREN_TABLE,
[
'parent' => 'string(128) NOT NULL',
'child' => 'string(128) NOT NULL',
'parent' => 'string(126) NOT NULL',
'child' => 'string(126) NOT NULL',
'PRIMARY KEY ([[parent]], [[child]])',
'FOREIGN KEY ([[parent]]) REFERENCES {{%' . self::ITEMS_TABLE . '}} ([[name]])',
'FOREIGN KEY ([[child]]) REFERENCES {{%' . self::ITEMS_TABLE . '}} ([[name]])',
Expand Down
10 changes: 5 additions & 5 deletions tests/Base/SchemaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ protected function checkItemsChildrenTable(): void
$this->assertArrayHasKey('parent', $columns);
$parent = $columns['parent'];
$this->assertSame('string', $parent->getType());
$this->assertSame(128, $parent->getSize());
$this->assertSame(126, $parent->getSize());
$this->assertFalse($parent->isAllowNull());

$this->assertArrayHasKey('child', $columns);
$child = $columns['child'];
$this->assertSame('string', $child->getType());
$this->assertSame(128, $child->getSize());
$this->assertSame(126, $child->getSize());
$this->assertFalse($child->isAllowNull());

$primaryKey = $databaseSchema->getTablePrimaryKey(self::$itemsChildrenTable);
Expand Down Expand Up @@ -165,7 +165,7 @@ private function checkItemsTable(): void
$this->assertArrayHasKey('name', $columns);
$name = $columns['name'];
$this->assertSame('string', $name->getType());
$this->assertSame(128, $name->getSize());
$this->assertSame(126, $name->getSize());
$this->assertFalse($name->isAllowNull());

$this->assertArrayHasKey('type', $columns);
Expand Down Expand Up @@ -229,13 +229,13 @@ private function checkAssignmentsTable(): void
$this->assertArrayHasKey('item_name', $columns);
$itemName = $columns['item_name'];
$this->assertSame('string', $itemName->getType());
$this->assertSame(128, $itemName->getSize());
$this->assertSame(126, $itemName->getSize());
$this->assertFalse($itemName->isAllowNull());

$this->assertArrayHasKey('user_id', $columns);
$userId = $columns['user_id'];
$this->assertSame('string', $userId->getType());
$this->assertSame(128, $userId->getSize());
$this->assertSame(126, $userId->getSize());
$this->assertFalse($userId->isAllowNull());

$this->assertArrayHasKey('created_at', $columns);
Expand Down

0 comments on commit 4f97cb1

Please sign in to comment.