بنقرة واحدة
data-model
Design database schemas with migrations and repository interfaces
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Design database schemas with migrations and repository interfaces
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | data-model |
| description | Design database schemas with migrations and repository interfaces |
| allowed-tools | Read, Write, Bash, Glob, Grep |
Interactive workflow for designing database schemas, generating migrations, and creating repository interfaces for multi-tenant SaaS applications.
Analyze the feature requirements to identify:
Output: Entity relationship diagram in Mermaid format.
erDiagram
TENANT ||--o{ USER : has
TENANT ||--o{ PROJECT : has
PROJECT ||--o{ TASK : contains
USER }o--o{ PROJECT : "member of"
For each entity, design the table following .claude/rules/data-patterns.md:
Every table MUST include the base entity fields:
id (UUID, primary key)tenant_id (UUID, NOT NULL, foreign key to tenants)created_at (TIMESTAMPTZ, NOT NULL, DEFAULT now())updated_at (TIMESTAMPTZ, NOT NULL, DEFAULT now())deleted_at (TIMESTAMPTZ, nullable for soft delete)created_by (UUID, foreign key to users)updated_by (UUID, foreign key to users)Plus entity-specific columns with proper types, constraints, and defaults.
Output: Complete table definitions with column types and constraints.
For each table, define:
UNIQUE(tenant_id, email))WHERE deleted_at IS NULL)Rules:
CREATE INDEX CONCURRENTLY for large tablesOutput: Index and constraint definitions.
Generate migration files following safe migration patterns:
Up migration (YYYYMMDDHHMMSS_description.up.sql):
BEGIN;
CREATE TABLE IF NOT EXISTS {entity} (
-- columns
);
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_{entity}_{column} ON {entity} ({column});
-- Row Level Security
ALTER TABLE {entity} ENABLE ROW LEVEL SECURITY;
ALTER TABLE {entity} FORCE ROW LEVEL SECURITY;
CREATE POLICY {entity}_tenant_isolation ON {entity}
USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
COMMIT;
Down migration (YYYYMMDDHHMMSS_description.down.sql):
BEGIN;
DROP POLICY IF EXISTS {entity}_tenant_isolation ON {entity};
DROP TABLE IF EXISTS {entity};
COMMIT;
Write migration files to the project's migration directory.
Generate repository interfaces for each aggregate root:
Go:
type {Entity}Repository interface {
FindByID(ctx context.Context, id uuid.UUID) (*{Entity}, error)
List(ctx context.Context, filter {Entity}Filter) (*PagedResult[{Entity}], error)
Create(ctx context.Context, entity *{Entity}) error
Update(ctx context.Context, entity *{Entity}) error
Delete(ctx context.Context, id uuid.UUID) error
}
TypeScript:
interface {Entity}Repository {
findById(id: string): Promise<{Entity} | null>;
list(filter: {Entity}Filter): Promise<PagedResult<{Entity}>>;
create(entity: Create{Entity}Input): Promise<{Entity}>;
update(id: string, entity: Update{Entity}Input): Promise<{Entity}>;
delete(id: string): Promise<void>;
}
Generate in-memory repository implementations for unit testing:
type mem{Entity}Repository struct {
mu sync.RWMutex
entities map[uuid.UUID]*{Entity}
}
func NewMem{Entity}Repository() *mem{Entity}Repository {
return &mem{Entity}Repository{
entities: make(map[uuid.UUID]*{Entity}),
}
}
func (r *mem{Entity}Repository) FindByID(ctx context.Context, id uuid.UUID) (*{Entity}, error) {
r.mu.RLock()
defer r.mu.RUnlock()
tenantID := tenant.FromContext(ctx)
e, ok := r.entities[id]
if !ok || e.TenantID != tenantID || e.DeletedAt != nil {
return nil, ErrNotFound
}
return e, nil
}
For key queries (list with filters, lookups by non-primary-key fields), generate EXPLAIN ANALYZE queries to validate index usage:
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT id, name, email, role, created_at
FROM users
WHERE tenant_id = 'test-uuid'
AND deleted_at IS NULL
AND role = 'admin'
ORDER BY created_at DESC
LIMIT 50;
Check for:
Present the query plans and any index recommendations.
After completing the workflow, the following files should be created:
migrations/YYYYMMDDHHMMSS_description.{up,down}.sqlCreate Architecture Decision Record
Design API contracts with OpenAPI specifications
Assess architecture decisions tradeoffs and edge cases
Break requests into parallel tasks for team execution
Audit dependencies for vulnerabilities and plan upgrades
Structured incident investigation and resolution