writing-database-queries

द्वारा bitwarden

Bitwarden database architecture, migrations, and dual-ORM strategy. Use when working with `.sql` files, stored procedures, EF migrations, or database schema…

npx skills add https://github.com/bitwarden/server --skill writing-database-queries

Dual-ORM Architecture

Bitwarden maintains two data access implementations, split by database provider:

  • MSSQL: Dapper with stored procedures
  • PostgreSQL, MySQL, SQLite: Entity Framework Core

These implementations are mutually exclusive at runtime — SQL Server uses only Dapper, while the other providers use only EF Core. Both implementations conform to the same repository interfaces.

  • When adding new repository functionality, implement it in both Dapper and EF Core (unless the feature is explicitly EF-only).
  • When modifying an existing stored procedure in a backwards-compatible way (for example, adding a new parameter with a default), EF Core changes are not required.
  • Some commercial features (for example, Secrets Manager) are EF Core only.

Evolutionary Database Design (EDD)

Bitwarden Cloud uses a no-rollback approach to database deployments. The key implication: server deployments can be rolled back, but database migrations cannot, so migrations must be designed to avoid being a source of downtime.

All MSSQL migrations live in util/Migrator/DbScripts/ and execute in chronological order based on the migration filename (YYYY-MM-DD_##_Description.sql).

Note: You may see util/Migrator/DbScripts_transition/ and util/Migrator/DbScripts_finalization/ folders. These are not currently used; ignore them for now.

Simple additive changes (new nullable column, new table, new stored procedure) typically require only a single migration script in util/Migrator/DbScripts/.

Stored procedure compatibility

Stored procedure changes fall into two categories:

  • Non-breaking (DEFAULT parameters): Adding a parameter with a default value (e.g., @NewParam BIT = NULL) is backwards-compatible. Existing callers keep working; no _V2 is needed.
  • Breaking (_V2 versioning): Required when result-set structure changes, calling patterns change (e.g., single result → multiple result sets), required parameters are added without defaults, or query semantics differ. Implement this by creating ProcedureName_V2 while retaining the original procedure for backwards compatibility.

Table-level breaking changes (removing columns, changing types) typically cascade into stored procedure changes and often require the _V2 pattern.

Always defer to the developer on migration strategy. The approach is complex and context-dependent. When a database change is needed, write the migration script and ask the developer whether _V2 versioning or additional steps are required.

Key locations

  • src/Sql/dbo — Master schema source of truth
  • util/Migrator/DbScripts — All migrations (single folder, chronological)

ORM-Specific Implementation

When implementing Dapper repository methods, stored procedures, or MSSQL migration scripts, activate the implementing-dapper-queries skill.

When implementing EF Core repositories, generating EF migrations, or working with PostgreSQL/MySQL/SQLite, activate the implementing-ef-core skill.

Critical Rules

These are the most frequently violated conventions. Claude cannot fetch the linked docs at runtime, so these are inlined here:

  • Migration file naming: YYYY-MM-DD_##_Description.sql (e.g., 2025-06-15_00_AddVaultColumn.sql)
  • All schema objects use dbo schema — never create objects in other schemas
  • Constraint naming: PK_TableName (primary key), FK_Child_Parent (foreign key), IX_Table_Column (index), DF_Table_Column (default)
  • Idempotent scripts: Use IF NOT EXISTS / IF COL_LENGTH(...) guards before schema changes in migration scripts
  • New repository functionality requires both Dapper and EF Core implementations — unless the feature is explicitly EF-only or the change is a backwards-compatible stored procedure modification
  • Integration tests use [DatabaseData] attribute — this runs the test against all configured database providers

Further Reading

bitwarden की और Skills

figma-to-angular
bitwarden
यह कौशल Figma डिज़ाइन स्पेक को Bitwarden क्लाइंट्स मोनोरेपो में Storybook स्टोरीज़ के साथ पूरी तरह से लागू किए गए Angular कम्पोनेंट में बदलता है। आउटपुट सभी कोडबेस परंपराओं का पालन करते हुए दृश्य रूप से डिज़ाइन से मेल खाना चाहिए।
force-multiplier
bitwarden
एक ही इरादे को एक साथ कई लक्ष्यों पर लागू करें — Bitwarden पारिस्थितिकी तंत्र में रिपॉजिटरीज़ का एक समूह, या एक मोनोरिपो के भीतर कई प्रोजेक्ट — N सुसंगत,…
analyzing-git-sessions
bitwarden
एक समय सीमा या कमिट रेंज के भीतर गिट कमिट और बदलावों का विश्लेषण करता है, कोड समीक्षा, रेट्रोस्पेक्टिव्स, कार्य लॉग या सत्र के लिए संरचित सारांश प्रदान करता है…
coordinating-cross-team-breakdown
bitwarden
Bitwarden Tech Breakdown के लिए क्रॉस-टीम समीक्षा और स्वीकृति का समन्वय करें। प्रभावित टीमों की पहचान करते समय, भाग 3 की स्वीकृति तालिका बनाते समय, अनुवर्ती कार्रवाई करते समय उपयोग करें…
assessing-jira-issue-relevance
bitwarden
उपयोग तब करें जब उपयोगकर्ता एकल Jira issue key प्रदान करता है और पूछता है कि क्या यह अभी भी प्रासंगिक है, अभी भी लागू है, अभी भी लंबित है, अभी भी बग है, ठीक हो गया है, या…
assessing-test-coverage
bitwarden
किसी विशिष्ट बदलाव (PR, Jira कुंजी, Tech Breakdown दस्तावेज़, Testmo CSV, बदले गए path, या नामित…) के लिए पहले से मौजूद test coverage का निर्धारण करते समय उपयोग करें।
retrospecting
bitwarden
क्लॉड कोड सत्रों का व्यापक विश्लेषण करता है, गिट इतिहास, वार्तालाप लॉग, कोड परिवर्तनों की जांच करता है, और उपयोगकर्ता प्रतिक्रिया एकत्र करके उत्पन्न करता है…
reviewing-incremental-changes
bitwarden
इस कौशल का उपयोग तब करें जब किसी PR की पुनः समीक्षा कर रहे हों जिसमें पहले से टिप्पणियाँ हों या प्रारंभिक समीक्षा के बाद डेवलपर परिवर्तनों का जवाब दे रहे हों। तब लागू करें जब PR थ्रेड मौजूद हों या...