bel-crm-schema-write-db

Generate PostgreSQL SQL queries for CRM schema operations with JSONB fields.

2|Updated Oct 22, 2025
One-click install
npx skills add https://github.com/bennoloeffler/bassi --skill bel-crm-schema-write-db
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bel-crm-schema-write-db
Source: https://github.com/bennoloeffler/bassi/tree/main/.claude/skills/bel-crm-schema-write-db
Command: npx skills add https://github.com/bennoloeffler/bassi --skill bel-crm-schema-write-db

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides schema knowledge and concrete PostgreSQL patterns to manage CRM data safely and efficiently.

Core Features & Use Cases

  • Schema Knowledge: understand tables and relationships (company_site, person, sales_opportunity, event).
  • SQL Examples: insert, update, and select patterns tailored to CRM data.
  • JSONB Guidance: query and modify JSONB fields within CRM entities.

Quick Start

Start with bel-crm-sql-rules, then apply CRM-specific insert/update/select patterns.

Frequently Asked Questions about bel-crm-schema-write-db

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

FAQPage Schema
How do I write PostgreSQL INSERT queries for a CRM database with JSONB fields?

PostgreSQL INSERT queries for CRM data require understanding the schema tables (company_site, person, sales_opportunity, event) and their relationships. Build two-step inserts: execute the INSERT, then retrieve the generated ID separately since RETURNING is not used. Handle JSONB fields for tags and metadata using PostgreSQL JSONB syntax, and validate foreign keys before insert to maintain referential integrity.

What's the best way to query JSONB columns in PostgreSQL for CRM tags and metadata?

PostgreSQL JSONB fields in CRM entities support operators like @>, ->, and ->> for querying and filtering. Use @> for containment checks on tags, -> to extract nested objects, and ->> to get text values. Combine JSONB operators with standard SQL WHERE clauses to build reports and pipeline analysis across company_site, person, sales_opportunity, and event tables.

How do I join CRM tables in PostgreSQL and handle foreign key constraints?

CRM schema joins connect company_site, person, sales_opportunity, and event through foreign keys. Write JOIN statements that match these relationships, validate foreign key references before INSERT or UPDATE operations, and use SELECT with joins to build pipeline reports and analysis. Enforce data type consistency across joined tables.

Can I use ON CONFLICT in PostgreSQL CRM queries, and what are the constraints?

ON CONFLICT is not used in this CRM schema approach. Instead, validate uniqueness before INSERT or UPDATE operations, handle conflicts through application logic, and use two-step ID retrieval after successful inserts. This constraint ensures predictable, explicit conflict handling in CRM data operations.

What UPDATE patterns work for modifying CRM records in PostgreSQL?

UPDATE queries for CRM data modify company_site, person, sales_opportunity, and event records by targeting specific rows with WHERE clauses. Update JSONB fields using || (merge) or assignment operators, validate foreign keys remain intact, avoid RETURNING clauses, and verify data types match schema definitions before commit.

When should I use PostgreSQL for CRM data instead of other SQL databases?

PostgreSQL offers JSONB for flexible tag and metadata storage, strong foreign key enforcement for CRM relationships, and native operators for complex queries. Choose PostgreSQL when your CRM needs schema validation, structured relationships across entities, and the ability to query semi-structured data within relational tables.