惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
罗磊的独立博客
S
SegmentFault 最新的问题
V
V2EX
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
D
Docker
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
M
Microsoft Research Blog - Microsoft Research
Martin Fowler
Martin Fowler
S
Secure Thoughts
B
Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
T
True Tiger Recordings
GbyAI
GbyAI
P
Proofpoint News Feed
P
Privacy International News Feed
Jina AI
Jina AI
The Cloudflare Blog
I
Intezer
AWS News Blog
AWS News Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Archives - TechRepublic
NISL@THU
NISL@THU
The Register - Security
The Register - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Palo Alto Networks Blog
S
Schneier on Security
L
LINUX DO - 热门话题
C
CXSECURITY Database RSS Feed - CXSecurity.com
Security Latest
Security Latest
C
Cybersecurity and Infrastructure Security Agency CISA

DEV Community

Why I Built Mneme HQ: Preventing AI Agent Architectural Drift I Built a Pay-Per-Call Crypto Signal API with x402 — Heres the Architecture 🚀 “From Prompts to Autonomous Agents: What Google I/O 2026 Changed” The Power of Distributed Consensus in Autonomous SOCs Sixteen TUI components, copy-paste, no dependency The Boring Reliability Layer Every Autonomous Agent Needs Nven - Secret manager Building Multi-Tenant Row-Level Security in PostgreSQL: A Production Pattern Building Vylo — Looking for Collaborators, Partners & Early Support I Thought Memory Fades With Time. It Actually Fades With Information. ORA-00064 오류 원인과 해결 방법 완벽 가이드 I registered an AI agent at 1 AM and something cracked open in my head Pitch: Nven - Sync secrets. Ship faster. Why y=mx+b is the heart of AI From Routines to a Crew — Building a System That Plans Its Own Work & executes it 25 React Interview Questions 2026 (With Answers) — Hooks, React 19, Concurrent Mode An open source LLM eval tool with two independent quality signals Using Dashboard Filtering to Get Customer Usage in Seconds from TBs of Data Skills, Java 17, And Theme Accents 4 Hard Lessons on Optimizing AI Coding Agents Arctype: Cross-Platform Database GUI for LLM Artifacts Your robots.txt says GPTBot is welcome. Your server says 403. Organizing How to Use AWS Glue Workflow 5 n8n Automations Every Digital Agency Should Be Running (Bill More, Work Less) Getting Started with TorchGeo — Remote Sensing with PyTorch Designing a Scalable Cross-Platform Appium Framework Google Antigravity 2.0 & Slash Commands Building a Unified Adaptive Learning Intelligence with Gemma 4, Flutter, and Multi-Model Orchestration Looking for beta testers for a £60 server management application The Disk-Pressure Incident That Taught Me to Always Set LimitRanges and Other Lessons from Mirroring EKS Locally. Why AI Should Not Write SQL Against ERP Databases Vibe coding works until it doesn't. The debt is real. Shipping at the Edge: Migrating a Coffee Subscription Platform to Cloudflare Workers Stop Tab-Switching: A Developer's Guide to Color Tools That Actually Fit the Workflow DevOps vs MLOps vs AIOps: What Changes, What Stays, and a Simple Roadmap to Get Started Run Powerful AI Coding Locally on a Normal Laptop 5 n8n Automations Every WooCommerce Store Needs (Save 10+ Hours/Week) What I Learned Building My Own AI Harness Hytale Servers Will Fail Treasure Hunts Until We Fix Our Event Handling Redux in React: Managing Global State Like a Pro Unfreezing Your GitHub Actions: Troubleshooting Stuck Deployments and Protecting Your Git Repo Statistics Unlocking Project Discoverability on GHES: A Key to Software Engineering Productivity When the Cleanup Code Becomes the Project Rockpack 8.0 - A React Scaffolder Built for the Age of AI-Assisted Development Mismanaging the Treasure Hunt Engine in Hytale Servers Will Get You Killed Stop Calling It an AI Assistant. It’s Already Managing Your Company Why Hardcoded Automations Fail AI Agents Why I built a post-quantum signing API (and why JWT is on borrowed time) Weekend Thought: Frontend Build Tools Suffer From Work Amnesia A 10-Line Playwright Trick That Saved Me Hours on Every Sephora Run AI Is Changing Engineering Culture More Than We Realize Everyone Was Focused on Gemini, But Infinite Scaler Was the Real Twister "Gemma 4 Analyzed My Bank Statements – Apparently I 'Have a Problem' with Coffee and Late-Night Apps" #css #webdev #beginners #codenewbie The Hidden Layer Every AI Developer Must Learn AlphaEvolve: Google DeepMind's Gemini-Powered Evolutionary Coding Agent RDS Reserved Instance Pricing: Every Engine, Every Rule, Real Dollar Savings How To Build An AI-Powered MVP Without Burning Your Startup Budget In 2026 Reading a Psychrometric Chart Without Getting Lost LMR-BENCH: Can LLM Agents Reproduce NLP Research Code? (EMNLP 2025) How to turn text into colors (without AI) Building Real-Time Apps in Node.js with Rivalis: WebSockets, Rooms, Actors, and a Binary Wire This Week In React #282 : Security, Fate, TanStack, Redux, Jotai | Hermes-node, Expo, Rozenite, Harness | TC39, Bun, pnpm, npm, Yarn, Node AI Copilot vs AI Agent Architecture - What's Actually Different (And Why It Matters) Smart Contract Security: NEAR's Futures Surge and AI Token Risks Database Maintenance: Tracing Production Incidents to Their Root Cause Stop juggling AI SDKs in PHP — meet Prisma Google Quietly Changed What “Apps” Mean at I/O 2026 The Infrastructure Team Is the Real Single Point of Failure Building SQLite from Scratch: 740 Lines of C++23 to Understand Every Byte of a .db File The 4 Levels of Hermes Agent Scaling Framework: From One Hermes Agent to a Fully Automated Team Your AI Has a Memory. It Just Doesn’t Know What to Remember. Claprec: Engineering Tradeoffs - Limited time vs. Perfection (6/6) Building a Daily Google News API Monitor in Python Building RookDuel Avikal: From Chess Steganography to Post-Quantum Archival Security Google I/O e IA: o que realmente muda na vida do dev? Color Contrast Failures: The Number One Accessibility Issue and How to Fix It # I Watched 15 Hours of Hermes Agent Videos So You Don't Have To Cómo solucionar el bucle infinito en useEffect con objetos y arrays en React The First Agent-Centric Cloud Security Platform — And Why We Didn't Build It That Way On Purpose Most Treasure Hunts Engines on Hytale Servers Are Built to Fail - Lessons from a Burned Database GhostScan v3.0 — From Closed-Source EXE to Open-Source Pentest Framework De hojas de cálculo a IA: construyendo una plataforma SRM moderna When is AI fine in education? Python Tools for Managing API Rate Limits in Data Pipelines How to Implement Exponential Backoff for Rate-Limited APIs in Python "My Web Chat Wasn't a Real Channel. That Broke My Agent Pipeline" next-advanced-sitemap v1.0.7 — safer URL ingestion & automatic trimming for Next.js sitemap generation I keep seeing people build an AI lead processing agent when they really need a 6-step rules engine AI Powered Student Learning Assistant Using Gemma 4 How I Built a Drop-In Proxy to Slash My OpenAI Bills by 20%+ Automatically Building a Sarcastic AI English Tutor with Persona-as-Code and Gemini Audio Input for Pronunciation Correction Five Years Later, I Finally Have 96GB VRAM — What It Actually Unlocks for Agent Loops Turning a 1-Line Idea Into a 40-Second Short with a 10-Beat Local Video Pipeline Running LTX-2.3 Alongside TTS on a Single 96GB GPU with a Cold-Start Architecture Cutting LTX-2 22B Peak VRAM by 40% with fp8_cast — and Why optimum-quanto Was a Trap HiDream Skeleton Mode: Prompt Beats OpenPose Ref — 8 Patterns Benchmarked Replicating a Language-Learning Comedy Short with Claude Code — Gemini as a Multimodal Sub-Agent HiDream-O1-Image 3–8x Faster: Benchmarking Steps, CFG, and Resolution AWS Savings Plan Buying Strategy: How to Layer, Size, and Time Commitments
PostgreSQL centric - Planetary Architecture
Ryo Suwito · 2026-05-18 · via DEV Community

