Schema separation orm control

From CarlosCaPe/octorato · View interactive version

Schema separation orm control is an AI agent skill from the GitHub repository CarlosCaPe/octorato. Schema Separation for ORM/Scaffolding Control

How to use this skill

Skill file

Schema Separation for ORM/Scaffolding Control

What

Moving internal database objects (partition children, helper tables, maintenance

artifacts) into a separate schema so that ORM tools (Entity Framework, Npgsql,

Prisma) only scaffold the intended application tables.

Why

ORMs like Entity Framework discover tables via information_schema.tables. If

partition children (e.g., AppointmentInfo_2024, AppointmentInfo_2025) live in

the public schema alongside the parent table, EF will scaffold them as

separate entities -- creating confusion, compilation errors, and bloated models.

Moving them to a partitions schema removes them from the ORM's discovery path

while keeping them fully functional (PostgreSQL resolves partition routing

regardless of schema).

How

Step 1: Create the target schema

CREATE SCHEMA IF NOT EXISTS partitions;

Step 2: Move the partition children

ALTER TABLE public."AppointmentInfo_2024"
    SET SCHEMA partitions;

ALTER TABLE public."AppointmentInfo_2025"
    SET SCHEMA partitions;

Step 3: Verify partition routing still works

-- Insert should still route to the correct partition
INSERT INTO public."AppointmentInfo" ("CreatedDate", ...)
VALUES ('2025-06-15', ...);

-- Query should still find data across all partitions
SELECT * FROM public."AppointmentInfo"
WHERE "CreatedDate" >= '2025-01-01';

Step 4: Update EF scaffolding command

# Scaffold only public schema
dotnet ef dbcontext scaffold ... --schema public

Schema Candidates

| Object Type | Move To | Reason |

|---|---|---|

| Partition children | partitions | Hide from ORM discovery |

| Maintenance procedures | maintenance | Separate ops from app code |

| Monitoring views | monitoring | Separate observability layer |

| Audit triggers/functions | audit | Clean separation of concerns |

When to Use

Where We Used It

so EF/Npgsql scaffolding only discovers parent tables

References

-- see Audit Finding #8 (Everything in public schema) and

"Database naming conventions" (Schemas section)

Gotchas


Category: Strategy | Origin:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.