Datastore Layer Skill
Layer Number: 08
Specification: Metadata Model Spec v0.7.0
Purpose: Defines physical database design using SQL DDL, specifying databases, tables, columns, indexes, constraints, and triggers.
Layer Overview
The Datastore Layer captures physical database design:
- DATABASES - Database instances and schemas
- TABLES - Database tables with columns
- COLUMNS - Column definitions with types and constraints
- INDEXES - Query optimization indexes (BTREE, HASH, GIN, etc.)
- CONSTRAINTS - PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK, EXCLUSION
- TRIGGERS - Database triggers (BEFORE/AFTER/INSTEAD OF)
- VIEWS - Database views (regular and materialized)
This layer uses SQL DDL concepts with support for PostgreSQL, MySQL, SQLite, and other RDBMS.
Central Entity: The Table (database table) is the core modeling unit.
Entity Types
Core Datastore Entities (10 entities)
| Entity Type |
Description |
| Database |
Database instance with schemas |
| DatabaseSchema |
Logical grouping of tables |
| Table |
Database table with columns and constraints |
| Column |
Table column with data type and constraints |
| Index |
Query optimization index |
| Constraint |
PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK, EXCLUSION |
| Trigger |
Database trigger with timing and events |
| View |
Database view (regular or materialized) |
| Sequence |
Auto-increment sequences |
| Partition |
Table partitioning configuration |
When to Use This Skill
Activate when the user:
- Mentions "database", "table", "SQL", "DDL", "datastore"
- Wants to define tables, columns, indexes, or constraints
- Asks about database design, normalization, or performance
- Needs to model physical storage for data models
- Wants to link database tables to logical data models
Cross-Layer Relationships
Outgoing (Datastore → Other Layers):
x-json-schema → Data Model Layer (what logical schema does this implement?)
x-governed-by-* → Security Layer (data access policies)
x-apm-performance-metrics → APM Layer (query performance monitoring)
Incoming (Other Layers → Datastore):
- Data Model Layer → Datastore (x-database mapping)
- Application Layer → Datastore (database connections)
- Technology Layer → Datastore (hosting infrastructure)
Design Best Practices
- Primary keys - Every table should have a PRIMARY KEY
- Indexes - Add indexes for frequently queried columns
- Foreign keys - Use FOREIGN KEY constraints for referential integrity
- Data types - Choose appropriate data types (e.g., UUID vs INTEGER)
- Normalization - Follow normal forms to reduce redundancy
- PII marking - Use x-pii extension to mark sensitive columns
- Performance - Consider partitioning for large tables
- Encryption - Use x-encrypted for sensitive data at rest
Common Commands
# Add database table
dr add datastore table --name "users" --property schema=public
# Add column to table
dr add datastore column --name "email" --property dataType=VARCHAR
# List tables
dr list datastore table
# Validate datastore layer
dr validate --layer datastore
# Export as SQL DDL
dr export --layer datastore --format sql
Example: Users Table
id: datastore.table.users
name: "Users Table"
type: table
properties:
schema: public
columns:
- id:
dataType: UUID
nullable: false
defaultValue: gen_random_uuid()
- email:
dataType: VARCHAR(255)
nullable: false
x-pii: true
x-encrypted: true
- username:
dataType: VARCHAR(50)
nullable: false
- password_hash:
dataType: VARCHAR(255)
nullable: false
x-encrypted: true
- created_at:
dataType: TIMESTAMP
nullable: false
defaultValue: CURRENT_TIMESTAMP
- last_login:
dataType: TIMESTAMP
nullable: true
constraints:
- type: PRIMARY_KEY
columns: [id]
- type: UNIQUE
columns: [email]
- type: UNIQUE
columns: [username]
indexes:
- name: idx_users_email
columns: [email]
type: BTREE
- name: idx_users_created_at
columns: [created_at]
type: BTREE
x-json-schema: data_model.object-schema.user
x-apm-performance-metrics:
- apm.metric.users-query-latency
Pitfalls to Avoid
- ❌ Missing primary keys
- ❌ Not indexing foreign keys (poor join performance)
- ❌ Using TEXT when VARCHAR(n) is appropriate
- ❌ Not marking PII columns with x-pii extension
- ❌ Missing cross-layer links to data model layer
- ❌ Ignoring database-specific features (e.g., PostgreSQL JSONB)
1---2name: layer-08-datastore3description: Expert knowledge for Datastore Layer modeling in Documentation Robotics4---5
6# Datastore Layer Skill
7
8**Layer Number:** 08
9**Specification:** Metadata Model Spec v0.7.0
10**Purpose:** Defines physical database design using SQL DDL, specifying databases, tables, columns, indexes, constraints, and triggers.
11
12---
13
14## Layer Overview
15
16The Datastore Layer captures **physical database design**:
17
18- **DATABASES** - Database instances and schemas
19- **TABLES** - Database tables with columns
20- **COLUMNS** - Column definitions with types and constraints
21- **INDEXES** - Query optimization indexes (BTREE, HASH, GIN, etc.)
22- **CONSTRAINTS** - PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK, EXCLUSION
23- **TRIGGERS** - Database triggers (BEFORE/AFTER/INSTEAD OF)
24- **VIEWS** - Database views (regular and materialized)
25
26This layer uses **SQL DDL** concepts with support for PostgreSQL, MySQL, SQLite, and other RDBMS.
27
28**Central Entity:** The **Table** (database table) is the core modeling unit.
29
30---
31
32## Entity Types
33
34### Core Datastore Entities (10 entities)
35
36| Entity Type | Description |
37| ------------------ | -------------------------------------------------- |
38| **Database** | Database instance with schemas |
39| **DatabaseSchema** | Logical grouping of tables |
40| **Table** | Database table with columns and constraints |
41| **Column** | Table column with data type and constraints |
42| **Index** | Query optimization index |
43| **Constraint** | PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK, EXCLUSION |
44| **Trigger** | Database trigger with timing and events |
45| **View** | Database view (regular or materialized) |
46| **Sequence** | Auto-increment sequences |
47| **Partition** | Table partitioning configuration |
48
49---
50
51## When to Use This Skill
52
53Activate when the user:
54
55- Mentions "database", "table", "SQL", "DDL", "datastore"
56- Wants to define tables, columns, indexes, or constraints
57- Asks about database design, normalization, or performance
58- Needs to model physical storage for data models
59- Wants to link database tables to logical data models
60
61---
62
63## Cross-Layer Relationships
64
65**Outgoing (Datastore → Other Layers):**
66
67- `x-json-schema` → Data Model Layer (what logical schema does this implement?)
68- `x-governed-by-*` → Security Layer (data access policies)
69- `x-apm-performance-metrics` → APM Layer (query performance monitoring)
70
71**Incoming (Other Layers → Datastore):**
72
73- Data Model Layer → Datastore (x-database mapping)
74- Application Layer → Datastore (database connections)
75- Technology Layer → Datastore (hosting infrastructure)
76
77---
78
79## Design Best Practices
80
811. **Primary keys** - Every table should have a PRIMARY KEY
822. **Indexes** - Add indexes for frequently queried columns
833. **Foreign keys** - Use FOREIGN KEY constraints for referential integrity
844. **Data types** - Choose appropriate data types (e.g., UUID vs INTEGER)
855. **Normalization** - Follow normal forms to reduce redundancy
866. **PII marking** - Use x-pii extension to mark sensitive columns
877. **Performance** - Consider partitioning for large tables
888. **Encryption** - Use x-encrypted for sensitive data at rest
89
90---
91
92## Common Commands
93
94```bash
95# Add database table
96dr add datastore table --name "users" --property schema=public
97
98# Add column to table
99dr add datastore column --name "email" --property dataType=VARCHAR
100
101# List tables
102dr list datastore table
103
104# Validate datastore layer
105dr validate --layer datastore
106
107# Export as SQL DDL
108dr export --layer datastore --format sql
109```
110
111---
112
113## Example: Users Table
114
115```yaml
116id: datastore.table.users
117name: "Users Table"
118type: table
119properties:
120 schema: public
121 columns:
122 - id:
123 dataType: UUID
124 nullable: false
125 defaultValue: gen_random_uuid()
126 - email:
127 dataType: VARCHAR(255)
128 nullable: false
129 x-pii: true
130 x-encrypted: true
131 - username:
132 dataType: VARCHAR(50)
133 nullable: false
134 - password_hash:
135 dataType: VARCHAR(255)
136 nullable: false
137 x-encrypted: true
138 - created_at:
139 dataType: TIMESTAMP
140 nullable: false
141 defaultValue: CURRENT_TIMESTAMP
142 - last_login:
143 dataType: TIMESTAMP
144 nullable: true
145 constraints:
146 - type: PRIMARY_KEY
147 columns: [id]
148 - type: UNIQUE
149 columns: [email]
150 - type: UNIQUE
151 columns: [username]
152 indexes:
153 - name: idx_users_email
154 columns: [email]
155 type: BTREE
156 - name: idx_users_created_at
157 columns: [created_at]
158 type: BTREE
159 x-json-schema: data_model.object-schema.user
160 x-apm-performance-metrics:
161 - apm.metric.users-query-latency
162```
163
164---
165
166## Pitfalls to Avoid
167
168- ❌ Missing primary keys
169- ❌ Not indexing foreign keys (poor join performance)
170- ❌ Using TEXT when VARCHAR(n) is appropriate
171- ❌ Not marking PII columns with x-pii extension
172- ❌ Missing cross-layer links to data model layer
173- ❌ Ignoring database-specific features (e.g., PostgreSQL JSONB)