From ff97ed553a904ca8d3029ef948719b7c3162da3e Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Thu, 12 Feb 2026 04:01:10 +0000 Subject: [PATCH] Update docs with new view code regardless of db DDL execution --- db/schemas/Makefile | 14 +++++++++++--- make_files/make_db.mk | 13 +++++++++++++ make_files/secondexpansion.mk | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/db/schemas/Makefile b/db/schemas/Makefile index 797c738..6e03a0b 100644 --- a/db/schemas/Makefile +++ b/db/schemas/Makefile @@ -90,6 +90,7 @@ COMMENT_DIRS := ../../doc/sphinx-doc/comment_src \ # The directory recording database create targets DB_CACHE_DIR := db_cache +# $(DB_CACHE) must match with SCHEMA_DB_CACHE in make_files/make_db. DB_CACHE := $(DB_CACHE_DIR)/$(TARGET_DB) # We can't have $(DB_CACHE) as a prerequsite, since its timestamp # gets updated when the directory content is created. So Have @@ -542,6 +543,13 @@ createviews.sql: $(DB_DEPENDS) $(VIEW_CREATE_FILES) \ create_sql.sh ./create_sql.sh '$(VIEW_CREATE_FILES)' > createviews.sql +# Leave breadcrumbs so we only re-create the views for the docs when +# necessary. See comment in: make_files/make_db +# (This does not need to be cached per-db, but it works and does not +# require interactions with, e.g., the doc cache.) +$(DB_CACHE)/views_for_docs: createviews.sql $(DB_CACHE_PREREQ) + touch $@ + ## dropviews.sql ## A file with the SQL which drops all the views dropviews.sql: $(DB_DEPENDS) $(VIEW_DROP_FILES) drop_sql.sh @@ -641,8 +649,8 @@ $(DB_CACHE)/build_comment_files: $(PSQL_DEPENDS) $(DB_CACHE_PREREQ) \ # Running gen_comments.py may take quite some time ./gen_comments.py $(HTML_SRCDIR) $(ORDER) # Aggregate comments in schemas into 2 single files. - touch $(DB_CACHE)/build_comment_files - { ./create_sql.sh '$(COMMENT_ON_FILES)' > comment_on.sql ; \ - ./create_sql.sh '$(COMMENT_OFF_FILES)' > comment_off.sql ; } \ + { { ./create_sql.sh '$(COMMENT_ON_FILES)' > comment_on.sql ; } \ + && { ./create_sql.sh '$(COMMENT_OFF_FILES)' > comment_off.sql ; } \ + && touch $(DB_CACHE)/build_comment_files ; } \ || { rm -f $(DB_CACHE)/build_comment_files ; \ exit 1 ; } diff --git a/make_files/make_db.mk b/make_files/make_db.mk index 965f84e..961ff22 100644 --- a/make_files/make_db.mk +++ b/make_files/make_db.mk @@ -128,6 +128,8 @@ DROP_SUB_DB_TARGETS := db/schemas/droptriggers.sql \ # installed in the db. DB_CACHE_DIR := $(DB_DIR)/db_cache DB_CACHE := $(DB_CACHE_DIR)/$(TARGET_DB) +# SCHEMA_DB_CACHE must match with the $(DB_CACHE) in db/schemas/Makefile +SCHEMA_DB_CACHE := $(DB_DIR)/schemas/db_cache/$(TARGET_DB) # We can't have $(DB_CACHE) as a prerequsite, since its timestamp # gets updated when the directory content is created. So Have # separate prerequsite that keeps track of cache creation time. @@ -468,6 +470,17 @@ db/schemas/createviews.sql db/schemas/dropviews.sql \ db/schemas/createindexes.sql db/schemas/dropindexes.sql: $(PSQL_DEPENDS) $(MAKE) -C db/schemas $(notdir $@) +# When using the recreate-db target, we only want to rebuild the sql +# for the views, and extract the CREATE VIEW statements for inclusion +# in the docs, when the views have changed. Because the +# db/schemas/createviews target is phony, it gets run every time. But +# this means that the recreate-db target needs to scan the new docs +# and put the comments into the db. This is slow, and the point of the +# recreate-db target is to be fast. So have a different target to +# only rebuild the view code when necessary. +$(SCHEMA_DB_CACHE)/views_for_docs: $(PSQL_DEPENDS) + $(MAKE) -C db/schemas $(subst db/schemas/,,$@) + ## db/schemas/comment_on.sql ## Build a file of sql that puts comments on all objects ## db/schemas/comment_off.sql diff --git a/make_files/secondexpansion.mk b/make_files/secondexpansion.mk index c4f1bd6..5b440c8 100644 --- a/make_files/secondexpansion.mk +++ b/make_files/secondexpansion.mk @@ -52,6 +52,7 @@ $(LATEX_RST_FILES): $$(patsubst %.rst,%.m4,\ # The "body" of the CREATE VIEW statements. $(VIEW_SQL): db/schemas/$$(notdir $$(patsubst \ %/,%,$$(dir $$@)))/views/create/$$(notdir $$@) \ + $(SCHEMA_DB_CACHE)/views_for_docs \ $(VIEW_DIR_PREREQ) doc/extract_view.py mkdir -p $(VIEW_DIR)/$$(basename $$(dirname $@)) doc/extract_view.py \ -- 2.34.1