Skip to content

Commit 7780484

Browse files
committed
fix(sync): re-apply datastore GRANTs after restore so views generate
pg_restore --no-privileges strips every GRANT from the restored datastore DB. The datastore_ro role then can't SELECT from _table_metadata, so DataPusher's datastore_search call 500s, push_to_datastore aborts before pushing rows, and the 'complete' callback that creates datatables_view never fires. Uploads appear to succeed but views never show up. Run 'ckan datastore set-permissions' after the restore and pipe the canonical GRANT script into psql as ckan_admin against the datastore DB.
1 parent f00c48d commit 7780484

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

deploy/sync/sync.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,31 @@ def _enabled_plugins(cfg: Config) -> list[str]:
430430
return result.stdout.split()
431431

432432

433+
def grant_datastore_permissions(cfg: Config) -> None:
434+
"""Re-apply datastore role GRANTs after restore.
435+
436+
pg_restore runs with --no-privileges, which strips every GRANT from
437+
the restored datastore DB. The datastore_ro role then can't SELECT
438+
from _table_metadata, so DataPusher's `datastore_search` call 500s,
439+
push_to_datastore aborts before it pushes any rows, and the
440+
`complete` callback that creates datatables_view never fires —
441+
uploads succeed but views don't appear.
442+
443+
`ckan datastore set-permissions` prints the canonical GRANT script
444+
to stdout; we pipe it into psql as ckan_admin against the datastore
445+
DB."""
446+
result = subprocess.run(
447+
["kubectl", "exec", "-n", cfg.ckan_namespace, cfg.ckan_deployment, "--",
448+
"ckan", "-c", "/tmp/production.ini", "datastore", "set-permissions"],
449+
capture_output=True, text=True, check=True,
450+
)
451+
run(
452+
["psql", "-v", "ON_ERROR_STOP=1"],
453+
env=pg_env(cfg.staging_ckan_url, db_override="datastore"),
454+
input=result.stdout, text=True,
455+
)
456+
457+
433458
def ckan_reindex(cfg: Config) -> None:
434459
# CKAN config is merged at startup to /tmp/production.ini
435460
# (base.ini + env.ini + secrets.ini); see deploy/base.ini.
@@ -566,6 +591,7 @@ def main() -> int:
566591
_blob_url(cfg.staging_lfs_account, cfg.staging_lfs_container, cfg.staging_lfs_sas),
567592
)
568593
ckan_migrate(cfg)
594+
grant_datastore_permissions(cfg)
569595
ckan_reindex(cfg)
570596

571597
slack(cfg, "sync OK", level="OK")

0 commit comments

Comments
 (0)