proagents 1.6.20 → 1.6.21

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.
Files changed (121) hide show
  1. package/.proagents/custom-commands.yaml +0 -1
  2. package/.proagents/docs/command-details.md +1 -2
  3. package/.proagents/getting-started/ai-training-setup.md +0 -1
  4. package/.proagents/performance/README.md +59 -0
  5. package/.proagents/performance/bundle-analysis.md +375 -0
  6. package/.proagents/performance/load-testing.md +563 -0
  7. package/.proagents/performance/runtime-metrics.md +489 -0
  8. package/.proagents/performance/web-vitals.md +425 -0
  9. package/.proagents/proagents.config.yaml +0 -1
  10. package/.proagents/workflow-modes/entry-modes.md +1 -6
  11. package/lib/commands/init.js +57 -8
  12. package/package.json +1 -1
  13. package/.proagents/api-versioning/README.md +0 -257
  14. package/.proagents/api-versioning/changelog-template.md +0 -225
  15. package/.proagents/api-versioning/deprecation-workflow.md +0 -470
  16. package/.proagents/api-versioning/versioning-strategy.md +0 -291
  17. package/.proagents/automation/README.md +0 -38
  18. package/.proagents/automation/ai-behavior-rules.md +0 -339
  19. package/.proagents/automation/ai-prompt-injection.md +0 -331
  20. package/.proagents/automation/auto-decisions.md +0 -535
  21. package/.proagents/automation/decision-defaults.yaml +0 -317
  22. package/.proagents/cache/README.md +0 -110
  23. package/.proagents/cache/analysis-metadata.json +0 -76
  24. package/.proagents/cache/conventions.json +0 -125
  25. package/.proagents/cache/dependencies.json +0 -85
  26. package/.proagents/cache/features.json +0 -115
  27. package/.proagents/cache/patterns.json +0 -105
  28. package/.proagents/cache/schemas/conventions-schema.json +0 -138
  29. package/.proagents/cache/schemas/dependencies-schema.json +0 -95
  30. package/.proagents/cache/schemas/features-schema.json +0 -104
  31. package/.proagents/cache/schemas/metadata-schema.json +0 -83
  32. package/.proagents/cache/schemas/patterns-schema.json +0 -136
  33. package/.proagents/cache/schemas/structure-schema.json +0 -72
  34. package/.proagents/cache/structure.json +0 -109
  35. package/.proagents/checklists/README.md +0 -261
  36. package/.proagents/checklists/code-quality.md +0 -137
  37. package/.proagents/checklists/code-review.md +0 -148
  38. package/.proagents/checklists/pr-checklist.md +0 -78
  39. package/.proagents/checklists/pre-deployment.md +0 -132
  40. package/.proagents/checklists/pre-implementation.md +0 -80
  41. package/.proagents/checklists/testing.md +0 -120
  42. package/.proagents/checkpoints.json +0 -13
  43. package/.proagents/cicd/README.md +0 -338
  44. package/.proagents/cicd/azure-devops.md +0 -267
  45. package/.proagents/cicd/github-actions.md +0 -375
  46. package/.proagents/cicd/gitlab-ci.md +0 -278
  47. package/.proagents/cicd/jenkins.md +0 -317
  48. package/.proagents/collaboration/README.md +0 -143
  49. package/.proagents/collaboration/roles.md +0 -248
  50. package/.proagents/collaboration/sessions.md +0 -390
  51. package/.proagents/collaboration/sync.md +0 -358
  52. package/.proagents/cost/README.md +0 -48
  53. package/.proagents/cost/cost-template.md +0 -283
  54. package/.proagents/cost/estimation-framework.md +0 -287
  55. package/.proagents/database/README.md +0 -72
  56. package/.proagents/database/examples/001-create-users.sql +0 -129
  57. package/.proagents/database/examples/002-add-preferences.sql +0 -94
  58. package/.proagents/database/examples/003-add-index.sql +0 -105
  59. package/.proagents/database/examples/004-rename-column.sql +0 -122
  60. package/.proagents/database/examples/005-add-foreign-key.sql +0 -142
  61. package/.proagents/database/examples/006-data-migration.sql +0 -196
  62. package/.proagents/database/examples/007-drop-column.sql +0 -163
  63. package/.proagents/database/examples/README.md +0 -89
  64. package/.proagents/database/migration-workflow.md +0 -478
  65. package/.proagents/database/rollback-scripts.md +0 -487
  66. package/.proagents/database/safety-checks.md +0 -447
  67. package/.proagents/git/README.md +0 -68
  68. package/.proagents/git/branch-strategy.md +0 -164
  69. package/.proagents/git/commit-conventions.md +0 -241
  70. package/.proagents/git/pr-workflow.md +0 -286
  71. package/.proagents/git/rollback-procedures.md +0 -416
  72. package/.proagents/ide-integration/README.md +0 -124
  73. package/.proagents/ide-integration/cline-config.md +0 -429
  74. package/.proagents/ide-integration/continue-config.md +0 -380
  75. package/.proagents/ide-integration/cursor-rules.md +0 -280
  76. package/.proagents/ide-integration/github-copilot.md +0 -384
  77. package/.proagents/ide-integration/windsurf-rules.md +0 -314
  78. package/.proagents/integrations/README.md +0 -97
  79. package/.proagents/integrations/pm/README.md +0 -344
  80. package/.proagents/learning/README.md +0 -136
  81. package/.proagents/learning/adaptation.md +0 -305
  82. package/.proagents/learning/data-collection.md +0 -283
  83. package/.proagents/learning/implementation-guide.md +0 -865
  84. package/.proagents/learning/reports.md +0 -306
  85. package/.proagents/mcp/README.md +0 -133
  86. package/.proagents/mcp/context-providers.md +0 -442
  87. package/.proagents/mcp/server-config.md +0 -306
  88. package/.proagents/mcp/tools-definition.md +0 -513
  89. package/.proagents/pm-integration/README.md +0 -151
  90. package/.proagents/pm-integration/asana.md +0 -346
  91. package/.proagents/pm-integration/github-issues.md +0 -308
  92. package/.proagents/pm-integration/gitlab-issues.md +0 -482
  93. package/.proagents/pm-integration/jira.md +0 -364
  94. package/.proagents/pm-integration/linear.md +0 -409
  95. package/.proagents/pm-integration/notion.md +0 -275
  96. package/.proagents/pm-integration/sync-config.md +0 -533
  97. package/.proagents/pm-integration/trello.md +0 -159
  98. package/.proagents/rules/README.md +0 -179
  99. package/.proagents/rules/custom-rules-template.yaml +0 -286
  100. package/.proagents/rules/custom-rules.md +0 -754
  101. package/.proagents/rules/validation-rules-template.yaml +0 -517
  102. package/.proagents/runbooks/README.md +0 -219
  103. package/.proagents/runbooks/dependency-vulnerability.md +0 -505
  104. package/.proagents/runbooks/incident-response.md +0 -451
  105. package/.proagents/runbooks/performance-degradation.md +0 -584
  106. package/.proagents/runbooks/production-debugging.md +0 -489
  107. package/.proagents/sprints/README.md +0 -58
  108. package/.proagents/team/README.md +0 -256
  109. package/.proagents/team/code-ownership.md +0 -306
  110. package/.proagents/team/communication-templates.md +0 -441
  111. package/.proagents/team/handoff-protocol.md +0 -380
  112. package/.proagents/team/ide-setup/README.md +0 -103
  113. package/.proagents/team/ide-setup/cursor.md +0 -276
  114. package/.proagents/team/ide-setup/jetbrains.md +0 -330
  115. package/.proagents/team/ide-setup/neovim.md +0 -640
  116. package/.proagents/team/ide-setup/vscode.md +0 -348
  117. package/.proagents/team/onboarding.md +0 -278
  118. package/.proagents/time-tracking.json +0 -19
  119. package/.proagents/troubleshooting/README.md +0 -730
  120. package/.proagents/troubleshooting/ai-issues.md +0 -601
  121. package/.proagents/troubleshooting/workflow-issues.md +0 -571
