From 08b8e70214ae2d9315762afc1a6135c6864f7f7c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 21 Aug 2026 22:44:38 +1200 Subject: [PATCH] (feat): add Schema\Order for index column directions Index types already use IndexType; column order was still a raw ASC/DESC string. Schema\Order is the matching enum so call sites do not keep magic strings next to typed index types. --- src/Query/Schema.php | 3 ++- src/Query/Schema/Order.php | 9 +++++++++ tests/Query/Schema/OrderTest.php | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/Query/Schema/Order.php create mode 100644 tests/Query/Schema/OrderTest.php diff --git a/src/Query/Schema.php b/src/Query/Schema.php index 6a347b3..effa5dc 100644 --- a/src/Query/Schema.php +++ b/src/Query/Schema.php @@ -7,6 +7,7 @@ use Utopia\Query\Exception\ValidationException; use Utopia\Query\Schema\Column; use Utopia\Query\Schema\IndexType; +use Utopia\Query\Schema\Order; use Utopia\Query\Schema\Table; abstract class Schema @@ -414,7 +415,7 @@ protected function compileIndexColumns(Schema\Index $index): string if (isset($index->orders[$col])) { $order = \strtoupper($index->orders[$col]); - if ($order !== OrderDirection::Asc->value && $order !== OrderDirection::Desc->value) { + if (Order::tryFrom($order) === null) { throw new ValidationException('Invalid index order: ' . $index->orders[$col]); } $part .= ' ' . $order; diff --git a/src/Query/Schema/Order.php b/src/Query/Schema/Order.php new file mode 100644 index 0000000..4deb9fc --- /dev/null +++ b/src/Query/Schema/Order.php @@ -0,0 +1,9 @@ +assertSame('ASC', Order::Asc->value); + $this->assertSame('DESC', Order::Desc->value); + } +}