database-best-practices

Enforce multi-tenant data isolation in Prisma-powered Shopify apps.

4|1|Updated Nov 23, 2025
One-click install
npx skills add https://github.com/sarojpunde/shopify-dev-toolkit-claude-plugins --skill database-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-best-practices
Source: https://github.com/sarojpunde/shopify-dev-toolkit-claude-plugins/tree/main/shopify-app-development/skills/database-best-practices
Command: npx skills add https://github.com/sarojpunde/shopify-dev-toolkit-claude-plugins --skill database-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides Prisma ORM best practices for Shopify apps, focusing on multi-tenant data isolation, query optimization, transactions, and safe migrations.

Core Features & Use Cases

  • Multi-Tenant Isolation: Always filter by shopId to prevent data leaks.
  • Query Optimization: Select only needed fields, use proper indexes, and batch operations.
  • Migrations & Transactions: Safe migrations and transactional patterns for consistency.

Quick Start

Implement a shop-scoped Product model with indexed fields and an upsert pattern for new/updated products.

Frequently Asked Questions about database-best-practices

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

FAQPage Schema
How do I prevent data leaks between shops in a multi-tenant Prisma database?

Multi-tenant data isolation in Prisma requires always filtering queries by shopId at the schema and query level. Implement indexed shopId fields, enforce filtering in all reads and writes, use transactions for consistency, and validate isolation in migrations to prevent cross-shop data exposure.

What's the best way to structure a Prisma schema for Shopify multi-tenant apps?

Design shop-scoped models with shopId as a required, indexed field. Use composite indexes on shopId plus business keys, implement upsert patterns for idempotent updates, and define explicit relationships that respect tenant boundaries to ensure queries remain shop-isolated.

How do I handle Prisma migrations safely in a production multi-tenant environment?

Safe migrations apply schema changes without downtime or data loss. Use transactional patterns, test migrations on staging data first, avoid breaking changes mid-deployment, and verify shopId filtering remains enforced after each migration to maintain isolation.

Can I use Prisma transactions to prevent N+1 queries and data consistency issues?

Prisma transactions batch multiple operations atomically, preventing partial updates and race conditions. Combine transactions with pagination, select only needed fields, and eager-load related data to eliminate N+1 queries while maintaining multi-tenant isolation.

What are common pitfalls when optimizing Prisma queries in multi-tenant apps?

Forgetting shopId filters, selecting all fields instead of required ones, missing indexes on tenant keys, and running unbatched operations trigger data leaks and slow queries. Always filter by shopId, use pagination, batch bulk operations, and index composite keys for performance and safety.

How do I handle JSON fields and bulk operations safely in Prisma?

JSON fields store nested data without new tables; query them with type-safe filters. Bulk operations batch inserts or updates; wrap them in transactions, maintain shopId filtering on each record, and validate input to prevent injection or isolation breaches.