Product Requirements Document

PostgreSQL is not the persistence layer. It is the application. Everything else is orbit.


1. Vision

Modern web stacks treat the database as a dumb filing cabinet at the end of a long chain — request → router → controller → service → ORM → DB. Business logic is smeared across every layer. Security is enforced in the app. Permissions live in middleware. Mutations go through serializers. The database just executes INSERT and stays quiet.

Planetary Architecture inverts this.

PostgreSQL is the sun. Every other component — the admin dashboard, the HTTP adapter, the frontend, the external services — orbits it. Business logic, authorization, validation, transformation, and auditing all live inside Postgres. Downstream layers are deliberately dumb: they render, they route, they receive webhooks. They do not own logic.

The platform — django-pg-planetary — is the control plane that makes this architecture operable without writing a single line of SQL. It extends Django admin into a full database operations dashboard, serving every persona involved in building and running a Planetary stack.


2. The Stack

┌─────────────────────────────────────────────────────────────┐
│                      CONTROL PLANE                          │
│         django-pg-planetary (Django Admin Extension)        │
│         Karen · Bob · Senior Dev — one unified dashboard    │
└──────────────────────────┬──────────────────────────────────┘
                           │  DDL only · metadata only
                           │  never raw table data
┌──────────────────────────▼──────────────────────────────────┐
│                   ☀️  POSTGRESQL (the app)                   │
│                                                             │
│  raw tables      — superadmin only, REVOKE ALL on everyone  │
│  views           — DTOs, redacted, role-scoped              │
│  INSTEAD OF      — the only way CUD ever happens            │
│  functions       — business logic, overloaded by signature  │
│  RLS policies    — authorization at the row level           │
│  triggers        — mutations, audits, notifications         │
│  types/domains   — validated, reusable data shapes          │
│  FDW             — forensic audit to separate DB            │
│  pg_notify       — async event emission                     │
└────────┬────────────────────────────────────────────────────┘
         │                              │
         │ pg_notify / pg_net           │ SQL over HTTP
         │                  ┌───────────▼──────────┐
         │                  │       PostgREST       │
         │                  │   dumb HTTP adapter   │
         │                  │   exposes views +     │
         │                  │   functions as REST   │
         │                  └───────────┬──────────┘
         │                              │ REST + JWT
         │                  ┌───────────▼──────────┐
         │                  │     Next.js BFF       │
         │                  │  renders · consumes   │
         │                  │  zero business logic  │
         │                  └───────────┬──────────┘
         │                              │