@@ -1,287 +0,0 @@
1
- # Cost Estimation Framework
2
-
3
- Estimate infrastructure and operational costs for new features.
4
-
5
- ---
6
-
7
- ## Cost Categories
8
-
9
- ### 1. Compute Costs
10
-
11
- **Serverless Functions:**
12
- ```yaml
13
- compute:
14
- serverless:
15
- provider: "aws_lambda" # aws_lambda | vercel | cloudflare_workers
16
-
17
- estimate:
18
- invocations_per_month: 1000000
19
- avg_duration_ms: 200
20
- memory_mb: 256
21
-
22
- calculation:
23
- # AWS Lambda pricing (example)
24
- request_cost: "$0.20 per 1M requests"
25
- duration_cost: "$0.0000166667 per GB-second"
26
-
27
- monthly_estimate:
28
- requests: "$0.20"
29
- duration: "$0.83" # 1M × 0.2s × 0.25GB × $0.0000166667
30
- total: "$1.03"
31
- ```
32
-
33
- **Container/Server:**
34
- ```yaml
35
- compute:
36
- containers:
37
- provider: "aws_ecs" # aws_ecs | gcp_cloud_run | azure_container
38
-
39
- estimate:
40
- instances: 2
41
- vcpu: 0.5
42
- memory_gb: 1
43
- hours_per_month: 730
44
-
45
- monthly_estimate: "$30"
46
- ```
47
-
48
- ---
49
-
50
- ### 2. Storage Costs
51
-
52
- **Database:**
53
- ```yaml
54
- storage:
55
- database:
56
- provider: "aws_rds" # aws_rds | planetscale | supabase
57
-
58
- estimate:
59
- storage_gb: 20
60
- iops: 1000
61
- backup_retention_days: 7
62
-
63
- monthly_estimate:
64
- storage: "$2.30"
65
- iops: "$10.00"
66
- backup: "$1.00"
67
- total: "$13.30"
68
- ```
69
-
70
- **File Storage:**
71
- ```yaml
72
- storage:
73
- files:
74
- provider: "aws_s3" # aws_s3 | cloudflare_r2 | gcp_storage
75
-
76
- estimate:
77
- storage_gb: 100
78
- requests_per_month: 100000
79
- bandwidth_gb: 50
80
-
81
- monthly_estimate:
82
- storage: "$2.30"
83
- requests: "$0.04"
84
- bandwidth: "$4.50"
85
- total: "$6.84"
86
- ```
87
-
88
- ---
89
-
90
- ### 3. Network Costs
91
-
92
- ```yaml
93
- network:
94
- cdn:
95
- provider: "cloudflare" # cloudflare | aws_cloudfront | vercel
96
-
97
- estimate:
98
- bandwidth_gb: 100
99
- requests_per_month: 10000000
100
-
101
- monthly_estimate:
102
- cloudflare_free: "$0"
103
- cloudflare_pro: "$20"
104
- aws_cloudfront: "$8.50"
105
-
106
- api_gateway:
107
- provider: "aws_api_gateway"
108
-
109
- estimate:
110
- requests_per_month: 1000000
111
-
112
- monthly_estimate: "$3.50"
113
- ```
114
-
115
- ---
116
-
117
- ### 4. Third-Party Services
118
-
119
- ```yaml
120
- third_party:
121
- auth:
122
- provider: "auth0"
123
- estimate:
124
- monthly_active_users: 1000
125
- monthly_estimate: "$0 (free tier)" # Up to 7000 MAU
126
-
127
- email:
128
- provider: "sendgrid"
129
- estimate:
130
- emails_per_month: 10000
131
- monthly_estimate: "$0 (free tier)" # Up to 100/day
132
-
133
- monitoring:
134
- provider: "datadog"
135
- estimate:
136
- hosts: 2
137
- custom_metrics: 100
138
- monthly_estimate: "$30"
139
-
140
- search:
141
- provider: "algolia"
142
- estimate:
143
- records: 10000
144
- searches_per_month: 100000
145
- monthly_estimate: "$0 (free tier)"
146
- ```
147
-
148
- ---
149
-
150
- ## Cost Estimation Template
151
-
152
- ```markdown
153
- # Feature Cost Estimate
154
-
155
- ## Feature: [Feature Name]
156
- ## Date: [YYYY-MM-DD]
157
- ## Estimated By: [Name]
158
-
159
- ---
160
-
161
- ## Summary
162
-
163
- | Category | Monthly Cost | Annual Cost |
164
- |----------|-------------|-------------|
165
- | Compute | $XX | $XXX |
166
- | Storage | $XX | $XXX |
167
- | Network | $XX | $XXX |
168
- | Third-party | $XX | $XXX |
169
- | **Total** | **$XX** | **$XXX** |
170
-
171
- ---
172
-
173
- ## Detailed Breakdown
174
-
175
- ### Compute
176
- | Resource | Specs | Cost |
177
- |----------|-------|------|
178
- | Lambda functions | 1M invocations, 256MB | $1.03 |
179
- | ECS containers | 2 × 0.5 vCPU | $30.00 |
180
- | **Subtotal** | | **$31.03** |
181
-
182
- ### Storage
183
- | Resource | Specs | Cost |
184
- |----------|-------|------|
185
- | RDS PostgreSQL | 20GB, db.t3.micro | $13.30 |
186
- | S3 bucket | 100GB, standard | $6.84 |
187
- | **Subtotal** | | **$20.14** |
188
-
189
- ### Network
190
- | Resource | Specs | Cost |
191
- |----------|-------|------|
192
- | CloudFront | 100GB bandwidth | $8.50 |
193
- | API Gateway | 1M requests | $3.50 |
194
- | **Subtotal** | | **$12.00** |
195
-
196
- ### Third-Party Services
197
- | Service | Tier | Cost |
198
- |---------|------|------|
199
- | Auth0 | Free | $0 |
200
- | SendGrid | Free | $0 |
201
- | Datadog | Pro | $30 |
202
- | **Subtotal** | | **$30.00** |
203
-
204
- ---
205
-
206
- ## Assumptions
207
- - Traffic estimates based on [source]
208
- - Growth rate: [X]% monthly
209
- - Peak traffic: [X]× average
210
-
211
- ## Scaling Projections
212
-
213
- | Users | Monthly Cost |
214
- |-------|-------------|
215
- | 1,000 | $93 |
216
- | 10,000 | $250 |
217
- | 100,000 | $1,200 |
218
-
219
- ## Cost Optimization Recommendations
220
- 1. Use reserved instances for predictable workloads
221
- 2. Implement caching to reduce database calls
222
- 3. Use CDN for static assets
223
- ```
224
-
225
- ---
226
-
227
- ## Approval Thresholds
228
-
229
- ```yaml
230
- cost_approval:
231
- thresholds:
232
- - range: "$0-100"
233
- approver: "auto_approved"
234
-
235
- - range: "$100-500"
236
- approver: "tech_lead"
237
- requires: "cost_estimate_doc"
238
-
239
- - range: "$500-2000"
240
- approver: "engineering_manager"
241
- requires:
242
- - "cost_estimate_doc"
243
- - "scaling_projections"
244
-
245
- - range: "$2000+"
246
- approver: "director"
247
- requires:
248
- - "cost_estimate_doc"
249
- - "scaling_projections"
250
- - "roi_analysis"
251
- ```
252
-
253
- ---
254
-
255
- ## Cost Monitoring
256
-
257
- ```yaml
258
- monitoring:
259
- alerts:
260
- - threshold: "80% of budget"
261
- action: "notify"
262
- recipients: ["team-lead"]
263
-
264
- - threshold: "100% of budget"
265
- action: "notify_urgent"
266
- recipients: ["team-lead", "manager"]
267
-
268
- - threshold: "120% of budget"
269
- action: "auto_scale_down"
270
- notify: ["all"]
271
-
272
- reports:
273
- daily: true
274
- weekly_summary: true
275
- monthly_detailed: true
276
- ```
277
-
278
- ---
279
-
280
- ## Commands
281
-
282
- | Command | Description |
283
- |---------|-------------|
284
- | `pa:cost-estimate` | Generate cost estimate for feature |
285
- | `pa:cost-compare` | Compare costs across providers |
286
- | `pa:cost-report` | View current costs |
287
- | `pa:cost-optimize` | Get optimization suggestions |
@@ -1,72 +0,0 @@
1
- # Database Management
2
-
3
- Schema migrations, safety checks, and rollback procedures.
4
-
5
- ---
6
-
7
- ## Overview
8
-
9
- Safe database changes with version control, validation, and rollback capabilities.
10
-
11
- ## Documentation
12
-
13
- | Document | Description |
14
- |----------|-------------|
15
- | [Migration Workflow](./migration-workflow.md) | Creating and running migrations |
16
- | [Safety Checks](./safety-checks.md) | Pre-migration validation |
17
- | [Rollback Scripts](./rollback-scripts.md) | Reverting database changes |
18
- | [Examples](./examples/) | Concrete migration examples |
19
-
20
- ## Examples
21
-
22
- Ready-to-use migration templates:
23
-
24
- | Example | Description | Risk |
25
- |---------|-------------|------|
26
- | [001-create-users](./examples/001-create-users.sql) | Create table with indexes | Low |
27
- | [002-add-preferences](./examples/002-add-preferences.sql) | Add JSONB column | Low |
28
- | [003-add-index](./examples/003-add-index.sql) | Add performance index | Medium |
29
- | [004-rename-column](./examples/004-rename-column.sql) | Rename column safely | Medium |
30
- | [005-add-foreign-key](./examples/005-add-foreign-key.sql) | Add relationships | Medium |
31
- | [006-data-migration](./examples/006-data-migration.sql) | Transform data | High |
32
- | [007-drop-column](./examples/007-drop-column.sql) | Remove column | High |
33
-
34
- ## Quick Start
35
-
36
- ```bash
37
- # Create a new migration
38
- proagents db migration create "add_user_preferences"
39
-
40
- # Run pending migrations
41
- proagents db migrate
42
-
43
- # Rollback last migration
44
- proagents db rollback
45
-
46
- # Check migration status
47
- proagents db status
48
- ```
49
-
50
- ## Safety Features
51
-
52
- - **Dry Run**: Preview changes before applying
53
- - **Backup**: Automatic backup before migrations
54
- - **Validation**: Check for breaking changes
55
- - **Rollback Scripts**: Every migration has a rollback
56
-
57
- ## Configuration
58
-
59
- ```yaml
60
- # proagents.config.yaml
61
- database:
62
- migrations:
63
- directory: "./migrations"
64
- backup_before: true
65
- require_rollback: true
66
-
67
- safety:
68
- block_destructive: true
69
- require_approval_for:
70
- - "drop_table"
71
- - "drop_column"
72
- ```
@@ -1,129 +0,0 @@
1
- -- Migration: Create users table
2
- -- Author: ProAgents
3
- -- Date: 2024-01-15
4
- -- Risk Level: Low
5
- -- Requires Approval: No
6
- -- Estimated Duration: < 1 second
7
-
8
- -- Description:
9
- -- Creates the core users table with essential fields for authentication
10
- -- and profile information. This is typically one of the first migrations
11
- -- in a new project.
12
-
13
- -- ============================================
14
- -- UP MIGRATION
15
- -- ============================================
16
-
17
- -- Create enum for user status
18
- CREATE TYPE user_status AS ENUM ('active', 'inactive', 'suspended', 'pending');
19
-
20
- -- Create enum for user role
21
- CREATE TYPE user_role AS ENUM ('admin', 'developer', 'viewer', 'guest');
22
-
23
- -- Create users table
24
- CREATE TABLE users (
25
- -- Primary key
26
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
27
-
28
- -- Authentication fields
29
- email VARCHAR(255) NOT NULL,
30
- password_hash VARCHAR(255) NOT NULL,
31
-
32
- -- Profile fields
33
- first_name VARCHAR(100),
34
- last_name VARCHAR(100),
35
- display_name VARCHAR(100),
36
- avatar_url TEXT,
37
-
38
- -- Status and role
39
- status user_status NOT NULL DEFAULT 'pending',
40
- role user_role NOT NULL DEFAULT 'viewer',
41
-
42
- -- Email verification
43
- email_verified BOOLEAN NOT NULL DEFAULT FALSE,
44
- email_verified_at TIMESTAMP WITH TIME ZONE,
45
-
46
- -- Timestamps
47
- created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
48
- updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
49
- last_login_at TIMESTAMP WITH TIME ZONE,
50
-
51
- -- Soft delete
52
- deleted_at TIMESTAMP WITH TIME ZONE
53
- );
54
-
55
- -- Create unique index on email (excluding soft-deleted users)
56
- CREATE UNIQUE INDEX idx_users_email_unique
57
- ON users (email)
58
- WHERE deleted_at IS NULL;
59
-
60
- -- Create index for common queries
61
- CREATE INDEX idx_users_status ON users (status) WHERE deleted_at IS NULL;
62
- CREATE INDEX idx_users_role ON users (role) WHERE deleted_at IS NULL;
63
- CREATE INDEX idx_users_created_at ON users (created_at);
64
-
65
- -- Create updated_at trigger function (reusable)
66
- CREATE OR REPLACE FUNCTION update_updated_at_column()
67
- RETURNS TRIGGER AS $$
68
- BEGIN
69
- NEW.updated_at = NOW();
70
- RETURN NEW;
71
- END;
72
- $$ LANGUAGE plpgsql;
73
-
74
- -- Apply trigger to users table
75
- CREATE TRIGGER trigger_users_updated_at
76
- BEFORE UPDATE ON users
77
- FOR EACH ROW
78
- EXECUTE FUNCTION update_updated_at_column();
79
-
80
- -- Add table comment
81
- COMMENT ON TABLE users IS 'Core user accounts for authentication and authorization';
82
-
83
- -- ============================================
84
- -- DOWN MIGRATION (Rollback)
85
- -- ============================================
86
-
87
- -- WARNING: This will delete all user data!
88
- -- Ensure you have a backup before running rollback.
89
-
90
- -- Drop trigger
91
- DROP TRIGGER IF EXISTS trigger_users_updated_at ON users;
92
-
93
- -- Drop function (only if not used by other tables)
94
- -- DROP FUNCTION IF EXISTS update_updated_at_column();
95
-
96
- -- Drop table
97
- DROP TABLE IF EXISTS users;
98
-
99
- -- Drop enums
100
- DROP TYPE IF EXISTS user_role;
101
- DROP TYPE IF EXISTS user_status;
102
-
103
- -- ============================================
104
- -- VERIFICATION
105
- -- ============================================
106
-
107
- -- Run these queries to verify the migration succeeded:
108
-
109
- -- Check table exists
110
- SELECT EXISTS (
111
- SELECT FROM information_schema.tables
112
- WHERE table_name = 'users'
113
- );
114
-
115
- -- Check columns
116
- SELECT column_name, data_type, is_nullable
117
- FROM information_schema.columns
118
- WHERE table_name = 'users'
119
- ORDER BY ordinal_position;
120
-
121
- -- Check indexes
122
- SELECT indexname, indexdef
123
- FROM pg_indexes
124
- WHERE tablename = 'users';
125
-
126
- -- Check trigger
127
- SELECT trigger_name
128
- FROM information_schema.triggers
129
- WHERE event_object_table = 'users';
@@ -1,94 +0,0 @@
1
- -- Migration: Add user preferences column
2
- -- Author: ProAgents
3
- -- Date: 2024-01-16
4
- -- Risk Level: Low
5
- -- Requires Approval: No
6
- -- Estimated Duration: < 1 second
7
-
8
- -- Description:
9
- -- Adds a JSONB column to store user preferences like theme, language,
10
- -- notification settings, etc. Using JSONB allows flexible schema-less
11
- -- storage with indexing capabilities.
12
-
13
- -- ============================================
14
- -- UP MIGRATION
15
- -- ============================================
16
-
17
- -- Add preferences column with default empty object
18
- ALTER TABLE users
19
- ADD COLUMN preferences JSONB NOT NULL DEFAULT '{}'::jsonb;
20
-
21
- -- Add GIN index for JSONB queries
22
- -- This enables fast queries like: WHERE preferences @> '{"theme": "dark"}'
23
- CREATE INDEX idx_users_preferences
24
- ON users USING GIN (preferences);
25
-
26
- -- Add specific index for common preference queries
27
- CREATE INDEX idx_users_preferences_theme
28
- ON users ((preferences->>'theme'))
29
- WHERE preferences->>'theme' IS NOT NULL;
30
-
31
- -- Add column comment
32
- COMMENT ON COLUMN users.preferences IS 'User preferences stored as JSONB. Keys: theme, language, notifications, timezone, etc.';
33
-
34
- -- Optionally set default preferences for existing users
35
- UPDATE users
36
- SET preferences = jsonb_build_object(
37
- 'theme', 'light',
38
- 'language', 'en',
39
- 'notifications', jsonb_build_object(
40
- 'email', true,
41
- 'push', true,
42
- 'weekly_digest', false
43
- ),
44
- 'timezone', 'UTC'
45
- )
46
- WHERE preferences = '{}'::jsonb;
47
-
48
- -- ============================================
49
- -- DOWN MIGRATION (Rollback)
50
- -- ============================================
51
-
52
- -- Drop indexes first
53
- DROP INDEX IF EXISTS idx_users_preferences_theme;
54
- DROP INDEX IF EXISTS idx_users_preferences;
55
-
56
- -- Remove column
57
- ALTER TABLE users DROP COLUMN IF EXISTS preferences;
58
-
59
- -- ============================================
60
- -- VERIFICATION
61
- -- ============================================
62
-
63
- -- Check column exists
64
- SELECT column_name, data_type, column_default
65
- FROM information_schema.columns
66
- WHERE table_name = 'users' AND column_name = 'preferences';
67
-
68
- -- Check indexes exist
69
- SELECT indexname
70
- FROM pg_indexes
71
- WHERE tablename = 'users' AND indexname LIKE '%preferences%';
72
-
73
- -- Test JSONB query performance
74
- EXPLAIN ANALYZE
75
- SELECT id, email, preferences->>'theme' as theme
76
- FROM users
77
- WHERE preferences @> '{"theme": "dark"}';
78
-
79
- -- ============================================
80
- -- EXAMPLE USAGE
81
- -- ============================================
82
-
83
- -- Query users by preference
84
- -- SELECT * FROM users WHERE preferences->>'theme' = 'dark';
85
-
86
- -- Update a single preference
87
- -- UPDATE users
88
- -- SET preferences = jsonb_set(preferences, '{theme}', '"dark"')
89
- -- WHERE id = '...';
90
-
91
- -- Add new preference key
92
- -- UPDATE users
93
- -- SET preferences = preferences || '{"sidebar_collapsed": true}'::jsonb
94
- -- WHERE id = '...';
@@ -1,105 +0,0 @@
1
- -- Migration: Add performance index on users.email
2
- -- Author: ProAgents
3
- -- Date: 2024-01-17
4
- -- Risk Level: Medium
5
- -- Requires Approval: Team Lead
6
- -- Estimated Duration: Depends on table size (1-5 minutes for large tables)
7
-
8
- -- Description:
9
- -- Adds a B-tree index on the email column to improve login query performance.
10
- -- Uses CONCURRENTLY to avoid locking the table during index creation.
11
- --
12
- -- IMPORTANT: CONCURRENTLY cannot be used inside a transaction block.
13
- -- Run this migration outside of a transaction.
14
-
15
- -- ============================================
16
- -- PRE-FLIGHT CHECKS
17
- -- ============================================
18
-
19
- -- Check table size before creating index
20
- SELECT
21
- pg_size_pretty(pg_total_relation_size('users')) as table_size,
22
- (SELECT count(*) FROM users) as row_count;
23
-
24
- -- Estimate index creation time (rough)
25
- -- Rule of thumb: ~1 minute per 10 million rows
26
-
27
- -- ============================================
28
- -- UP MIGRATION
29
- -- ============================================
30
-
31
- -- Create index concurrently (non-blocking)
32
- -- NOTE: Cannot run inside transaction
33
- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email_lookup
34
- ON users (LOWER(email))
35
- WHERE deleted_at IS NULL;
36
-
37
- -- Create composite index for common queries
38
- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_status_created
39
- ON users (status, created_at DESC)
40
- WHERE deleted_at IS NULL;
41
-
42
- -- Create partial index for active users only
43
- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_active
44
- ON users (last_login_at DESC)
45
- WHERE status = 'active' AND deleted_at IS NULL;
46
-
47
- -- ============================================
48
- -- DOWN MIGRATION (Rollback)
49
- -- ============================================
50
-
51
- -- Drop indexes (also use CONCURRENTLY for safety)
52
- DROP INDEX CONCURRENTLY IF EXISTS idx_users_active;
53
- DROP INDEX CONCURRENTLY IF EXISTS idx_users_status_created;
54
- DROP INDEX CONCURRENTLY IF EXISTS idx_users_email_lookup;
55
-
56
- -- ============================================
57
- -- VERIFICATION
58
- -- ============================================
59
-
60
- -- Check indexes were created
61
- SELECT
62
- indexname,
63
- indexdef,
64
- pg_size_pretty(pg_relation_size(indexname::regclass)) as index_size
65
- FROM pg_indexes
66
- WHERE tablename = 'users'
67
- ORDER BY indexname;
68
-
69
- -- Verify index is being used
70
- EXPLAIN ANALYZE
71
- SELECT id, email
72
- FROM users
73
- WHERE LOWER(email) = 'test@example.com'
74
- AND deleted_at IS NULL;
75
-
76
- -- Check for invalid indexes (failed CONCURRENTLY)
77
- SELECT indexrelid::regclass as index_name, indisvalid
78
- FROM pg_index
79
- WHERE NOT indisvalid;
80
-
81
- -- ============================================
82
- -- TROUBLESHOOTING
83
- -- ============================================
84
-
85
- -- If CONCURRENTLY fails, the index may be in invalid state.
86
- -- Check and drop invalid indexes:
87
- --
88
- -- SELECT indexrelid::regclass
89
- -- FROM pg_index
90
- -- WHERE NOT indisvalid;
91
- --
92
- -- DROP INDEX CONCURRENTLY idx_users_email_lookup;
93
- -- Then retry the CREATE INDEX CONCURRENTLY.
94
-
95
- -- ============================================
96
- -- PERFORMANCE COMPARISON
97
- -- ============================================
98
-
99
- -- Before index (sequential scan):
100
- -- Seq Scan on users (cost=0.00..1234.00 rows=1 width=36)
101
- -- Filter: (lower((email)::text) = 'test@example.com'::text)
102
-
103
- -- After index (index scan):
104
- -- Index Scan using idx_users_email_lookup on users (cost=0.42..8.44 rows=1 width=36)
105
- -- Index Cond: (lower((email)::text) = 'test@example.com'::text)