Skip to content

Commit cadf7dd

Browse files
authored
#29: add catalog to last_update table (#396)
1 parent f401466 commit cadf7dd

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

app/data/repositories/layer2/repository.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ def __init__(self, storage: postgres.PgStorage, logger: structlog.stdlib.BoundLo
2525
self._storage = storage
2626

2727
def get_last_update_time(self) -> datetime.datetime:
28-
return self._storage.query_one("SELECT dt FROM layer2.last_update")["dt"]
28+
return self._storage.query_one("SELECT dt FROM layer2.last_update WHERE catalog = %s", params=["all"])["dt"]
2929

3030
def update_last_update_time(self, dt: datetime.datetime):
31-
self._storage.exec("UPDATE layer2.last_update SET dt = %s", params=[dt])
31+
self._storage.exec(
32+
"UPDATE layer2.last_update SET dt = %s WHERE catalog = %s",
33+
params=[dt, "all"],
34+
)
3235

3336
def get_orphaned_pgcs(self, catalogs: list[model.RawCatalog]) -> dict[str, list[int]]:
3437
result: dict[str, list[int]] = {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* pgmigrate-encoding: utf-8 */
2+
ALTER TABLE layer2.last_update ADD COLUMN catalog text;
3+
4+
UPDATE layer2.last_update SET catalog = 'all';
5+
6+
ALTER TABLE layer2.last_update ALTER COLUMN catalog SET NOT NULL;
7+
8+
ALTER TABLE layer2.last_update ADD PRIMARY KEY (catalog);

tests/lib/postgres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def clear(self):
137137
):
138138
self.storage.exec(f"TRUNCATE {table['table_schema']}.{table['table_name']} CASCADE")
139139

140-
self.storage.exec("INSERT INTO layer2.last_update VALUES (to_timestamp(0))")
140+
self.storage.exec("INSERT INTO layer2.last_update (dt, catalog) VALUES (to_timestamp(0), 'all')")
141141

142142
def get_storage(self) -> postgres.PgStorage:
143143
return self.storage

0 commit comments

Comments
 (0)