s9n-devops-agent 2.0.14 → 2.0.18-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,346 @@
1
+ {
2
+ "contract_version": "1.0.0",
3
+ "last_updated": "2024-12-02",
4
+ "updated_by": "DevOps Agent",
5
+ "description": "SQL Contract - Stores all reusable SQL queries, their parameters, and module dependencies. Coding agents MUST check this before writing new SQL to reuse existing queries.",
6
+ "changelog": [
7
+ {
8
+ "date": "2024-12-02",
9
+ "version": "1.0.0",
10
+ "author": "DevOps Agent",
11
+ "changes": "Initial template creation",
12
+ "impact": "N/A - Template only"
13
+ }
14
+ ],
15
+ "queries": {
16
+ "example_get_user_by_email": {
17
+ "id": "example_get_user_by_email",
18
+ "name": "Get User By Email",
19
+ "description": "Retrieves a single user record by email address",
20
+ "created_date": "2024-01-15",
21
+ "last_modified": "2024-01-15",
22
+ "category": "user_management",
23
+ "sql": "SELECT id, email, username, is_active, created_at FROM users WHERE email = $1 AND is_active = true",
24
+ "database": "main",
25
+ "operation_type": "SELECT",
26
+ "parameters": [
27
+ {
28
+ "name": "email",
29
+ "type": "string",
30
+ "required": true,
31
+ "description": "User email address to search for",
32
+ "validation": "Must be valid email format",
33
+ "example": "user@example.com"
34
+ }
35
+ ],
36
+ "returns": {
37
+ "type": "single_row",
38
+ "columns": [
39
+ {
40
+ "name": "id",
41
+ "type": "integer",
42
+ "description": "User ID"
43
+ },
44
+ {
45
+ "name": "email",
46
+ "type": "string",
47
+ "description": "User email"
48
+ },
49
+ {
50
+ "name": "username",
51
+ "type": "string",
52
+ "description": "Username"
53
+ },
54
+ {
55
+ "name": "is_active",
56
+ "type": "boolean",
57
+ "description": "Account active status"
58
+ },
59
+ {
60
+ "name": "created_at",
61
+ "type": "timestamp",
62
+ "description": "Account creation timestamp"
63
+ }
64
+ ]
65
+ },
66
+ "used_by_modules": [
67
+ {
68
+ "module": "auth-service",
69
+ "file": "src/auth/login.js",
70
+ "function": "authenticateUser",
71
+ "usage": "User lookup during login"
72
+ },
73
+ {
74
+ "module": "user-profile-api",
75
+ "file": "src/api/users.js",
76
+ "function": "getUserProfile",
77
+ "usage": "Profile retrieval endpoint"
78
+ }
79
+ ],
80
+ "depends_on_tables": [
81
+ "users"
82
+ ],
83
+ "performance_notes": "Uses idx_users_email index. Average execution time: 2ms",
84
+ "security_notes": "Returns only non-sensitive user data. Password hash excluded.",
85
+ "tags": [
86
+ "user",
87
+ "authentication",
88
+ "lookup"
89
+ ]
90
+ },
91
+ "example_insert_user": {
92
+ "id": "example_insert_user",
93
+ "name": "Insert New User",
94
+ "description": "Creates a new user account with hashed password",
95
+ "created_date": "2024-01-15",
96
+ "last_modified": "2024-01-15",
97
+ "category": "user_management",
98
+ "sql": "INSERT INTO users (email, password_hash, username, is_active) VALUES ($1, $2, $3, $4) RETURNING id, email, username, created_at",
99
+ "database": "main",
100
+ "operation_type": "INSERT",
101
+ "parameters": [
102
+ {
103
+ "name": "email",
104
+ "type": "string",
105
+ "required": true,
106
+ "description": "User email address",
107
+ "validation": "Must be valid email format and unique",
108
+ "example": "newuser@example.com"
109
+ },
110
+ {
111
+ "name": "password_hash",
112
+ "type": "string",
113
+ "required": true,
114
+ "description": "Bcrypt hashed password",
115
+ "validation": "Must be bcrypt hash (60 chars)",
116
+ "example": "$2b$10$..."
117
+ },
118
+ {
119
+ "name": "username",
120
+ "type": "string",
121
+ "required": true,
122
+ "description": "Unique username",
123
+ "validation": "3-100 characters, alphanumeric + underscore",
124
+ "example": "john_doe"
125
+ },
126
+ {
127
+ "name": "is_active",
128
+ "type": "boolean",
129
+ "required": false,
130
+ "description": "Initial account status",
131
+ "validation": "Boolean value",
132
+ "example": true
133
+ }
134
+ ],
135
+ "returns": {
136
+ "type": "single_row",
137
+ "columns": [
138
+ {
139
+ "name": "id",
140
+ "type": "integer",
141
+ "description": "Newly created user ID"
142
+ },
143
+ {
144
+ "name": "email",
145
+ "type": "string",
146
+ "description": "User email"
147
+ },
148
+ {
149
+ "name": "username",
150
+ "type": "string",
151
+ "description": "Username"
152
+ },
153
+ {
154
+ "name": "created_at",
155
+ "type": "timestamp",
156
+ "description": "Account creation timestamp"
157
+ }
158
+ ]
159
+ },
160
+ "used_by_modules": [
161
+ {
162
+ "module": "auth-service",
163
+ "file": "src/auth/register.js",
164
+ "function": "registerUser",
165
+ "usage": "User registration endpoint"
166
+ }
167
+ ],
168
+ "depends_on_tables": [
169
+ "users"
170
+ ],
171
+ "performance_notes": "Triggers index updates on email and username. Average execution time: 5ms",
172
+ "security_notes": "CRITICAL: Password must be hashed before calling this query. Never pass plain text passwords.",
173
+ "error_handling": [
174
+ {
175
+ "error_code": "23505",
176
+ "description": "Unique constraint violation (duplicate email or username)",
177
+ "handling": "Return user-friendly error message"
178
+ }
179
+ ],
180
+ "tags": [
181
+ "user",
182
+ "registration",
183
+ "insert"
184
+ ]
185
+ }
186
+ },
187
+ "query_categories": {
188
+ "user_management": {
189
+ "description": "Queries related to user CRUD operations",
190
+ "queries": [
191
+ "example_get_user_by_email",
192
+ "example_insert_user"
193
+ ]
194
+ },
195
+ "authentication": {
196
+ "description": "Queries for authentication and authorization",
197
+ "queries": [
198
+ "example_get_user_by_email"
199
+ ]
200
+ }
201
+ },
202
+ "usage_instructions": {
203
+ "for_coding_agents": [
204
+ "ALWAYS search this contract before writing new SQL queries",
205
+ "REUSE existing queries whenever possible - do not duplicate SQL",
206
+ "If a query is similar but not exact, consider parameterizing the existing query",
207
+ "When adding new queries, follow the exact JSON schema structure",
208
+ "Update 'used_by_modules' array when reusing a query in a new module",
209
+ "Increment contract_version (patch for additions, minor for modifications)",
210
+ "Add entry to changelog with date, version, author, changes, and impact",
211
+ "Cross-reference DATABASE_SCHEMA_CONTRACT.md for table structures",
212
+ "Use parameterized queries ($1, $2, etc.) to prevent SQL injection",
213
+ "Document performance characteristics and index usage",
214
+ "Include security notes for sensitive operations",
215
+ "Tag queries appropriately for easy searching"
216
+ ],
217
+ "before_writing_new_sql": [
218
+ "1. Search this contract by category and tags",
219
+ "2. Check if similar query exists that can be reused",
220
+ "3. If exact match found, use it and add your module to 'used_by_modules'",
221
+ "4. If similar query found, consider adding parameters to make it reusable",
222
+ "5. If no match, create new query following the template structure",
223
+ "6. Document all parameters, return values, and dependencies",
224
+ "7. Add security and performance notes",
225
+ "8. Update changelog and version number"
226
+ ],
227
+ "query_naming_convention": {
228
+ "pattern": "{operation}_{entity}_{by_condition}",
229
+ "examples": [
230
+ "get_user_by_email",
231
+ "get_user_by_id",
232
+ "insert_user",
233
+ "update_user_password",
234
+ "delete_user_by_id",
235
+ "list_active_users",
236
+ "count_users_by_status"
237
+ ]
238
+ },
239
+ "search_tips": [
240
+ "Search by category for related queries",
241
+ "Search by tags for functional grouping",
242
+ "Search by table name in 'depends_on_tables'",
243
+ "Search by module name in 'used_by_modules'",
244
+ "Use operation_type to filter SELECT/INSERT/UPDATE/DELETE"
245
+ ]
246
+ },
247
+ "template_for_new_query": {
248
+ "id": "unique_query_identifier",
249
+ "name": "Human Readable Query Name",
250
+ "description": "Detailed description of what this query does",
251
+ "created_date": "YYYY-MM-DD",
252
+ "last_modified": "YYYY-MM-DD",
253
+ "category": "category_name",
254
+ "sql": "SELECT ... FROM ... WHERE ...",
255
+ "database": "database_name",
256
+ "operation_type": "SELECT|INSERT|UPDATE|DELETE",
257
+ "parameters": [
258
+ {
259
+ "name": "param_name",
260
+ "type": "string|integer|boolean|timestamp|json",
261
+ "required": true,
262
+ "description": "Parameter description",
263
+ "validation": "Validation rules",
264
+ "example": "example_value"
265
+ }
266
+ ],
267
+ "returns": {
268
+ "type": "single_row|multiple_rows|affected_count|void",
269
+ "columns": [
270
+ {
271
+ "name": "column_name",
272
+ "type": "data_type",
273
+ "description": "Column description"
274
+ }
275
+ ]
276
+ },
277
+ "used_by_modules": [
278
+ {
279
+ "module": "module_name",
280
+ "file": "relative/path/to/file.js",
281
+ "function": "functionName",
282
+ "usage": "How this query is used"
283
+ }
284
+ ],
285
+ "depends_on_tables": [
286
+ "table1",
287
+ "table2"
288
+ ],
289
+ "performance_notes": "Index usage, execution time, optimization notes",
290
+ "security_notes": "Security considerations, data sensitivity, access control",
291
+ "error_handling": [
292
+ {
293
+ "error_code": "code",
294
+ "description": "Error description",
295
+ "handling": "How to handle this error"
296
+ }
297
+ ],
298
+ "tags": [
299
+ "tag1",
300
+ "tag2"
301
+ ]
302
+ },
303
+ "initial_population_instructions": {
304
+ "for_devops_agent": [
305
+ "1. Scan entire codebase for SQL queries using patterns:",
306
+ " - Raw SQL strings: SELECT, INSERT, UPDATE, DELETE",
307
+ " - ORM query builders: .query(), .find(), .where()",
308
+ " - Database client calls: db.query(), pool.query(), connection.execute()",
309
+ "2. Extract each unique SQL query",
310
+ "3. Identify parameters (?, $1, :param, etc.)",
311
+ "4. Find all files/modules that use each query",
312
+ "5. Document return types by analyzing code usage",
313
+ "6. Add performance and security notes based on query complexity",
314
+ "7. Categorize queries by domain (user, product, order, etc.)",
315
+ "8. Tag queries for easy searching",
316
+ "9. Cross-reference with DATABASE_SCHEMA_CONTRACT.md for table info"
317
+ ],
318
+ "search_patterns": [
319
+ "*.sql files in the repository",
320
+ "db.query(, pool.query(, connection.execute(",
321
+ "SELECT, INSERT, UPDATE, DELETE (case insensitive)",
322
+ "ORM methods: .find(, .findOne(, .create(, .update(, .delete(",
323
+ "Raw SQL in template literals: sql`...`",
324
+ "Query builder chains: .select().from().where()"
325
+ ],
326
+ "file_locations_to_check": [
327
+ "src/**/repositories/**",
328
+ "src/**/models/**",
329
+ "src/**/services/**",
330
+ "src/**/api/**",
331
+ "database/queries/**",
332
+ "db/**/*.sql",
333
+ "migrations/**"
334
+ ]
335
+ },
336
+ "benefits": {
337
+ "code_reuse": "Avoid duplicating SQL queries across modules",
338
+ "consistency": "Ensure all modules use the same optimized queries",
339
+ "maintenance": "Update query in one place, all modules benefit",
340
+ "documentation": "Self-documenting SQL with parameters and usage",
341
+ "onboarding": "New developers can discover existing queries easily",
342
+ "refactoring": "Know exactly which modules are affected by query changes",
343
+ "performance": "Track and optimize frequently used queries",
344
+ "security": "Centralized review of SQL for injection vulnerabilities"
345
+ }
346
+ }