┌────────▼──────────────────────────────▼──────────────────────┐
│                   SERVICES (dumb, isolated)                   │
│     pdf-export · email · payment · sms · storage · etc.      │
│     receive payload · do one thing · return result           │
│     know nothing about the DB schema                         │
└──────────────────────────────────────────────────────────────┘
         │
┌────────▼──────────────────────────────────────────────────────┐
│                    AUDIT DB (FDW shadow)                       │
│     separate server · append-only · forensic isolation        │
│     full before/after JSON trail per row per operation        │
└────────────────────────────────────────────────────────────────┘

Enter fullscreen mode Exit fullscreen mode


3. Personas

Karen — Business Operations

Uses Django admin to browse and manage data rows. Her experience is unchanged from standard Django admin. She interacts with views only — never raw tables. RLS ensures she sees exactly what her role allows, automatically.

Bob — DevOps / DB Administrator

Uses the planetary extension to manage the full Postgres security and infrastructure layer. Zero SQL written. He manages roles, grants, policies, table health, scheduled jobs, replication, and configuration through GUI forms that generate and execute SQL behind the scenes.

Senior Developer

Uses the extension to design and apply the Postgres application layer. Writes function bodies, designs view schemas, declares protected tables, manages types, configures FTS, and controls the audit setup. The platform scaffolds everything; Senior fills in the business logic.

PostgREST (system actor)

Watches Postgres. Exposes whatever views and functions exist as REST endpoints, scoped by JWT role claims. Picks up every change Senior makes automatically. No configuration required per new view or function.

Next.js BFF (system actor)

Consumes PostgREST endpoints. Renders data. Calls service endpoints for non-DB operations. Has no knowledge of the underlying schema, RLS rules, or function signatures.


4. Core Principles

4.1 The Protected Table Contract

Every raw table in a Planetary stack follows this contract:

  1. REVOKE ALL ON raw_table FROM PUBLIC — no one touches data directly
  2. REVOKE ALL ON raw_table FROM app_role — includes the Django DB user
  3. One or more views declared as the only access points
  4. INSTEAD OF triggers on each view — the only mutation path
  5. Overloaded functions per operation type — validation and transformation
  6. RLS on views — row-level authorization per role/claim

The platform scaffolds steps 1–6 from a single "Protect this table" action. Senior fills in function bodies. Everything else is generated.

4.2 Views as DTOs

A view is not a convenience — it is an explicit API contract. One raw table can have many views:

