# Semana 12: estadísticas, estimación de cardinalidades y planes de ejecución.
# Se usa dentro del contenedor del curso.
#
#   make          crea la base de datos chasqui_w12 con los datos de ejemplo y
#                 hace VACUUM (ANALYZE): así las tablas no tienen páginas vacías
#                 al final y las estadísticas salen siempre iguales
#   make test     la vuelve a crear y corre las pruebas (*.test.mjs)
#   make clean    borra chasqui_w12
#
# Los .sql se corren sobre chasqui_w12, por ejemplo
#   psql -d chasqui_w12 -f stats.sql
# y selectivity.mjs con
#   PGDATABASE=chasqui_w12 node selectivity.mjs shipment created_at '>=' 2026-06-01

DB = chasqui_w12
PSQL = psql -X -q -v ON_ERROR_STOP=1 -d $(DB)

.PHONY: all test clean

all:
	chasqui-load $(DB)
	$(PSQL) -c "VACUUM (ANALYZE)"

# Las pruebas crean índices, tablas y estadísticas y corren ANALYZE: se
# corren una después de otra.
test: all
	PGDATABASE=$(DB) node --test --test-concurrency=1 --test-reporter=spec

clean:
	dropdb --if-exists $(DB)
