single-database-tenant-isolation

Enforce tenant_id scoping across tenant-related tables in single-database SaaS applications.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/marquesfelip/agents-and-skills --skill single-database-tenant-isolation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: single-database-tenant-isolation
Source: https://github.com/marquesfelip/agents-and-skills/tree/main/skills/single-database-tenant-isolation
Command: npx skills add https://github.com/marquesfelip/agents-and-skills --skill single-database-tenant-isolation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Tenant isolation in a single shared database is challenging; this skill provides patterns and steps to ensure data belonging to one tenant cannot be accessed by another, preventing cross-tenant leakage and performance degradation.

Core Features & Use Cases

  • Audit data model to classify tables as tenant-scoped, platform-level, or cross-tenant data.
  • Add and enforce tenant_id columns, backfill strategies, and not-null constraints with safe migrations.
  • Implement ORM global scopes or repository patterns to automatically filter by tenant_id.
  • Design and enforce leading-column indexes on tenant_id for all tenant-scoped queries.
  • Provide safe cross-tenant access paths for admin or platform operations and corresponding tests.

Quick Start

Audit the current data model, add a NOT NULL tenant_id column to all tenant-scoped tables, and enable automatic tenant filtering in your ORM or data access layer.

Frequently Asked Questions about single-database-tenant-isolation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce tenant isolation in a single shared database?

Enforce tenant isolation in a single shared database by adding a NOT NULL tenant_id column to all tenant-scoped tables and applying ORM global scopes or repository patterns to automatically filter all queries by tenant_id.

What is the best way to prevent cross-tenant data exposure in a multi-tenant SaaS application?

Prevent cross-tenant data exposure by auditing your data model to classify tables as tenant-scoped or platform-level, adding tenant_id constraints with safe backfill migrations, and validating the isolation enforcement through comprehensive integration tests.

Does this multi-tenant isolation approach require database schema changes?

Yes, this approach requires schema changes: you must add tenant_id columns, implement leading-column indexes on tenant_id for all tenant-scoped queries, and apply not-null constraints through safe database migrations to ensure data integrity.

How do I handle safe admin access to cross-tenant data without breaking isolation?

Handle safe admin access by designing specific cross-tenant access paths for platform operations that bypass the automatic tenant_id filtering, ensuring standard tenant queries remain strictly scoped while admins can retrieve global data securely.

Why do I need leading-column indexes on tenant_id for multi-tenant tables?

Leading-column indexes on tenant_id are required to prevent performance degradation in tenant-scoped queries, ensuring the database efficiently filters data per tenant within the shared single-database architecture without scanning unrelated tenant rows.

When should I not use a single-database multi-tenant architecture?

You should reconsider a single-database multi-tenant architecture if your application requires absolute physical data separation between tenants, as this approach relies on logical tenant_id scoping and ORM filtering rather than physical database-level isolation.