db icon indicating copy to clipboard operation
db copied to clipboard

Unique indexes can be loaded in 3 different ways

Open Tigrov opened this issue 10 months ago • 1 comments

Unique indexes can be loaded in 3 different ways:

  • Schema::loadTableConstraints(): Constraint[] <- AbstractSchema::getTableUniques()
  • Schema::loadTableIndexes(): IndexConstraint[] <- AbstractSchema::getTableIndexes() with check $index->isUnique()
  • Schema::findUniqueIndexes(): array <- SchemaInterface::findUniqueIndexes()

PgSQL https://github.com/yiisoft/db-pgsql/blob/535975396d865da6cb15ed7bee5648c27a9b7360/src/Schema.php#L894 https://github.com/yiisoft/db-pgsql/tree/535975396d865da6cb15ed7bee5648c27a9b7360/src/Schema.php#L357 https://github.com/yiisoft/db-pgsql/tree/535975396d865da6cb15ed7bee5648c27a9b7360/src/Schema.php#L630

MySQL https://github.com/yiisoft/db-mysql/blob/4dd4e13502a0f047627c398854fc733a41054370/src/Schema.php#L618 https://github.com/yiisoft/db-mysql/blob/4dd4e13502a0f047627c398854fc733a41054370/src/Schema.php#L770 https://github.com/yiisoft/db-mysql/blob/4dd4e13502a0f047627c398854fc733a41054370/src/Schema.php#L158

Suggestion

  • Load all unique indexes include primary key in getTableUniques()
  • Mark as @deprecated SchemaInterface::findUniqueIndexes(): array use getTableUniques() instead
  • Load all indexes loadTableIndexes() and unique indexes in one way
    • get uniques from getTableIndexes() with check $index->isUnique()
    • or load all indexes together with uniques as in SQLite Schema::loadTableConstraints() in one or more queries

Tigrov avatar Aug 15 '23 07:08 Tigrov