django-materialized-views
Model, migrate, refresh, and verify PostgreSQL materialized views in Django for expensive report or dashboard queries that can tolerate stale data. Use when ORM/index/query rewrites are not enough, the result is read often, freshness can be bounded, and a Django app needs unmanaged models, RunSQL migrations, refresh commands, or concurrent refresh.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- django-materialized-views
- license
- MIT
- metadata
- { "tags": "django,database,materialized-views,postgres,performance", "version": "0.1.0", "category": "Django", "displayName": "Django Materialized Views" }
- description
- Model, migrate, refresh, and verify PostgreSQL materialized views in Django for expensive report or dashboard queries that can tolerate stale data. Use when ORM/index/query rewrites are not enough, the result is read often, freshness can be bounded, and a Django app needs unmanaged models, RunSQL migrations, refresh commands, or concurrent refresh.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 1
- 参考文档references/materialized-view-patterns.md2.8 KB
03 SKILL.md 正文
Django Materialized Views
Use this skill when an expensive read query is reused often and can tolerate controlled staleness. Try query-plan, index, and ORM expression improvements first; materialized views add operational state.
Workflow
-
Confirm fit.
- The source query is expensive and stable.
- Consumers can accept stale data.
- Refresh cadence, ownership, and failure behavior are clear.
- PostgreSQL is the target database.
-
Design the materialized view.
- Define the SQL query and output columns.
- Add a unique column or unique column set if concurrent refresh is required.
- Add indexes for consumer queries against the view.
-
Integrate with Django.
- Create the view with
RunSQL. - Represent it as an unmanaged model with
managed = False. - Keep the unmanaged model fields aligned with the SQL output.
- Make writes impossible at the application boundary.
- Create the view with
-
Implement refresh.
- Use
REFRESH MATERIALIZED VIEWfor simple refreshes. - Use
REFRESH MATERIALIZED VIEW CONCURRENTLYonly when the view is already populated and has a qualifying unique index. - Schedule refresh through a management command, task queue, or database job.
- Use
See materialized-view-patterns.md for migration, model, and refresh templates.
Safety Notes
- A materialized view returns stored data; it is not automatically current.
- Concurrent refresh avoids locking out reads but has prerequisites and still allows only one refresh at a time per view.
- Refreshing a large view can be a major database workload. Measure it separately from reads.
Verification
Validate the SQL against source tables, test the unmanaged model reads, prove refresh behavior, and measure read latency before/after.
04 同仓库更多 Skills
android-emulator-qa
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
supabase-postgres-best-practices
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
render-workflows
Sets up, develops, tests, and deploys Render Workflows. Covers first-time scaffolding (via CLI or manual), SDK installation (Python or TypeScript), task patterns (retries, subtasks, fan-out), local development, Dashboard deployment, and troubleshooting. Use when a user wants to set up Render Workflows for the first time, scaffold a workflow service, add or modify workflow tasks, test workflows locally, or deploy workflows to Render.
render-web-services
Configures Render web services—port binding, TLS, health checks, custom domains, auto-deploy, PR previews, persistent disks, and deploy lifecycle. Use when the user needs to set up a web service, fix health check failures, add a custom domain, configure zero-downtime deploys, or troubleshoot port binding issues.
render-static-sites
Deploys and configures static sites on Render's global CDN—build commands, publish paths, SPA routing, redirects, custom headers, and PR previews. Use when the user needs to deploy a static site, set up a React/Vue/Hugo/Gatsby frontend, configure SPA fallback routing, add redirect rules, customize response headers, or choose between a static site and a web service for their frontend. Trigger terms: static site, CDN, SPA, single-page app, React deploy, Vue deploy, Hugo, Gatsby, Docusaurus, Jekyll, staticPublishPath.