invoice_raw          ← locked, superadmin only
  invoice_v          ← standard ops view, status + amounts
  invoice_v_finance  ← finance role, full breakdown
  invoice_v_redacted ← public-facing, PII masked
  invoice_v_audit    ← compliance, all fields + metadata

Enter fullscreen mode Exit fullscreen mode

PostgREST exposes each view as a separate endpoint. RLS on each view enforces who can query what. No app-layer serializers needed.

4.3 Metadata ≠ Data Privileges

Revoking data access from the Django DB user does NOT revoke metadata access. The platform can fully introspect any table's columns, types, constraints, indexes, policies, and triggers via pg_catalog and information_schema — without ever reading a row of actual data. This is the foundation of the view builder, policy editor, and trigger scaffolder.

4.4 Functions as the Business Logic Layer

Postgres functions are:

  • Overloadable by signature — process_invoice(a) and process_invoice(a, b) coexist
  • Transactional — they run inside the trigger's transaction
  • Testable — callable directly via PostgREST or SELECT
  • Replaceable — CREATE OR REPLACE with no downtime

All validation, transformation, computed fields, and side-effect orchestration live in functions. The app layer calls views. It never implements business logic.

4.5 FDW Forensic Audit

Audit triggers write to a foreign table backed by a separate database server via postgres_fdw. The audit DB is:

  • On a different host (optionally different provider)
  • Append-only by policy — no UPDATE, no DELETE
  • Invisible to application roles
  • Full row_to_json(OLD) / row_to_json(NEW) per operation

If the main DB is compromised, wiped, or ransomwared — the audit trail is untouched on a completely separate server. The platform wires this up per table with a toggle.


5. Platform Features

5.1 Introspection Engine

The foundation. Pure pg_catalog + information_schema queries. Returns structured metadata the UI builds on. No data access required.

  • Tables, columns, data types, nullability, defaults
  • Constraints — PK, FK, unique, check, exclusion
  • Indexes — type, columns, partial condition, expression
  • Views + materialized views — definition, dependencies
  • Stored functions + procedures — signature, language, body, security
  • Triggers — timing, event, level, condition, function
  • Policies — command, roles, USING, WITH CHECK expressions
  • Roles + grants — membership, table/column/schema privileges
  • Extensions — installed, available, version
  • FDW servers + foreign tables
  • Publications + subscriptions
  • Table health — live tuples, dead tuples, bloat, last vacuum/analyze

5.2 Protected Table Manager (Senior + Bob)

The core workflow of the platform.

Declare a table as protected:

  • Select table from introspected list
  • Platform generates REVOKE statements for all non-superadmin roles
  • Column picker: drag-drop columns into one or more named views
  • Per-column: include / exclude / apply redaction function
  • Platform generates CREATE VIEW for each declared view
  • INSTEAD OF trigger skeleton auto-generated per view
  • Senior writes function body in inline editor
  • One-click apply — REVOKE + views + triggers executed in single transaction

View builder:

  • Visual column selector from introspected schema
  • Redaction function picker (mask_pan, mask_email, hash, nullify, etc.)
  • Live SQL preview
  • Role assignment — which PostgREST role sees this view
  • RLS policy generator — column picker for USING expression

5.3 Policy Manager — RLS / RBAC / ABAC / PBAC (Bob + Senior)

RLS Policies:

  • Enable/disable RLS per table/view — toggle
  • Create policy: name, table, command (ALL/SELECT/INSERT/UPDATE/DELETE)
  • USING expression builder — column picker + operator + value/function
  • WITH CHECK expression builder
  • PERMISSIVE vs RESTRICTIVE toggle
  • Role assignment
  • Live SQL preview
  • Active policies list with enable/disable per policy

Role Management (RBAC):

  • Create / rename / drop roles
  • Role membership — assign roles to roles (hierarchy)
  • Grant / revoke table privileges per role
  • Grant / revoke column-level privileges
  • Grant / revoke schema privileges
  • Grant / revoke function execute privileges
  • Role matrix view — roles × tables × privileges grid

Session Claims (ABAC):

  • Define current_setting('app.x') claim variables used in policies
  • JWT claim → set_config mapping documentation per role
  • Policy expression helpers using claim variables

Policy Templates (PBAC):

  • User-owns-row: user_id = current_setting('app.user_id')::uuid
  • Tenant isolation: tenant_id = (auth.jwt() ->> 'tenant_id')::uuid
  • Soft-delete filter: deleted_at IS NULL
  • Time-bounded: valid_from <= now() AND valid_to >= now()
  • Save custom templates — reusable across tables

