mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #933 from utopia-php/sort-order-by-created-at
Sort createdAt updatedAt unique tie break
This commit is contained in:
3 files changed
+160
-85
No files matched your search
Generated
+88
-84
@@ -1389,16 +1389,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-client",
|
||||
"version": "v7.4.14",
|
||||
"version": "v7.4.16",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-client.git",
|
||||
"reference": "f6bc6b5a54ff5afac4725cacec9bf2f52eb15920"
|
||||
"reference": "c513ed0ba5d1784a6b55fc84190dbe4451b12f41"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-client/zipball/f6bc6b5a54ff5afac4725cacec9bf2f52eb15920",
|
||||
"reference": "f6bc6b5a54ff5afac4725cacec9bf2f52eb15920",
|
||||
"url": "https://api.github.com/repos/symfony/http-client/zipball/c513ed0ba5d1784a6b55fc84190dbe4451b12f41",
|
||||
"reference": "c513ed0ba5d1784a6b55fc84190dbe4451b12f41",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1466,7 +1466,7 @@
|
||||
"http"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/http-client/tree/v7.4.14"
|
||||
"source": "https://github.com/symfony/http-client/tree/v7.4.16"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1486,7 +1486,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-06-16T11:50:14+00:00"
|
||||
"time": "2026-07-29T16:20:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-client-contracts",
|
||||
@@ -1737,16 +1737,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php83",
|
||||
"version": "v1.38.2",
|
||||
"version": "v1.41.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php83.git",
|
||||
"reference": "796a26abb75ce49f3a84433cd81bf1009d73d5f8"
|
||||
"reference": "5ea99087fb99c273a9b9236ed4c31e78b16103c6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/796a26abb75ce49f3a84433cd81bf1009d73d5f8",
|
||||
"reference": "796a26abb75ce49f3a84433cd81bf1009d73d5f8",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/5ea99087fb99c273a9b9236ed4c31e78b16103c6",
|
||||
"reference": "5ea99087fb99c273a9b9236ed4c31e78b16103c6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1793,7 +1793,7 @@
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php83/tree/v1.38.2"
|
||||
"source": "https://github.com/symfony/polyfill-php83/tree/v1.41.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1813,20 +1813,20 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-05-27T06:51:48+00:00"
|
||||
"time": "2026-07-01T12:47:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php85",
|
||||
"version": "v1.38.1",
|
||||
"version": "v1.41.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php85.git",
|
||||
"reference": "ba2ba04f3352cfa2dcbbcb90aee13ed967f505b1"
|
||||
"reference": "255fab485aaa1006ed411040c42aecd7b5302d7a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php85/zipball/ba2ba04f3352cfa2dcbbcb90aee13ed967f505b1",
|
||||
"reference": "ba2ba04f3352cfa2dcbbcb90aee13ed967f505b1",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php85/zipball/255fab485aaa1006ed411040c42aecd7b5302d7a",
|
||||
"reference": "255fab485aaa1006ed411040c42aecd7b5302d7a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1873,7 +1873,7 @@
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php85/tree/v1.38.1"
|
||||
"source": "https://github.com/symfony/polyfill-php85/tree/v1.41.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1893,7 +1893,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-05-26T02:25:22+00:00"
|
||||
"time": "2026-07-01T12:47:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/service-contracts",
|
||||
@@ -2036,33 +2036,32 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cache",
|
||||
"version": "4.0.0",
|
||||
"version": "4.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/cache.git",
|
||||
"reference": "2ab50440114a7699b8a017ee2ecd8bcd9d54ac5e"
|
||||
"reference": "6f8cb03a5cb76e95b95a05103cd14cf782b8060f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/cache/zipball/2ab50440114a7699b8a017ee2ecd8bcd9d54ac5e",
|
||||
"reference": "2ab50440114a7699b8a017ee2ecd8bcd9d54ac5e",
|
||||
"url": "https://api.github.com/repos/utopia-php/cache/zipball/6f8cb03a5cb76e95b95a05103cd14cf782b8060f",
|
||||
"reference": "6f8cb03a5cb76e95b95a05103cd14cf782b8060f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"ext-memcached": "*",
|
||||
"ext-redis": "*",
|
||||
"php": ">=8.3",
|
||||
"utopia-php/circuit-breaker": "0.3.*",
|
||||
"utopia-php/pools": "2.*",
|
||||
"utopia-php/telemetry": "*"
|
||||
"php": ">=8.4",
|
||||
"utopia-php/circuit-breaker": "^0.3",
|
||||
"utopia-php/pools": "^2.0",
|
||||
"utopia-php/telemetry": "^0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "1.2.*",
|
||||
"phpstan/phpstan": "^1.12",
|
||||
"phpunit/phpunit": "^9.3",
|
||||
"swoole/ide-helper": "^6.0",
|
||||
"vimeo/psalm": "4.13.1"
|
||||
"swoole/ide-helper": "^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-memcached": "Required for the Memcached and Hazelcast adapters.",
|
||||
"ext-redis": "Required for the Redis, RedisCluster and Sharding adapters.",
|
||||
"ext-swoole": "Required for the multiplexing Redis adapter (>=6.0)."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@@ -2074,6 +2073,12 @@
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Team Appwrite",
|
||||
"email": "team@appwrite.io"
|
||||
}
|
||||
],
|
||||
"description": "A simple cache library to manage application cache storing, loading and purging",
|
||||
"keywords": [
|
||||
"cache",
|
||||
@@ -2084,32 +2089,29 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/cache/issues",
|
||||
"source": "https://github.com/utopia-php/cache/tree/4.0.0"
|
||||
"source": "https://github.com/utopia-php/cache/tree/4.0.1"
|
||||
},
|
||||
"time": "2026-07-31T13:04:45+00:00"
|
||||
"time": "2026-08-04T00:06:02+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/circuit-breaker",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/circuit-breaker.git",
|
||||
"reference": "db5d77f6c99ebce2ee81bd8ed4ae8f41bd2b0828"
|
||||
"reference": "5fbc3802471b0d1b4260bd9f5544514e6929b481"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/circuit-breaker/zipball/db5d77f6c99ebce2ee81bd8ed4ae8f41bd2b0828",
|
||||
"reference": "db5d77f6c99ebce2ee81bd8ed4ae8f41bd2b0828",
|
||||
"url": "https://api.github.com/repos/utopia-php/circuit-breaker/zipball/5fbc3802471b0d1b4260bd9f5544514e6929b481",
|
||||
"reference": "5fbc3802471b0d1b4260bd9f5544514e6929b481",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "^1.29",
|
||||
"phpstan/phpstan": "^2.1",
|
||||
"phpunit/phpunit": "^10.0",
|
||||
"utopia-php/telemetry": "^0.4"
|
||||
"utopia-php/telemetry": "^0.4.6"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-opentelemetry": "Required by utopia-php/telemetry when using OpenTelemetry metrics.",
|
||||
@@ -2121,7 +2123,7 @@
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Utopia\\CircuitBreaker\\": "src/CircuitBreaker"
|
||||
"Utopia\\CircuitBreaker\\": "src/CircuitBreaker/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
@@ -2146,9 +2148,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/circuit-breaker/issues",
|
||||
"source": "https://github.com/utopia-php/circuit-breaker/tree/0.3.1"
|
||||
"source": "https://github.com/utopia-php/circuit-breaker/tree/0.3.2"
|
||||
},
|
||||
"time": "2026-05-29T12:12:23+00:00"
|
||||
"time": "2026-08-05T18:07:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/console",
|
||||
@@ -2200,16 +2202,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/mongo",
|
||||
"version": "1.3.2",
|
||||
"version": "1.5.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/mongo.git",
|
||||
"reference": "34d9ab406a87d2006b0e108796fdb6b5397853d3"
|
||||
"reference": "3ece830d1d72d2c9f68c656738e285629b5c72a9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/mongo/zipball/34d9ab406a87d2006b0e108796fdb6b5397853d3",
|
||||
"reference": "34d9ab406a87d2006b0e108796fdb6b5397853d3",
|
||||
"url": "https://api.github.com/repos/utopia-php/mongo/zipball/3ece830d1d72d2c9f68c656738e285629b5c72a9",
|
||||
"reference": "3ece830d1d72d2c9f68c656738e285629b5c72a9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2255,27 +2257,27 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/mongo/issues",
|
||||
"source": "https://github.com/utopia-php/mongo/tree/1.3.2"
|
||||
"source": "https://github.com/utopia-php/mongo/tree/1.5.1"
|
||||
},
|
||||
"time": "2026-07-20T09:02:13+00:00"
|
||||
"time": "2026-08-02T00:46:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/pools",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/pools.git",
|
||||
"reference": "48905dac1b8f8050c2e07bdda32a018ca33982fc"
|
||||
"reference": "86d43fcacd125232c0743e8c22695faf97285cf3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/pools/zipball/48905dac1b8f8050c2e07bdda32a018ca33982fc",
|
||||
"reference": "48905dac1b8f8050c2e07bdda32a018ca33982fc",
|
||||
"url": "https://api.github.com/repos/utopia-php/pools/zipball/86d43fcacd125232c0743e8c22695faf97285cf3",
|
||||
"reference": "86d43fcacd125232c0743e8c22695faf97285cf3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.4",
|
||||
"utopia-php/telemetry": "^0.4"
|
||||
"utopia-php/telemetry": "^0.4.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"swoole/ide-helper": "6.*"
|
||||
@@ -2311,22 +2313,22 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/pools/issues",
|
||||
"source": "https://github.com/utopia-php/pools/tree/2.0.1"
|
||||
"source": "https://github.com/utopia-php/pools/tree/2.0.2"
|
||||
},
|
||||
"time": "2026-07-31T12:19:18+00:00"
|
||||
"time": "2026-08-05T18:07:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/telemetry",
|
||||
"version": "0.4.5",
|
||||
"version": "0.4.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/telemetry.git",
|
||||
"reference": "139943bffcd4f6dd8fb9ed247f946a1d151b006a"
|
||||
"reference": "f96778a01792c32df0876fe1f38a79b9588445d8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/telemetry/zipball/139943bffcd4f6dd8fb9ed247f946a1d151b006a",
|
||||
"reference": "139943bffcd4f6dd8fb9ed247f946a1d151b006a",
|
||||
"url": "https://api.github.com/repos/utopia-php/telemetry/zipball/f96778a01792c32df0876fe1f38a79b9588445d8",
|
||||
"reference": "f96778a01792c32df0876fe1f38a79b9588445d8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2362,22 +2364,22 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/telemetry/issues",
|
||||
"source": "https://github.com/utopia-php/telemetry/tree/0.4.5"
|
||||
"source": "https://github.com/utopia-php/telemetry/tree/0.4.6"
|
||||
},
|
||||
"time": "2026-07-08T11:07:25+00:00"
|
||||
"time": "2026-08-05T17:56:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/validators",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/validators.git",
|
||||
"reference": "444a3dbfcd5f2d167214f07f6e8a9962048def1c"
|
||||
"reference": "61832b7c863831466ccdeccd4e4f76a43765fbbf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/validators/zipball/444a3dbfcd5f2d167214f07f6e8a9962048def1c",
|
||||
"reference": "444a3dbfcd5f2d167214f07f6e8a9962048def1c",
|
||||
"url": "https://api.github.com/repos/utopia-php/validators/zipball/61832b7c863831466ccdeccd4e4f76a43765fbbf",
|
||||
"reference": "61832b7c863831466ccdeccd4e4f76a43765fbbf",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2402,9 +2404,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/validators/issues",
|
||||
"source": "https://github.com/utopia-php/validators/tree/0.4.0"
|
||||
"source": "https://github.com/utopia-php/validators/tree/0.4.1"
|
||||
},
|
||||
"time": "2026-08-07T10:53:49+00:00"
|
||||
"time": "2026-08-10T04:15:37+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
@@ -2542,16 +2544,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.29.3",
|
||||
"version": "v1.30.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "da1d1111a6aa2e082d2a388b194afe1ba0a05d14"
|
||||
"reference": "a96cb6eee2961905d2fce7207aefb80945bf6b28"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/da1d1111a6aa2e082d2a388b194afe1ba0a05d14",
|
||||
"reference": "da1d1111a6aa2e082d2a388b194afe1ba0a05d14",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/a96cb6eee2961905d2fce7207aefb80945bf6b28",
|
||||
"reference": "a96cb6eee2961905d2fce7207aefb80945bf6b28",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2562,14 +2564,16 @@
|
||||
"php": "^8.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.95.8",
|
||||
"illuminate/view": "^12.62.0",
|
||||
"composer/semver": "^3.4.4",
|
||||
"friendsofphp/php-cs-fixer": "^3.95.18",
|
||||
"illuminate/view": "^12.65.0",
|
||||
"larastan/larastan": "^3.10.0",
|
||||
"laravel-zero/framework": "^12.1.0",
|
||||
"laravel/agent-detector": "^2.0.2",
|
||||
"laravel/prompts": "^0.3.22",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/termwind": "^2.4.0",
|
||||
"pestphp/pest": "^3.8.6"
|
||||
"pestphp/pest": "^3.8.7"
|
||||
},
|
||||
"bin": [
|
||||
"builds/pint"
|
||||
@@ -2606,7 +2610,7 @@
|
||||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2026-06-16T15:34:04+00:00"
|
||||
"time": "2026-08-05T16:47:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "myclabs/deep-copy",
|
||||
@@ -2873,11 +2877,11 @@
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpstan",
|
||||
"version": "1.12.33",
|
||||
"version": "1.12.34",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1",
|
||||
"reference": "37982d6fc7cbb746dda7773530cda557cdf119e1",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/4dd89ca7aa30fdc6760be21550d583bcc32e8476",
|
||||
"reference": "4dd89ca7aa30fdc6760be21550d583bcc32e8476",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2922,7 +2926,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2026-02-28T20:30:03+00:00"
|
||||
"time": "2026-07-28T10:04:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
@@ -4644,5 +4648,5 @@
|
||||
"ext-redis": "*"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.9.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
@@ -8575,7 +8575,16 @@ class Database
|
||||
// costs a full scan of the collection. The tie break exists to hold a page boundary
|
||||
// still, so it is only owed to a cursor.
|
||||
if ($uniqueOrderBy === false && (!$vectorSearch || !empty($cursor))) {
|
||||
$orderAttributes[] = '$sequence';
|
||||
$leadingAttribute = $orderAttributes[0] ?? null;
|
||||
$leadingOrderType = $orderTypes[0] ?? Database::ORDER_ASC;
|
||||
|
||||
if (\in_array($leadingAttribute, ['$createdAt', '$updatedAt'], true)) {
|
||||
$orderAttributes[] = '$sequence';
|
||||
$orderTypes[] = $leadingOrderType;
|
||||
} else {
|
||||
$orderAttributes[] = '$sequence';
|
||||
$orderTypes[] = Database::ORDER_ASC;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cursor)) {
|
||||
|
||||
@@ -3627,6 +3627,68 @@ trait DocumentTests
|
||||
$this->assertEquals($documentsTest[1]['$id'], $documents[0]['$id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* A batch insert stamps every row with the same `$createdAt` — createDocuments() takes
|
||||
* one timestamp for the whole batch — so ordering by that timestamp alone leaves the
|
||||
* order of those rows to the tie break Database::find() appends.
|
||||
*
|
||||
* The tie break follows the direction of the leading timestamp, so a descending order
|
||||
* returns the batch newest-inserted first. It used to be appended ascending regardless,
|
||||
* which both reversed the rows inside a tied group and produced a mixed-direction
|
||||
* ORDER BY that no ascending index can answer.
|
||||
*/
|
||||
public function testFindOrderByCreateDateTieBreak(): void
|
||||
{
|
||||
/** @var Database $database */
|
||||
$database = $this->getDatabase();
|
||||
|
||||
$database->createCollection('tieBreak', permissions: [
|
||||
Permission::create(Role::any()),
|
||||
Permission::read(Role::any()),
|
||||
], documentSecurity: false);
|
||||
|
||||
$this->assertEquals(true, $database->createAttribute('tieBreak', 'name', Database::VAR_STRING, 128, true));
|
||||
|
||||
$documents = [];
|
||||
foreach (['alpha', 'bravo', 'charlie'] as $name) {
|
||||
$documents[] = new Document([
|
||||
'name' => $name,
|
||||
'$permissions' => [Permission::read(Role::any())],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertEquals(3, $database->createDocuments('tieBreak', $documents));
|
||||
|
||||
$created = $database->find('tieBreak', [Query::orderAsc('$sequence')]);
|
||||
$this->assertCount(3, $created);
|
||||
|
||||
// The batch shares one timestamp, otherwise the tie break is never consulted.
|
||||
$this->assertEquals($created[0]->getCreatedAt(), $created[2]->getCreatedAt());
|
||||
|
||||
$descending = $database->find('tieBreak', [Query::orderDesc('$createdAt')]);
|
||||
$this->assertEquals(
|
||||
[$created[2]->getSequence(), $created[1]->getSequence(), $created[0]->getSequence()],
|
||||
\array_map(fn (Document $document) => $document->getSequence(), $descending)
|
||||
);
|
||||
|
||||
$ascending = $database->find('tieBreak', [Query::orderAsc('$createdAt')]);
|
||||
$this->assertEquals(
|
||||
[$created[0]->getSequence(), $created[1]->getSequence(), $created[2]->getSequence()],
|
||||
\array_map(fn (Document $document) => $document->getSequence(), $ascending)
|
||||
);
|
||||
|
||||
// The tie break sits behind the caller's own order, so `name` still decides the
|
||||
// rows the timestamp ties — placing a unique key ahead of it would leave it unread.
|
||||
$byName = $database->find('tieBreak', [
|
||||
Query::orderDesc('$createdAt'),
|
||||
Query::orderAsc('name'),
|
||||
]);
|
||||
$this->assertEquals(
|
||||
['alpha', 'bravo', 'charlie'],
|
||||
\array_map(fn (Document $document) => $document->getAttribute('name'), $byName)
|
||||
);
|
||||
}
|
||||
|
||||
public function testFindCreatedBefore(): void
|
||||
{
|
||||
/** @var Database $database */
|
||||
|
||||
Reference in new issue
Block a user