Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat relationships #246

Merged
merged 196 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
72752b5
Add relationships base
abnegate Feb 21, 2023
db87b17
Remove foreign key use
abnegate Feb 27, 2023
78b1cff
WIP add fetching related documents
abnegate Feb 27, 2023
d69861e
Move tests to base
abnegate Feb 28, 2023
901c5f6
Hacky fix for circular one-to-one reference fetches
abnegate Feb 28, 2023
318a459
Working one to many
abnegate Feb 28, 2023
783ed8b
Fix two way related fetch from child side
abnegate Feb 28, 2023
88d3c19
Update collections
abnegate Mar 1, 2023
5aa3f68
Use switch for document reference relation type
abnegate Mar 1, 2023
b5e9768
Fix junction name
abnegate Mar 1, 2023
2286537
Add `private` attribute to metadata collection to hide junction colle…
abnegate Mar 1, 2023
ba664bc
Move anonymous function to class level
abnegate Mar 1, 2023
cd6f05a
Remove private changes
abnegate Mar 1, 2023
59f16c9
Remove private key
abnegate Mar 1, 2023
8299921
Working many to many
abnegate Mar 1, 2023
378431e
Many to one
abnegate Mar 2, 2023
3fe54a5
Add update relationships
abnegate Mar 2, 2023
d7cc289
WIP add delete relationships
abnegate Mar 2, 2023
22991eb
Add rest of delete tests
abnegate Mar 3, 2023
4da89c9
Add indexes
abnegate Mar 3, 2023
4a19b82
Fix test order
abnegate Mar 6, 2023
1e51392
Unlimited related documents
abnegate Mar 6, 2023
1476212
Populate relationships from find
abnegate Mar 6, 2023
a9852a1
Support relationship property queries
abnegate Mar 6, 2023
7962efa
WIP document relationship updates
abnegate Mar 6, 2023
941e597
Unique key index for one to one relations
abnegate Mar 7, 2023
c70a44b
Add relationship updating
abnegate Mar 7, 2023
bb77b72
WIP delete documents with relationships
abnegate Mar 7, 2023
2ec8b52
Merge remote-tracking branch 'origin/main' into feat-relationships
abnegate Mar 8, 2023
8d52a50
Merge remote-tracking branch 'origin/main' into feat-relationships
abnegate Mar 8, 2023
cea1858
Merge remote-tracking branch 'origin/main' into feat-relationships
abnegate Mar 8, 2023
0080797
Fix updating on update/delete
abnegate Mar 9, 2023
4f97ebb
One to one delete
abnegate Mar 9, 2023
ccb67df
Check fixes
abnegate Mar 9, 2023
932957b
Format
abnegate Mar 9, 2023
73adc93
Set null / cascade on delete
abnegate Mar 9, 2023
bce8e5f
Many to many cascade delete
abnegate Mar 10, 2023
8a7e29c
Rename delete methods
abnegate Mar 10, 2023
fa02062
WIP nested selects
abnegate Mar 10, 2023
974959b
Add nested selects using chained queries
abnegate Mar 11, 2023
bf2d852
Fix one-to-many and many-to-one not removing old relations on update
abnegate Mar 11, 2023
99911e2
Fix many-to-one caching
abnegate Mar 11, 2023
3c01064
Delete relation cache for many to many so nested items are re-fetched
abnegate Mar 11, 2023
d9e6eba
Add checks to test for relationship nesting
abnegate Mar 11, 2023
bbe883c
Fix over-fetched nesting
abnegate Mar 12, 2023
cf7dd89
Fix creating documents with two-way relations from child-side
abnegate Mar 13, 2023
aa20d08
Fix infinite recursion when creating multi-level nested documents
abnegate Mar 13, 2023
2b20d17
Fix upsert related documents
abnegate Mar 13, 2023
865b19a
Add tests for creating two-way relations from child side
abnegate Mar 13, 2023
9811183
Fix nested relationship fetches for some types
abnegate Mar 14, 2023
e4f19a0
Add method stubs
abnegate Mar 15, 2023
343de80
Change PDO to mixed
abnegate Mar 15, 2023
dc842d7
Change method return to mixed
abnegate Mar 15, 2023
4388984
Fix more nested fetches
abnegate Mar 15, 2023
f01e936
Check fixes
abnegate Mar 15, 2023
fe29a04
Add extra test cases for missing coverage
abnegate Mar 15, 2023
e396c00
Add Postgres relationships
abnegate Mar 16, 2023
352a161
Fix Postgres select * queries
abnegate Mar 16, 2023
cdabfe0
Fix default index creation
abnegate Mar 16, 2023
509d139
Add explicit `index` prefix to avoid index/table name collisions in P…
abnegate Mar 16, 2023
3304a5d
Fix postgres tests
abnegate Mar 16, 2023
ec6b399
Recreate databases for each test
abnegate Mar 16, 2023
f158f63
Fix index meta not updated with renamed relationships
abnegate Mar 16, 2023
f6f1190
Add mongo support
abnegate Mar 16, 2023
697a9b0
Format
abnegate Mar 16, 2023
7d22708
Remove on update as document IDs can never be updated
abnegate Mar 16, 2023
8b3ea61
Remove other update usages
abnegate Mar 17, 2023
0ec2635
Add test for inherited permissions
abnegate Mar 17, 2023
9bb8783
Permissions inherit/enforcement tests
abnegate Mar 17, 2023
35c6e2e
Check max depth for document creation
abnegate Mar 20, 2023
2851954
Fix create document with relationships not returning populated relati…
abnegate Mar 20, 2023
a0b0835
Fix one to one updates with new documents
abnegate Mar 20, 2023
17c6b66
Fix one to one updates for all creation types
abnegate Mar 21, 2023
ab6c773
Fix one to many updates for all creation types
abnegate Mar 22, 2023
574de81
Don't filter newly added documents for update
abnegate Mar 22, 2023
62eb6e7
Fix many to one updates for all creation types
abnegate Mar 22, 2023
bd43a63
Fix many to many updates for all creation types
abnegate Mar 22, 2023
bb39da6
Test for updating via all types from child side for two way relations…
abnegate Mar 22, 2023
663a0de
Fix empty state test
abnegate Mar 22, 2023
594d7c5
Inherit parent permissions on update
abnegate Mar 22, 2023
8c64d6b
Skip fetching relationships when removing from old documents on update
abnegate Mar 22, 2023
718fb5d
Skip relationships past max depth on update
abnegate Mar 22, 2023
c233735
Test update through create
abnegate Mar 22, 2023
c1412e0
Update mongo
abnegate Mar 22, 2023
73c48d6
Remove SQLite test db recreate
abnegate Mar 22, 2023
5610fb0
Add relationship support flag to disable for problematic adapters
abnegate Mar 22, 2023
c313463
Fix phpstan
abnegate Mar 22, 2023
3dac815
Allow updating two way
abnegate Mar 22, 2023
f56a2c8
Skip updating columns names if key matches the original
abnegate Mar 22, 2023
277828f
Don't update anything if no new values were passed
abnegate Mar 22, 2023
c97273d
Make sure auth status is reset in case of exception inside callback
abnegate Mar 22, 2023
5505887
Add assertions for update on create test
abnegate Mar 22, 2023
1ce6b21
Fix delete with no related items when on delete set to restrict
abnegate Mar 22, 2023
e30fae5
Test for delete with no related documents when on delete set to restrict
abnegate Mar 22, 2023
4505743
Remove test code
abnegate Mar 22, 2023
9c6e449
Update index var names
abnegate Mar 22, 2023
ba5b3ea
Update default relationship key values
abnegate Mar 22, 2023
350f801
Short circuit loops
abnegate Mar 22, 2023
6943e0f
Clean up select query processing for relationships
abnegate Mar 22, 2023
649bd0c
Apply suggestions from code review
abnegate Mar 22, 2023
c998b0e
Arrow function usages
abnegate Mar 23, 2023
e6bb18b
Update src/Database/Database.php
abnegate Mar 23, 2023
b5c3b13
Review feedback
abnegate Mar 23, 2023
303438b
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
abnegate Mar 23, 2023
40bd069
Use instance vars instead of statics for depths
abnegate Mar 23, 2023
aae2f88
Format
abnegate Mar 23, 2023
3284d92
Merge remote-tracking branch 'origin/main' into feat-relationships
abnegate Mar 23, 2023
825ea1c
Add null checks
abnegate Mar 23, 2023
685feba
Fix many to one one way meta checks
abnegate Mar 23, 2023
c1df0b7
Fix one to many one way key checks
abnegate Mar 23, 2023
a3a71bf
Add missing `silent` for some calls
abnegate Mar 24, 2023
851deda
Fix test cases for metadata
abnegate Mar 24, 2023
269c528
Check fixes
abnegate Mar 24, 2023
fa0f6a7
Add test for many related to one
abnegate Mar 24, 2023
6b4b365
Add extra many-many case
abnegate Mar 24, 2023
29b7126
Allow adding hooks to pre/post process documents with the collection …
abnegate Mar 27, 2023
7d198b0
Remove pre-delete hook
abnegate Mar 27, 2023
88d9746
Remove redundant throws defs
abnegate Mar 27, 2023
94c4385
Merge branch 'feat-hooks' into feat-relationships
abnegate Mar 27, 2023
faf43ac
Revert "Merge branch 'feat-hooks' into feat-relationships"
abnegate Mar 27, 2023
91d81fb
Revert "Revert "Merge branch 'feat-hooks' into feat-relationships""
abnegate Mar 28, 2023
5683ad2
Revert "Revert "Revert "Merge branch 'feat-hooks' into feat-relations…
abnegate Mar 28, 2023
49b827b
Throw exception when deleting child side one-to-one with related parent
abnegate Mar 29, 2023
a0d62c7
Add test for one-to-one one way child side delete
abnegate Mar 29, 2023
a51b3db
Allow deleting child one-to-one relation when one-way
abnegate Mar 29, 2023
ed91c85
Prefix internal collections and indexes with _ so names can never col…
abnegate Mar 30, 2023
15a7158
Reset keys when unsetting from lists
abnegate Mar 31, 2023
7001161
Fix deleting two-way relationship from child side
abnegate Mar 31, 2023
4659f00
Fix deleting relationships on collection delete
abnegate Mar 31, 2023
5df27b1
Fix junction not delete from metadata table
abnegate Mar 31, 2023
629652a
Add tests for deleting two way relationship from child side
abnegate Mar 31, 2023
a5bed05
Add one to many list array with $id together
fogelito Apr 2, 2023
c6d20e0
Add one to many list array with $id together
fogelito Apr 2, 2023
e3162cb
LimitException Duplication
fogelito Apr 2, 2023
b5d98c7
Fix analysis
abnegate Apr 3, 2023
f9e242a
Fix removing attributes with null values
abnegate Apr 3, 2023
22edc68
check cascade delete with no limits
fogelito Apr 3, 2023
2fe2ba4
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 3, 2023
1472c47
Fix analysis
abnegate Apr 4, 2023
b9bfc46
Select operator and filter fixes
fogelito Apr 4, 2023
897a025
remove var_dump
fogelito Apr 4, 2023
98f1fe0
Fix analysis
abnegate Apr 4, 2023
76fc55c
linter commit
fogelito Apr 4, 2023
fb62db6
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 4, 2023
5e4292f
Some more assertArrayNotHasKey tests on find method
fogelito Apr 4, 2023
da5f08e
dormitories
fogelito Apr 4, 2023
d8752a8
Tests to be check
fogelito Apr 4, 2023
5c4ddcb
Update rename parameter
abnegate Apr 5, 2023
0ca9f61
Fix delete attribute not removing attribute from index metadata
abnegate Apr 5, 2023
a1e53fa
Use key length const instead of magic number
abnegate Apr 5, 2023
96a10d8
Return true on empty query for relationship delete
abnegate Apr 5, 2023
04e8f61
Check if attribute key or twoWayKey already exists when trying to rename
abnegate Apr 5, 2023
76e6f33
Remove redundant param from adapter relationship create
abnegate Apr 5, 2023
b7e3568
Format
abnegate Apr 5, 2023
285474a
Fix tests
abnegate Apr 5, 2023
628170c
Fix tests
abnegate Apr 5, 2023
9ac58dc
Fix tests
abnegate Apr 5, 2023
0526571
Merge remote-tracking branch 'origin/main' into feat-relationships
abnegate Apr 5, 2023
c7f9e47
Fix nested select tests
abnegate Apr 5, 2023
f25f144
Copy fix select queries for `getDocument`
abnegate Apr 5, 2023
c7a55cb
Tests Select operator on 3 level nesting
fogelito Apr 5, 2023
9c8af66
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 5, 2023
c540ce2
Tests Select operator on 3 level nesting
fogelito Apr 5, 2023
8b1244b
Fix analysis
abnegate Apr 5, 2023
cfa79e4
Fix update set to null for one-to-many child side
abnegate Apr 5, 2023
8c9cd48
Disable delete relationship on regular attribute
fogelito Apr 5, 2023
280d9da
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 5, 2023
08e6f74
Disable delete relationship on regular attribute
fogelito Apr 5, 2023
a9de5d6
Skip relationships on related fetch to preserve unchanged values
abnegate Apr 5, 2023
6e5e5ce
Format
abnegate Apr 5, 2023
8d75406
Fix many to many update with removal
abnegate Apr 5, 2023
05a3f8c
Select operator on getDocument
fogelito Apr 5, 2023
552883e
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 5, 2023
b450b0b
Fix many to many update with removal
abnegate Apr 5, 2023
c0e90dd
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
abnegate Apr 5, 2023
2f9c43c
Add restricted exception
abnegate Apr 5, 2023
ac604e7
Format
abnegate Apr 5, 2023
e5dd71a
Fix special characters in junction table keys
abnegate Apr 5, 2023
ce2ee8e
Cache test on updating related document
fogelito Apr 5, 2023
c84d5fb
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 5, 2023
6fc3911
Add limit checks for related collection on relationship create
abnegate Apr 5, 2023
4080f8d
Fix special characters in attribute names
abnegate Apr 6, 2023
038499c
Fix special characters in relationship names
abnegate Apr 6, 2023
2c8e678
POC for cache clean up
fogelito Apr 6, 2023
a1f4776
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 6, 2023
e83f2df
remove comments
fogelito Apr 6, 2023
2db552f
Some Test and Optimize
fogelito Apr 9, 2023
6273c4d
Delete restrict OneToOne allow from child side
fogelito Apr 9, 2023
52d31cb
Use internal collection IDs for junction collection ID
abnegate Apr 10, 2023
853f9b7
Fix one to one duplicate checks
abnegate Apr 10, 2023
0e5edd8
skip relations
fogelito Apr 10, 2023
f98ed87
Merge remote-tracking branch 'origin/feat-relationships' into feat-re…
fogelito Apr 10, 2023
1cee8b7
skipRelationships + add kill database object
fogelito Apr 10, 2023
31c1d15
Change SQLiteTest.php DSN to memory
fogelito Apr 10, 2023
6321d09
Check status and throw on attribute/relationship create/update/delete…
abnegate Apr 11, 2023
84a3aea
Use return values to make code more readable
abnegate Apr 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"php": ">=8.0",
"utopia-php/framework": "0.*.*",
"utopia-php/cache": "0.8.*",
"utopia-php/mongo": "0.1.*"
"utopia-php/mongo": "0.2.*"
},
"require-dev": {
"ext-redis": "*",
Expand All @@ -46,7 +46,7 @@
"swoole/ide-helper": "4.8.0",
"utopia-php/cli": "^0.14.0",
"laravel/pint": "1.4.*",
"phpstan/phpstan": "1.9.*",
"phpstan/phpstan": "1.10.*",
"rregeer/phpunit-coverage-check": "^0.3.1"
},
"suggests": {
Expand Down
29 changes: 16 additions & 13 deletions composer.lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of those rare PRs where the lock file has lesser changes than the rest! Love it 😄

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ abstract public function deleteCollection(string $name): bool;
* @param int $size
* @param bool $signed
* @param bool $array
*
* @return bool
*/
abstract public function createAttribute(string $collection, string $id, string $type, int $size, bool $signed = true, bool $array = false): bool;
Expand Down Expand Up @@ -242,6 +241,46 @@ abstract public function deleteAttribute(string $collection, string $id): bool;
*/
abstract public function renameAttribute(string $collection, string $old, string $new): bool;

/**
* @param string $collection
* @param string $relatedCollection
* @param string $type
* @param bool $twoWay
* @param string $id
* @param string $twoWayKey
* @param string $onDelete
* @return bool
*/
abstract public function createRelationship(string $collection, string $relatedCollection, string $type, bool $twoWay = false, string $id = '', string $twoWayKey = '', string $onDelete = Database::RELATION_MUTATE_RESTRICT): bool;
christyjacob4 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Update Relationship
*
* @param string $collection
* @param string $relatedCollection
* @param string $type
* @param bool $twoWay
* @param string $key
* @param string $twoWayKey
* @param string|null $newKey
* @param string|null $newTwoWayKey
* @return bool
*/
abstract public function updateRelationship(string $collection, string $relatedCollection, string $type, bool $twoWay, string $key, string $twoWayKey, ?string $newKey = null, ?string $newTwoWayKey = null): bool;

/**
* Delete Relationship
*
* @param string $collection
* @param string $relatedCollection
* @param string $type
* @param bool $twoWay
* @param string $key
* @param string $twoWayKey
* @return bool
*/
abstract public function deleteRelationship(string $collection, string $relatedCollection, string $type, bool $twoWay, string $key, string $twoWayKey): bool;

/**
* Rename Index
*
Expand Down Expand Up @@ -443,6 +482,13 @@ abstract public function getSupportForQueryContains(): bool;
*/
abstract public function getSupportForTimeouts(): bool;

/**
* Are relationships supported?
*
* @return bool
*/
abstract public function getSupportForRelationships(): bool;

/**
* Get current attribute count from collection document
*
Expand Down
Loading