5.4 Function & Trigger Manager (Senior)

Functions:

  • List all stored functions with signature, language, security mode
  • Create / edit function — inline code editor with syntax highlighting
  • Language picker — plpgsql, sql, python (plpython3u)
  • SECURITY INVOKER vs SECURITY DEFINER toggle
  • Parameter builder — name, type, default, mode (IN/OUT/INOUT)
  • Return type picker — scalar, setof, table, trigger, void
  • Function overload group view — all signatures for same name
  • Test runner — call function with sample args, see output

Triggers:

  • List all triggers per table with status
  • Create trigger: timing (BEFORE/AFTER/INSTEAD OF), event (INSERT/UPDATE/DELETE/TRUNCATE)
  • Column-specific UPDATE trigger (OF col1, col2)
  • FOR EACH ROW vs FOR EACH STATEMENT toggle
  • WHEN condition builder
  • Function picker from existing trigger functions
  • Enable / disable per trigger
  • Deferrable + deferred toggle

Event Triggers (DDL-level):

  • Fire on CREATE TABLE, ALTER TABLE, DROP, etc.
  • Auto-attach audit triggers to any new table — set-and-forget for Bob
  • Enforce naming conventions on DDL operations

5.5 Schema Object Manager (Senior + Bob)

Views:

  • List all views with definition preview
  • Create / edit view — column picker + SQL editor
  • Dependency graph — which tables/functions a view uses
  • Drop cascade safety — shows what breaks before executing

Materialized Views:

  • Create materialized view from view or raw SQL
  • Refresh strategy — manual / pg_cron scheduled
  • Refresh schedule builder (cron expression)
  • Index management on materialized view columns
  • Concurrent refresh toggle

Custom Types:

  • ENUM types — create, add values, rename, drop
  • Composite types — field builder with name + type
  • Domain types — base type + CHECK constraint
  • Range types — subtype + canonical function

Extensions:

  • Available extensions list with description
  • Install / drop per extension
  • Version display
  • Commonly useful: uuid-ossp, pgcrypto, pg_stat_statements, pg_cron, pg_net, postgres_fdw, postgis, unaccent, btree_gin

Sequences:

  • List, create, alter (start, increment, min, max, cycle)
  • Current value display
  • Owned-by column display

Schemas:

  • Create / drop schemas
  • search_path configuration per role
  • Move tables between schemas

5.6 Index Manager (Bob + Senior)

  • List all indexes — type, columns, size, usage stats
  • Detect unused indexes via pg_stat_user_indexes (idx_scan = 0)
  • Create index — type picker (B-tree, GIN, GiST, BRIN, Hash)
  • Partial index — WHERE clause builder
  • Expression index — expression input with column picker
  • Concurrent build toggle (non-blocking)
  • Index size vs query benefit display

5.7 Full Text Search (Senior)

  • Text search configuration manager
  • Dictionary management
  • tsvector column setup — which columns, which config
  • to_tsvector expression builder
  • GIN index auto-suggestion on tsvector columns
  • Test query — enter search terms, preview ranked results

5.8 Audit Layer (Bob)

  • Enable audit per table — toggle
  • FDW server configuration — host, dbname, credentials
  • Foreign table auto-creation on audit DB
  • Audit trigger auto-generated and attached
  • Audit log viewer (reads from foreign table — read-only)
  • Audit DB health status
  • Retention policy — pg_cron job to prune old audit records (on audit DB side)

5.9 Replication & CDC (Bob)

  • Publications — create, add/remove tables, manage row filters
  • Subscriptions — create, monitor lag, enable/disable
  • Logical replication slot monitoring
  • FDW connections — list, test, drop

5.10 Scheduled Jobs — pg_cron (Bob)

  • List all cron jobs with schedule, last run, status
  • Create job — SQL input + cron expression builder
  • Enable / disable per job
  • Run now (immediate one-off execution)
  • Job run history + error log

5.11 Notifications — pg_notify / pg_net (Senior)

  • NOTIFY channels in use — list active LISTEN connections
  • pg_net webhook trigger builder — target URL, payload template
  • Outbound webhook log (via net._http_response)

5.12 Performance & Health (Bob)

  • Table stats — live tuples, dead tuples, bloat %, last vacuum/analyze
  • pg_stat_statements — top queries by total time, calls, mean time
  • Cache hit ratio — buffer hits vs disk reads
  • Connection stats — active, idle, idle-in-transaction, by role
  • Lock monitor — active locks, blocking queries, wait graph
  • VACUUM / ANALYZE — trigger manually per table or ALL
  • Autovacuum settings — per-table overrides (fillfactor, thresholds)
  • Table size breakdown — table + indexes + toast

