pgbelt 0.7.7__py3-none-any.whl → 0.7.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pgbelt/cmd/sync.py +1 -1
- pgbelt/util/postgres.py +22 -25
- {pgbelt-0.7.7.dist-info → pgbelt-0.7.9.dist-info}/METADATA +1 -1
- {pgbelt-0.7.7.dist-info → pgbelt-0.7.9.dist-info}/RECORD +7 -7
- {pgbelt-0.7.7.dist-info → pgbelt-0.7.9.dist-info}/LICENSE +0 -0
- {pgbelt-0.7.7.dist-info → pgbelt-0.7.9.dist-info}/WHEEL +0 -0
- {pgbelt-0.7.7.dist-info → pgbelt-0.7.9.dist-info}/entry_points.txt +0 -0
pgbelt/cmd/sync.py
CHANGED
|
@@ -30,7 +30,7 @@ async def _sync_sequences(
|
|
|
30
30
|
) -> None:
|
|
31
31
|
|
|
32
32
|
seq_vals = await dump_sequences(src_pool, targeted_sequences, schema, src_logger)
|
|
33
|
-
await load_sequences(dst_pool, seq_vals, dst_logger)
|
|
33
|
+
await load_sequences(dst_pool, seq_vals, schema, dst_logger)
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
@run_with_configs
|
pgbelt/util/postgres.py
CHANGED
|
@@ -15,23 +15,13 @@ async def dump_sequences(
|
|
|
15
15
|
# Get all sequences in the schema
|
|
16
16
|
seqs = await pool.fetch(
|
|
17
17
|
f"""
|
|
18
|
-
SELECT
|
|
18
|
+
SELECT sequence_name
|
|
19
19
|
FROM information_schema.sequences
|
|
20
|
-
WHERE sequence_schema = '{schema}'
|
|
20
|
+
WHERE sequence_schema = '{schema}';
|
|
21
21
|
"""
|
|
22
22
|
)
|
|
23
23
|
|
|
24
|
-
# Note
|
|
25
|
-
# This may not be done by the user, so we must do it here.
|
|
26
|
-
proper_sequence_names = None
|
|
27
|
-
if targeted_sequences is not None:
|
|
28
|
-
proper_sequence_names = []
|
|
29
|
-
for seq in targeted_sequences:
|
|
30
|
-
if f"{schema}." not in seq:
|
|
31
|
-
proper_sequence_names.append(f'{schema}."{seq}"')
|
|
32
|
-
else:
|
|
33
|
-
proper_sequence_names.append(seq)
|
|
34
|
-
targeted_sequences = proper_sequence_names
|
|
24
|
+
# Note, in exodus migrations, we expect the sequence names to not contain the schema name when coming into targeted_sequences.
|
|
35
25
|
|
|
36
26
|
seq_vals = {}
|
|
37
27
|
final_seqs = []
|
|
@@ -42,14 +32,16 @@ async def dump_sequences(
|
|
|
42
32
|
final_seqs = [r[0] for r in seqs]
|
|
43
33
|
|
|
44
34
|
for seq in final_seqs:
|
|
45
|
-
res = await pool.fetchval(f
|
|
35
|
+
res = await pool.fetchval(f'SELECT last_value FROM {schema}."{seq}";')
|
|
46
36
|
seq_vals[seq.strip()] = res
|
|
47
37
|
|
|
48
38
|
logger.debug(f"Dumped sequences: {seq_vals}")
|
|
49
39
|
return seq_vals
|
|
50
40
|
|
|
51
41
|
|
|
52
|
-
async def load_sequences(
|
|
42
|
+
async def load_sequences(
|
|
43
|
+
pool: Pool, seqs: dict[str, int], schema: str, logger: Logger
|
|
44
|
+
) -> None:
|
|
53
45
|
"""
|
|
54
46
|
given a dict of sequence named mapped to values, set each sequence to the
|
|
55
47
|
matching value
|
|
@@ -60,9 +52,9 @@ async def load_sequences(pool: Pool, seqs: dict[str, int], logger: Logger) -> No
|
|
|
60
52
|
logger.info("No sequences to load. Skipping sequence loading.")
|
|
61
53
|
return
|
|
62
54
|
|
|
63
|
-
logger.info(f"Loading sequences {list(seqs.keys())}...")
|
|
64
|
-
sql_template = "SELECT pg_catalog.setval('{}', {}, true);"
|
|
65
|
-
sql = "\n".join([sql_template.format(k, v) for k, v in seqs.items()])
|
|
55
|
+
logger.info(f"Loading sequences {list(seqs.keys())} from schema {schema}...")
|
|
56
|
+
sql_template = "SELECT pg_catalog.setval('{}.\"{}\"', {}, true);"
|
|
57
|
+
sql = "\n".join([sql_template.format(schema, k, v) for k, v in seqs.items()])
|
|
66
58
|
async with pool.acquire() as conn:
|
|
67
59
|
async with conn.transaction():
|
|
68
60
|
await conn.execute(sql)
|
|
@@ -114,17 +106,22 @@ async def compare_data(
|
|
|
114
106
|
full_table_name = f'{schema}."{table}"'
|
|
115
107
|
|
|
116
108
|
logger.debug(f"Validating table {full_table_name}...")
|
|
117
|
-
order_by_pkeys = ",".join(pkeys_dict[table])
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
|
|
110
|
+
# Have to wrap each pkey in double quotes due to capitalization issues.
|
|
111
|
+
order_by_pkeys = ""
|
|
112
|
+
for pkey in pkeys_dict[table]:
|
|
113
|
+
order_by_pkeys += f'"{pkey}", '
|
|
114
|
+
order_by_pkeys = order_by_pkeys[:-2]
|
|
115
|
+
|
|
116
|
+
filled_query = query.format(
|
|
117
|
+
table=full_table_name, order_by_pkeys=order_by_pkeys
|
|
121
118
|
)
|
|
122
119
|
|
|
120
|
+
src_rows = await src_pool.fetch(filled_query)
|
|
121
|
+
|
|
123
122
|
# There is a chance tables are empty...
|
|
124
123
|
if len(src_rows) == 0:
|
|
125
|
-
dst_rows = await dst_pool.fetch(
|
|
126
|
-
query.format(table=full_table_name, order_by_pkeys=order_by_pkeys)
|
|
127
|
-
)
|
|
124
|
+
dst_rows = await dst_pool.fetch(filled_query)
|
|
128
125
|
if len(dst_rows) != 0:
|
|
129
126
|
raise AssertionError(
|
|
130
127
|
f"Table {full_table_name} has 0 rows in source but nonzero rows in target... Big problem. Please investigate."
|
|
@@ -152,7 +149,7 @@ async def compare_data(
|
|
|
152
149
|
dst_query = f"SELECT * FROM {full_table_name} WHERE "
|
|
153
150
|
|
|
154
151
|
for k, v in pkey_vals_dict.items():
|
|
155
|
-
dst_query = dst_query + f"{k} IN ({v}) AND
|
|
152
|
+
dst_query = dst_query + f'"{k}" IN ({v}) AND '
|
|
156
153
|
|
|
157
154
|
# SELECT * FROM <table> WHERE <pkey1> IN (1,2,3,4,5,6...) AND <pkey2> IN ('a','b','c',...);
|
|
158
155
|
comparison_query = dst_query[:-5] + f" ORDER BY {order_by_pkeys};"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pgbelt
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.9
|
|
4
4
|
Summary: A CLI tool used to manage Postgres data migrations from beginning to end, for a single database or a fleet, leveraging pglogical replication.
|
|
5
5
|
Author: Varjitt Jeeva
|
|
6
6
|
Author-email: varjitt.jeeva@autodesk.com
|
|
@@ -7,7 +7,7 @@ pgbelt/cmd/preflight.py,sha256=-78Puqqf1rCxNQEyn4bQIAORez_tsy6zJAbSuO_de9s,20676
|
|
|
7
7
|
pgbelt/cmd/schema.py,sha256=XAAj2BH6HVoA1LxuWw2kheesGDu41L3GAd5UahNp3nE,4760
|
|
8
8
|
pgbelt/cmd/setup.py,sha256=Jp5sqT9_whoVBiOzAlOzX1ubtXQADYBkBrJldch_fKk,6627
|
|
9
9
|
pgbelt/cmd/status.py,sha256=LTvteFwA1jcfnGJdlA2siJn5TUtlf14ffMkGVSi5gi0,4730
|
|
10
|
-
pgbelt/cmd/sync.py,sha256=
|
|
10
|
+
pgbelt/cmd/sync.py,sha256=JOOVn7nIIOpQ0bGFqHIXRq87pHOOAD6U8kdQzgngGxs,9035
|
|
11
11
|
pgbelt/cmd/teardown.py,sha256=Nl37vpugxO7QHO0tKpTfZDV0KtsSm0SbWUbzb3k2N-0,3545
|
|
12
12
|
pgbelt/config/__init__.py,sha256=SXok1aZcpMYJpX_hk5cuKO33CJ5s8IESkswNN9KsVSo,35
|
|
13
13
|
pgbelt/config/config.py,sha256=Kw2H-G1Evfj0TXIbh3k06gE72dZEp_wXWJ2Icq_T54c,3817
|
|
@@ -19,9 +19,9 @@ pgbelt/util/asyncfuncs.py,sha256=7i_GpBmUNNZ8RUGvU-q5nclsoaCm6Lx8jLP8usYvmZc,583
|
|
|
19
19
|
pgbelt/util/dump.py,sha256=AwyOAd9CP014gvsl-qlo1lbnXZfxoeN4ujZWUIq7KM8,14715
|
|
20
20
|
pgbelt/util/logs.py,sha256=l2jT-WKZ-33eNDw4S4W1_eE4ISo4rtDRXYLVf4QTV4Y,1699
|
|
21
21
|
pgbelt/util/pglogical.py,sha256=Y6KZBeiH85zhNSvhATqh0xozhfUMyQnPWN1HwRosZFo,13613
|
|
22
|
-
pgbelt/util/postgres.py,sha256=
|
|
23
|
-
pgbelt-0.7.
|
|
24
|
-
pgbelt-0.7.
|
|
25
|
-
pgbelt-0.7.
|
|
26
|
-
pgbelt-0.7.
|
|
27
|
-
pgbelt-0.7.
|
|
22
|
+
pgbelt/util/postgres.py,sha256=XlbgadfrlnF7wEYzQjHUmhIYlIH3FOVc5FcFzDD3kvY,19206
|
|
23
|
+
pgbelt-0.7.9.dist-info/LICENSE,sha256=FQ5cFkW02dKK3LmKH8z-rwn93tWSCh7lsxfNUiWcFsg,10758
|
|
24
|
+
pgbelt-0.7.9.dist-info/METADATA,sha256=_ZLX-4MRhCnbkzmJmeuOhpgF5EP2BhR0_Pz_8Rf-Rro,2960
|
|
25
|
+
pgbelt-0.7.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
26
|
+
pgbelt-0.7.9.dist-info/entry_points.txt,sha256=SCz_poPjkaVnWpJ-CeytAnDzbVc6l0WalOwitIqW_3g,40
|
|
27
|
+
pgbelt-0.7.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|