Skip to content

Commit e665625

Browse files
committedAug 25, 2024·
add root primary identifiers to meta
1 parent 7cdd542 commit e665625

8 files changed

+406
-191
lines changed
 

‎pgsync/sync.py

+12
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,18 @@ def sync(
983983

984984
row[META] = Transform.get_primary_keys(keys)
985985

986+
if node.is_root:
987+
primary_key_values: t.List[str] = list(
988+
map(str, primary_keys)
989+
)
990+
primary_key_names: t.List[str] = [
991+
primary_key.name for primary_key in node.primary_keys
992+
]
993+
# TODO: add support for composite pkeys
994+
row[META][node.table] = {
995+
primary_key_names[0]: [primary_key_values[0]],
996+
}
997+
986998
if self.verbose:
987999
print(f"{(i+1)})")
9881000
print(f"pkeys: {primary_keys}")

‎requirements/base.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#
77
async-timeout==4.0.3
88
# via redis
9-
boto3==1.34.159
9+
boto3==1.35.5
1010
# via -r requirements/base.in
11-
botocore==1.34.159
11+
botocore==1.35.5
1212
# via
1313
# boto3
1414
# s3transfer
@@ -27,25 +27,25 @@ elasticsearch==8.15.0
2727
# via
2828
# -r requirements/base.in
2929
# elasticsearch-dsl
30-
elasticsearch-dsl==8.15.0
30+
elasticsearch-dsl==8.15.1
3131
# via -r requirements/base.in
3232
environs==11.0.0
3333
# via -r requirements/base.in
3434
events==0.5
3535
# via opensearch-py
3636
greenlet==3.0.3
3737
# via sqlalchemy
38-
idna==3.7
38+
idna==3.8
3939
# via requests
4040
jmespath==1.0.1
4141
# via
4242
# boto3
4343
# botocore
44-
marshmallow==3.21.3
44+
marshmallow==3.22.0
4545
# via environs
4646
opensearch-dsl==2.1.0
4747
# via -r requirements/base.in
48-
opensearch-py==2.6.0
48+
opensearch-py==2.7.1
4949
# via opensearch-dsl
5050
packaging==24.1
5151
# via marshmallow
@@ -74,7 +74,6 @@ s3transfer==0.10.2
7474
six==1.16.0
7575
# via
7676
# opensearch-dsl
77-
# opensearch-py
7877
# python-dateutil
7978
sqlalchemy==2.0.32
8079
# via -r requirements/base.in

‎requirements/dev.txt

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ async-timeout==4.0.3
88
# via redis
99
black==24.8.0
1010
# via -r requirements/dev.in
11-
boto3==1.34.159
11+
boto3==1.35.5
1212
# via -r requirements/base.in
13-
botocore==1.34.159
13+
botocore==1.35.5
1414
# via
1515
# boto3
1616
# s3transfer
@@ -39,15 +39,15 @@ elasticsearch==8.15.0
3939
# via
4040
# -r requirements/base.in
4141
# elasticsearch-dsl
42-
elasticsearch-dsl==8.15.0
42+
elasticsearch-dsl==8.15.1
4343
# via -r requirements/base.in
4444
environs==11.0.0
4545
# via -r requirements/base.in
4646
events==0.5
4747
# via opensearch-py
4848
exceptiongroup==1.2.2
4949
# via pytest
50-
faker==27.0.0
50+
faker==28.0.0
5151
# via -r requirements/dev.in
5252
filelock==3.15.4
5353
# via virtualenv
@@ -59,7 +59,7 @@ greenlet==3.0.3
5959
# via sqlalchemy
6060
identify==2.6.0
6161
# via pre-commit
62-
idna==3.7
62+
idna==3.8
6363
# via requests
6464
iniconfig==2.0.0
6565
# via pytest
@@ -69,7 +69,7 @@ jmespath==1.0.1
6969
# via
7070
# boto3
7171
# botocore
72-
marshmallow==3.21.3
72+
marshmallow==3.22.0
7373
# via environs
7474
mccabe==0.7.0
7575
# via flake8
@@ -81,7 +81,7 @@ nodeenv==1.9.1
8181
# via pre-commit
8282
opensearch-dsl==2.1.0
8383
# via -r requirements/base.in
84-
opensearch-py==2.6.0
84+
opensearch-py==2.7.1
8585
# via opensearch-dsl
8686
packaging==24.1
8787
# via
@@ -140,7 +140,6 @@ s3transfer==0.10.2
140140
six==1.16.0
141141
# via
142142
# opensearch-dsl
143-
# opensearch-py
144143
# python-dateutil
145144
sqlalchemy==2.0.32
146145
# via -r requirements/base.in

‎tests/test_sync_nested_children.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def test_sync(self, sync, nodes, data):
391391
"_index": "testdb",
392392
"_source": {
393393
"_meta": {
394+
"book": {"isbn": ["abc"]},
394395
"author": {"id": [1, 4]},
395396
"book_author": {"id": [1, 4]},
396397
"book_language": {"id": [1, 4, 7, 9]},
@@ -449,6 +450,7 @@ def test_sync(self, sync, nodes, data):
449450
"_index": "testdb",
450451
"_source": {
451452
"_meta": {
453+
"book": {"isbn": ["def"]},
452454
"author": {"id": [1, 2]},
453455
"book_author": {"id": [2, 5]},
454456
"book_language": {"id": [2, 5, 8]},
@@ -506,6 +508,7 @@ def test_sync(self, sync, nodes, data):
506508
"_index": "testdb",
507509
"_source": {
508510
"_meta": {
511+
"book": {"isbn": ["ghi"]},
509512
"author": {"id": [2, 3]},
510513
"book_author": {"id": [3, 6]},
511514
"book_language": {"id": [3, 6]},
@@ -708,6 +711,7 @@ def test_insert_root(
708711
"_index": "testdb",
709712
"_source": {
710713
"_meta": {
714+
"book": {"isbn": ["jkl"]},
711715
"author": {"id": [5]},
712716
"book_author": {"id": [7]},
713717
"book_language": {"id": [10, 11]},
@@ -753,6 +757,7 @@ def test_insert_root(
753757
"_index": "testdb",
754758
"_source": {
755759
"_meta": {
760+
"book": {"isbn": ["mno"]},
756761
"author": {"id": [5]},
757762
"book_author": {"id": [8]},
758763
"book_language": {"id": [12, 13]},
@@ -834,6 +839,7 @@ def test_update_root(self, data, nodes, book_cls):
834839
"_index": "testdb",
835840
"_source": {
836841
"_meta": {
842+
"book": {"isbn": ["abc"]},
837843
"author": {"id": [1, 4]},
838844
"book_author": {"id": [1, 4]},
839845
"book_language": {"id": [1, 4, 7, 9]},
@@ -1001,6 +1007,7 @@ def poll_db():
10011007
expected = [
10021008
{
10031009
"_meta": {
1010+
"book": {"isbn": ["def"]},
10041011
"author": {"id": [1, 2]},
10051012
"book_author": {"id": [2, 5]},
10061013
"book_language": {"id": [2, 5, 8]},
@@ -1054,6 +1061,7 @@ def poll_db():
10541061
},
10551062
{
10561063
"_meta": {
1064+
"book": {"isbn": ["ghi"]},
10571065
"author": {"id": [2, 3]},
10581066
"book_author": {"id": [3, 6]},
10591067
"book_language": {"id": [3, 6]},
@@ -1174,7 +1182,7 @@ def test_insert_through_child_op2(
11741182
"isbn": "abc",
11751183
"group": None,
11761184
"title": "The Tiger Club",
1177-
"_meta": {},
1185+
"_meta": {"book": {"isbn": ["abc"]}},
11781186
},
11791187
},
11801188
{
@@ -1184,7 +1192,7 @@ def test_insert_through_child_op2(
11841192
"isbn": "def",
11851193
"group": None,
11861194
"title": "The Lion Club",
1187-
"_meta": {},
1195+
"_meta": {"book": {"isbn": ["def"]}},
11881196
},
11891197
},
11901198
{
@@ -1194,7 +1202,7 @@ def test_insert_through_child_op2(
11941202
"isbn": "ghi",
11951203
"group": None,
11961204
"title": "The Rabbit Club",
1197-
"_meta": {},
1205+
"_meta": {"book": {"isbn": ["ghi"]}},
11981206
},
11991207
},
12001208
]
@@ -1249,6 +1257,7 @@ def poll_db():
12491257
],
12501258
"title": "The Tiger Club",
12511259
"_meta": {
1260+
"book": {"isbn": ["abc"]},
12521261
"group": {"id": [1, 2]},
12531262
"book_group": {"id": [1, 2]},
12541263
},
@@ -1261,7 +1270,7 @@ def poll_db():
12611270
"isbn": "def",
12621271
"group": None,
12631272
"title": "The Lion Club",
1264-
"_meta": {},
1273+
"_meta": {"book": {"isbn": ["def"]}},
12651274
},
12661275
},
12671276
{
@@ -1271,7 +1280,7 @@ def poll_db():
12711280
"isbn": "ghi",
12721281
"group": None,
12731282
"title": "The Rabbit Club",
1274-
"_meta": {},
1283+
"_meta": {"book": {"isbn": ["ghi"]}},
12751284
},
12761285
},
12771286
]
@@ -1346,6 +1355,7 @@ def test_insert_through_child_op(
13461355
expected = [
13471356
{
13481357
"_meta": {
1358+
"book": {"isbn": ["abc"]},
13491359
"author": {"id": [1, 4, 5]},
13501360
"book_author": {"id": [1, 4, 7]},
13511361
"book_language": {"id": [1, 4, 7, 9]},
@@ -1413,6 +1423,7 @@ def test_insert_through_child_op(
14131423
},
14141424
{
14151425
"_meta": {
1426+
"book": {"isbn": ["def"]},
14161427
"author": {"id": [1, 2]},
14171428
"book_author": {"id": [2, 5]},
14181429
"book_language": {"id": [2, 5, 8]},
@@ -1466,6 +1477,7 @@ def test_insert_through_child_op(
14661477
},
14671478
{
14681479
"_meta": {
1480+
"book": {"isbn": ["ghi"]},
14691481
"author": {"id": [2, 3]},
14701482
"book_author": {"id": [3, 6]},
14711483
"book_language": {"id": [3, 6]},
@@ -1602,6 +1614,7 @@ def test_update_through_child_op(
16021614
expected = [
16031615
{
16041616
"_meta": {
1617+
"book": {"isbn": ["abc"]},
16051618
"author": {"id": [4, 5]},
16061619
"book_author": {"id": [1, 4]},
16071620
"book_language": {"id": [1, 4, 7, 9]},
@@ -1656,6 +1669,7 @@ def test_update_through_child_op(
16561669
},
16571670
{
16581671
"_meta": {
1672+
"book": {"isbn": ["def"]},
16591673
"author": {"id": [1, 2]},
16601674
"book_author": {"id": [2, 5]},
16611675
"book_language": {"id": [2, 5, 8]},
@@ -1709,6 +1723,7 @@ def test_update_through_child_op(
17091723
},
17101724
{
17111725
"_meta": {
1726+
"book": {"isbn": ["ghi"]},
17121727
"author": {"id": [2, 3]},
17131728
"book_author": {"id": [3, 6]},
17141729
"book_language": {"id": [3, 6]},
@@ -1818,6 +1833,7 @@ def test_delete_through_child_op(self, sync, data, nodes, book_author_cls):
18181833
expected = [
18191834
{
18201835
"_meta": {
1836+
"book": {"isbn": ["abc"]},
18211837
"book_language": {"id": [1, 4, 7, 9]},
18221838
"book_subject": {"id": [1, 4, 6]},
18231839
"language": {"id": [1, 2, 3, 4]},
@@ -1840,6 +1856,7 @@ def test_delete_through_child_op(self, sync, data, nodes, book_author_cls):
18401856
},
18411857
{
18421858
"_meta": {
1859+
"book": {"isbn": ["def"]},
18431860
"author": {"id": [1, 2]},
18441861
"book_author": {"id": [2, 5]},
18451862
"book_language": {"id": [2, 5, 8]},
@@ -1893,6 +1910,7 @@ def test_delete_through_child_op(self, sync, data, nodes, book_author_cls):
18931910
},
18941911
{
18951912
"_meta": {
1913+
"book": {"isbn": ["ghi"]},
18961914
"author": {"id": [2, 3]},
18971915
"book_author": {"id": [3, 6]},
18981916
"book_language": {"id": [3, 6]},

‎tests/test_sync_root.py

+205-49
Large diffs are not rendered by default.

‎tests/test_sync_single_child_fk_on_child.py

+71-62
Large diffs are not rendered by default.

‎tests/test_sync_single_child_fk_on_parent.py

+81-60
Large diffs are not rendered by default.

‎tests/test_unique_behaviour.py

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def test_sync_multiple_children_empty_leaf(
220220
"_index": "testdb",
221221
"_source": {
222222
"_meta": {
223+
"book": {"isbn": ["abc"]},
223224
"contact": {"id": [1, 2]},
224225
"user": {"id": [1, 2]},
225226
},

0 commit comments

Comments
 (0)
Please sign in to comment.