5.13 Configuration (Bob)

  • ALTER SYSTEM GUI — categorized parameter list
  • Search params by name or description
  • Current vs pending (requires reload) indicator
  • pg_reload_conf() trigger button
  • Per-database and per-role parameter overrides via ALTER DATABASE SET / ALTER ROLE SET

5.14 PostgREST Integration

  • View → PostgREST endpoint mapping display
  • Function → RPC endpoint display (/rpc/function_name)
  • JWT role claim → Postgres role mapping documentation
  • Schema cache reload trigger (NOTIFY pgrst, 'reload schema')
  • Endpoint health check per view

6. Non-Goals

  • Not a data browser. Django admin owns rows and data management. This platform does not display table contents except for the audit log viewer.
  • Not a query editor. Not a replacement for psql, DBeaver, or TablePlus. Senior who needs raw SQL uses those tools.
  • Not an ORM. No model abstraction. Everything is native Postgres SQL, generated and executed directly.
  • Not a migration framework. No Alembic/django-migrate style versioned migrations. DDL changes are applied directly. Event triggers handle DDL auditing.
  • Not a connection pooler. PgBouncer / Supavisor are separate infrastructure concerns.

7. Privilege Architecture

superadmin         → everything. raw tables, DDL, pg_catalog, config
senior_dev role    → DDL via platform, metadata, no raw table data
bob_devops role    → platform UI operations, metadata, health stats
django_app role    → metadata on raw tables, data on views only
postgrest role     → data on views, scoped by JWT sub-role
karen role         → rows in views, filtered by RLS
audit_writer role  → INSERT only on foreign audit tables

Enter fullscreen mode Exit fullscreen mode

The platform authenticates as django_app for introspection. DDL operations are executed via a separate platform_ddl role with elevated privileges, scoped to specific operations, never exposed to the HTTP layer.


8. Package Design

django-pg-planetary/
├── planetary/
│   ├── apps.py                  ← PlanetaryConfig, auto-registers admin
│   ├── introspect/
│   │   ├── tables.py            ← columns, types, constraints
│   │   ├── policies.py          ← pg_policies queries
│   │   ├── roles.py             ← pg_roles, memberships, grants
│   │   ├── routines.py          ← functions, triggers, event triggers
│   │   ├── objects.py           ← views, matviews, types, sequences
│   │   ├── indexes.py           ← index stats, usage
│   │   ├── health.py            ← pg_stat_*, vacuum, bloat
│   │   └── replication.py       ← publications, subscriptions, slots
│   ├── builders/
│   │   ├── policy_builder.py    ← CREATE/ALTER/DROP POLICY → SQL
│   │   ├── role_builder.py      ← GRANT/REVOKE/CREATE ROLE → SQL
│   │   ├── trigger_builder.py   ← CREATE/DROP TRIGGER → SQL
│   │   ├── view_builder.py      ← CREATE VIEW / INSTEAD OF → SQL
│   │   ├── function_builder.py  ← CREATE OR REPLACE FUNCTION → SQL
│   │   └── audit_builder.py     ← FDW setup, audit trigger → SQL
│   ├── executor.py              ← safe DDL execution, transaction wrapper
│   ├── admin/
│   │   ├── policy_admin.py
│   │   ├── role_admin.py
│   │   ├── schema_admin.py
│   │   ├── trigger_admin.py
│   │   ├── function_admin.py
│   │   ├── health_admin.py
│   │   ├── audit_admin.py
│   │   └── cron_admin.py
│   ├── templates/
│   │   └── admin/planetary/     ← per-view HTML templates
│   └── static/
│       └── planetary/           ← JS for live SQL preview, editors
└── setup.py

Enter fullscreen mode Exit fullscreen mode

Installation:

# settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'planetary',               # adds Planetary section to admin
    ...
]

PLANETARY = {
    'DDL_ROLE': 'platform_ddl',          # elevated role for DDL ops
    'AUDIT_SERVER': 'audit_db_server',   # FDW server name for audit
    'POSTGREST_URL': 'http://localhost:3000',
}

Enter fullscreen mode Exit fullscreen mode


9. The Paradigm in One Sentence

Karen checks the data. Bob secures the database. Senior encodes the rules. Postgres enforces everything. PostgREST exposes it. Next.js renders it. Services handle the side effects. Nobody writes middleware.