@cloudstreamsoftware/claude-tools 1.0.0 → 1.1.0

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 (189) hide show
  1. package/README.md +152 -37
  2. package/agents/INDEX.md +183 -0
  3. package/agents/architect.md +247 -0
  4. package/agents/build-error-resolver.md +555 -0
  5. package/agents/catalyst-deployer.md +132 -0
  6. package/agents/code-reviewer.md +121 -0
  7. package/agents/compliance-auditor.md +148 -0
  8. package/agents/creator-architect.md +395 -0
  9. package/agents/deluge-reviewer.md +98 -0
  10. package/agents/doc-updater.md +471 -0
  11. package/agents/e2e-runner.md +711 -0
  12. package/agents/planner.md +122 -0
  13. package/agents/refactor-cleaner.md +309 -0
  14. package/agents/security-reviewer.md +582 -0
  15. package/agents/tdd-guide.md +302 -0
  16. package/config/versions.json +63 -0
  17. package/dist/hooks/hooks.json +209 -0
  18. package/dist/index.js +47 -0
  19. package/dist/lib/asset-value.js +609 -0
  20. package/dist/lib/client-manager.js +300 -0
  21. package/dist/lib/command-matcher.js +242 -0
  22. package/dist/lib/cross-session-patterns.js +754 -0
  23. package/dist/lib/intent-classifier.js +1075 -0
  24. package/dist/lib/package-manager.js +374 -0
  25. package/dist/lib/recommendation-engine.js +597 -0
  26. package/dist/lib/session-memory.js +489 -0
  27. package/dist/lib/skill-effectiveness.js +486 -0
  28. package/dist/lib/skill-matcher.js +595 -0
  29. package/dist/lib/tutorial-metrics.js +242 -0
  30. package/dist/lib/tutorial-progress.js +209 -0
  31. package/dist/lib/tutorial-renderer.js +431 -0
  32. package/dist/lib/utils.js +380 -0
  33. package/dist/lib/verify-formatter.js +143 -0
  34. package/dist/lib/workflow-state.js +249 -0
  35. package/hooks/hooks.json +209 -0
  36. package/package.json +5 -1
  37. package/scripts/aggregate-sessions.js +290 -0
  38. package/scripts/branch-name-validator.js +291 -0
  39. package/scripts/build.js +101 -0
  40. package/scripts/commands/client-switch.js +231 -0
  41. package/scripts/deprecate-skill.js +610 -0
  42. package/scripts/diagnose.js +324 -0
  43. package/scripts/doc-freshness.js +168 -0
  44. package/scripts/generate-weekly-digest.js +393 -0
  45. package/scripts/health-check.js +270 -0
  46. package/scripts/hooks/credential-check.js +101 -0
  47. package/scripts/hooks/evaluate-session.js +81 -0
  48. package/scripts/hooks/pre-compact.js +66 -0
  49. package/scripts/hooks/prompt-analyzer.js +276 -0
  50. package/scripts/hooks/prompt-router.js +422 -0
  51. package/scripts/hooks/quality-gate-enforcer.js +371 -0
  52. package/scripts/hooks/session-end.js +156 -0
  53. package/scripts/hooks/session-start.js +195 -0
  54. package/scripts/hooks/skill-injector.js +333 -0
  55. package/scripts/hooks/suggest-compact.js +58 -0
  56. package/scripts/lib/asset-value.js +609 -0
  57. package/scripts/lib/client-manager.js +300 -0
  58. package/scripts/lib/command-matcher.js +242 -0
  59. package/scripts/lib/cross-session-patterns.js +754 -0
  60. package/scripts/lib/intent-classifier.js +1075 -0
  61. package/scripts/lib/package-manager.js +374 -0
  62. package/scripts/lib/recommendation-engine.js +597 -0
  63. package/scripts/lib/session-memory.js +489 -0
  64. package/scripts/lib/skill-effectiveness.js +486 -0
  65. package/scripts/lib/skill-matcher.js +595 -0
  66. package/scripts/lib/tutorial-metrics.js +242 -0
  67. package/scripts/lib/tutorial-progress.js +209 -0
  68. package/scripts/lib/tutorial-renderer.js +431 -0
  69. package/scripts/lib/utils.js +380 -0
  70. package/scripts/lib/verify-formatter.js +143 -0
  71. package/scripts/lib/workflow-state.js +249 -0
  72. package/scripts/onboard.js +363 -0
  73. package/scripts/quarterly-report.js +692 -0
  74. package/scripts/setup-package-manager.js +204 -0
  75. package/scripts/sync-upstream.js +391 -0
  76. package/scripts/test.js +108 -0
  77. package/scripts/tutorial-runner.js +351 -0
  78. package/scripts/validate-all.js +201 -0
  79. package/scripts/verifiers/agents.js +245 -0
  80. package/scripts/verifiers/config.js +186 -0
  81. package/scripts/verifiers/environment.js +123 -0
  82. package/scripts/verifiers/hooks.js +188 -0
  83. package/scripts/verifiers/index.js +38 -0
  84. package/scripts/verifiers/persistence.js +140 -0
  85. package/scripts/verifiers/plugin.js +215 -0
  86. package/scripts/verifiers/skills.js +209 -0
  87. package/scripts/verify-setup.js +164 -0
  88. package/skills/INDEX.md +157 -0
  89. package/skills/backend-patterns/SKILL.md +586 -0
  90. package/skills/backend-patterns/catalyst-patterns.md +128 -0
  91. package/skills/bigquery-patterns/SKILL.md +27 -0
  92. package/skills/bigquery-patterns/performance-optimization.md +518 -0
  93. package/skills/bigquery-patterns/query-patterns.md +372 -0
  94. package/skills/bigquery-patterns/schema-design.md +78 -0
  95. package/skills/cloudstream-project-template/SKILL.md +20 -0
  96. package/skills/cloudstream-project-template/structure.md +65 -0
  97. package/skills/coding-standards/SKILL.md +524 -0
  98. package/skills/coding-standards/deluge-standards.md +83 -0
  99. package/skills/compliance-patterns/SKILL.md +28 -0
  100. package/skills/compliance-patterns/hipaa/audit-requirements.md +251 -0
  101. package/skills/compliance-patterns/hipaa/baa-process.md +298 -0
  102. package/skills/compliance-patterns/hipaa/data-archival-strategy.md +387 -0
  103. package/skills/compliance-patterns/hipaa/phi-handling.md +52 -0
  104. package/skills/compliance-patterns/pci-dss/saq-a-requirements.md +307 -0
  105. package/skills/compliance-patterns/pci-dss/tokenization-patterns.md +382 -0
  106. package/skills/compliance-patterns/pci-dss/zoho-checkout-patterns.md +56 -0
  107. package/skills/compliance-patterns/soc2/access-controls.md +344 -0
  108. package/skills/compliance-patterns/soc2/audit-logging.md +458 -0
  109. package/skills/compliance-patterns/soc2/change-management.md +403 -0
  110. package/skills/compliance-patterns/soc2/deluge-execution-logging.md +407 -0
  111. package/skills/consultancy-workflows/SKILL.md +19 -0
  112. package/skills/consultancy-workflows/client-isolation.md +21 -0
  113. package/skills/consultancy-workflows/documentation-automation.md +454 -0
  114. package/skills/consultancy-workflows/handoff-procedures.md +257 -0
  115. package/skills/consultancy-workflows/knowledge-capture.md +513 -0
  116. package/skills/consultancy-workflows/time-tracking.md +26 -0
  117. package/skills/continuous-learning/SKILL.md +84 -0
  118. package/skills/continuous-learning/config.json +18 -0
  119. package/skills/continuous-learning/evaluate-session.sh +60 -0
  120. package/skills/continuous-learning-v2/SKILL.md +126 -0
  121. package/skills/continuous-learning-v2/config.json +61 -0
  122. package/skills/frontend-patterns/SKILL.md +635 -0
  123. package/skills/frontend-patterns/zoho-widget-patterns.md +103 -0
  124. package/skills/gcp-data-engineering/SKILL.md +36 -0
  125. package/skills/gcp-data-engineering/bigquery/performance-optimization.md +337 -0
  126. package/skills/gcp-data-engineering/dataflow/error-handling.md +496 -0
  127. package/skills/gcp-data-engineering/dataflow/pipeline-patterns.md +444 -0
  128. package/skills/gcp-data-engineering/dbt/model-organization.md +63 -0
  129. package/skills/gcp-data-engineering/dbt/testing-patterns.md +503 -0
  130. package/skills/gcp-data-engineering/medallion-architecture/bronze-layer.md +60 -0
  131. package/skills/gcp-data-engineering/medallion-architecture/gold-layer.md +311 -0
  132. package/skills/gcp-data-engineering/medallion-architecture/layer-transitions.md +517 -0
  133. package/skills/gcp-data-engineering/medallion-architecture/silver-layer.md +305 -0
  134. package/skills/gcp-data-engineering/zoho-to-gcp/data-extraction.md +543 -0
  135. package/skills/gcp-data-engineering/zoho-to-gcp/real-time-vs-batch.md +337 -0
  136. package/skills/security-review/SKILL.md +498 -0
  137. package/skills/security-review/compliance-checklist.md +53 -0
  138. package/skills/strategic-compact/SKILL.md +67 -0
  139. package/skills/tdd-workflow/SKILL.md +413 -0
  140. package/skills/tdd-workflow/zoho-testing.md +124 -0
  141. package/skills/tutorial/SKILL.md +249 -0
  142. package/skills/tutorial/docs/ACCESSIBILITY.md +169 -0
  143. package/skills/tutorial/lessons/00-philosophy-and-workflow.md +198 -0
  144. package/skills/tutorial/lessons/01-basics.md +81 -0
  145. package/skills/tutorial/lessons/02-training.md +86 -0
  146. package/skills/tutorial/lessons/03-commands.md +109 -0
  147. package/skills/tutorial/lessons/04-workflows.md +115 -0
  148. package/skills/tutorial/lessons/05-compliance.md +116 -0
  149. package/skills/tutorial/lessons/06-zoho.md +121 -0
  150. package/skills/tutorial/lessons/07-hooks-system.md +277 -0
  151. package/skills/tutorial/lessons/08-mcp-servers.md +316 -0
  152. package/skills/tutorial/lessons/09-client-management.md +215 -0
  153. package/skills/tutorial/lessons/10-testing-e2e.md +260 -0
  154. package/skills/tutorial/lessons/11-skills-deep-dive.md +272 -0
  155. package/skills/tutorial/lessons/12-rules-system.md +326 -0
  156. package/skills/tutorial/lessons/13-golden-standard-graduation.md +213 -0
  157. package/skills/tutorial/lessons/14-fork-setup-and-sync.md +312 -0
  158. package/skills/tutorial/lessons/15-living-examples-system.md +221 -0
  159. package/skills/tutorial/tracks/accelerated/README.md +134 -0
  160. package/skills/tutorial/tracks/accelerated/assessment/checkpoint-1.md +161 -0
  161. package/skills/tutorial/tracks/accelerated/assessment/checkpoint-2.md +175 -0
  162. package/skills/tutorial/tracks/accelerated/day-1-core-concepts.md +234 -0
  163. package/skills/tutorial/tracks/accelerated/day-2-essential-commands.md +270 -0
  164. package/skills/tutorial/tracks/accelerated/day-3-workflow-mastery.md +305 -0
  165. package/skills/tutorial/tracks/accelerated/day-4-compliance-zoho.md +304 -0
  166. package/skills/tutorial/tracks/accelerated/day-5-hooks-skills.md +344 -0
  167. package/skills/tutorial/tracks/accelerated/day-6-client-testing.md +386 -0
  168. package/skills/tutorial/tracks/accelerated/day-7-graduation.md +369 -0
  169. package/skills/zoho-patterns/CHANGELOG.md +108 -0
  170. package/skills/zoho-patterns/SKILL.md +446 -0
  171. package/skills/zoho-patterns/analytics/dashboard-patterns.md +352 -0
  172. package/skills/zoho-patterns/analytics/zoho-to-bigquery-pipeline.md +427 -0
  173. package/skills/zoho-patterns/catalyst/appsail-deployment.md +349 -0
  174. package/skills/zoho-patterns/catalyst/context-close-patterns.md +354 -0
  175. package/skills/zoho-patterns/catalyst/cron-batch-processing.md +374 -0
  176. package/skills/zoho-patterns/catalyst/function-patterns.md +439 -0
  177. package/skills/zoho-patterns/creator/form-design.md +304 -0
  178. package/skills/zoho-patterns/creator/publish-api-patterns.md +313 -0
  179. package/skills/zoho-patterns/creator/widget-integration.md +306 -0
  180. package/skills/zoho-patterns/creator/workflow-automation.md +253 -0
  181. package/skills/zoho-patterns/deluge/api-patterns.md +468 -0
  182. package/skills/zoho-patterns/deluge/batch-processing.md +403 -0
  183. package/skills/zoho-patterns/deluge/cross-app-integration.md +356 -0
  184. package/skills/zoho-patterns/deluge/error-handling.md +423 -0
  185. package/skills/zoho-patterns/deluge/syntax-reference.md +65 -0
  186. package/skills/zoho-patterns/integration/cors-proxy-architecture.md +426 -0
  187. package/skills/zoho-patterns/integration/crm-books-native-sync.md +277 -0
  188. package/skills/zoho-patterns/integration/oauth-token-management.md +461 -0
  189. package/skills/zoho-patterns/integration/zoho-flow-patterns.md +334 -0
@@ -0,0 +1,311 @@
1
+ # Gold Layer - Business-Ready Aggregations
2
+
3
+ > The gold layer provides pre-computed, business-aligned datasets optimized for consumption by Looker Studio, Zoho Analytics, and custom applications.
4
+
5
+ ## Architecture Overview
6
+
7
+ ```
8
+ Silver (cleansed entities) → Gold (business metrics, dimensions, facts)
9
+
10
+ ├── Fact tables (events, transactions)
11
+ ├── Dimension tables (customers, products)
12
+ ├── Materialized views (common aggregations)
13
+ ├── Pre-computed KPIs (daily snapshots)
14
+ └── Consumer-specific views
15
+ ```
16
+
17
+ ## Materialized Views vs Tables: Decision Framework
18
+
19
+ | Factor | Materialized View | Table |
20
+ |--------|-------------------|-------|
21
+ | Refresh | Auto (within limits) | Manual/scheduled |
22
+ | Cost (storage) | Free (cached query) | Billed at storage rates |
23
+ | Cost (compute) | Incremental refresh | Full rebuild each run |
24
+ | Freshness | Near real-time (5-min lag) | Depends on schedule |
25
+ | Complexity | Single-table aggregations only | Arbitrary SQL |
26
+ | Joins | Limited (single source table) | Unlimited |
27
+ | Best for | Simple rollups, dashboards | Complex multi-source models |
28
+
29
+ > **COST WARNING**: Materialized views only support single-table sources with limited SQL. For multi-table joins, use scheduled dbt models instead.
30
+
31
+ ```sql
32
+ -- Good candidate for materialized view: simple daily aggregation
33
+ CREATE MATERIALIZED VIEW `project.gold.mv_daily_deal_summary`
34
+ PARTITION BY deal_date
35
+ CLUSTER BY owner_id
36
+ AS
37
+ SELECT
38
+ DATE(close_date) AS deal_date,
39
+ owner_id,
40
+ stage,
41
+ COUNT(*) AS deal_count,
42
+ SUM(amount) AS total_amount,
43
+ AVG(amount) AS avg_amount
44
+ FROM `project.silver.zoho_deals`
45
+ WHERE close_date IS NOT NULL
46
+ GROUP BY 1, 2, 3;
47
+
48
+ -- NOT a candidate for materialized view: multi-table join → use dbt table
49
+ -- models/marts/fct_revenue.sql
50
+ ```
51
+
52
+ ## Fact/Dimension Modeling
53
+
54
+ ### Dimension Tables
55
+
56
+ ```sql
57
+ -- models/marts/dim_customers.sql
58
+ {{
59
+ config(
60
+ materialized='table',
61
+ partition_by={'field': '_loaded_date', 'data_type': 'date'},
62
+ cluster_by=['industry', 'region']
63
+ )
64
+ }}
65
+
66
+ SELECT
67
+ c.record_id AS customer_id,
68
+ c.account_name,
69
+ c.industry,
70
+ c.annual_revenue,
71
+ c.employee_count,
72
+ a.billing_city,
73
+ a.billing_state,
74
+ a.billing_country,
75
+ CASE
76
+ WHEN a.billing_country IN ('US', 'CA') THEN 'North America'
77
+ WHEN a.billing_country IN ('GB', 'DE', 'FR') THEN 'Europe'
78
+ ELSE 'Other'
79
+ END AS region,
80
+ o.owner_name AS account_owner,
81
+ c.created_time AS customer_since,
82
+ CURRENT_DATE() AS _loaded_date
83
+ FROM {{ ref('stg_zoho__accounts') }} c
84
+ LEFT JOIN {{ ref('int_zoho__addresses') }} a ON c.record_id = a.account_id
85
+ LEFT JOIN {{ ref('stg_zoho__users') }} o ON c.owner_id = o.user_id
86
+ ```
87
+
88
+ ### Fact Tables
89
+
90
+ ```sql
91
+ -- models/marts/fct_invoices.sql
92
+ {{
93
+ config(
94
+ materialized='incremental',
95
+ unique_key='invoice_id',
96
+ partition_by={'field': 'invoice_date', 'data_type': 'date'},
97
+ cluster_by=['customer_id', 'status']
98
+ )
99
+ }}
100
+
101
+ SELECT
102
+ i.record_id AS invoice_id,
103
+ i.customer_id,
104
+ i.invoice_number,
105
+ DATE(i.invoice_date) AS invoice_date,
106
+ DATE(i.due_date) AS due_date,
107
+ i.status,
108
+ i.sub_total,
109
+ i.tax_amount,
110
+ i.total AS invoice_total,
111
+ i.balance_due,
112
+ DATE_DIFF(
113
+ COALESCE(i.paid_date, CURRENT_DATE()),
114
+ i.invoice_date,
115
+ DAY
116
+ ) AS days_to_payment,
117
+ i.currency_code,
118
+ i.salesperson_id,
119
+ CURRENT_TIMESTAMP() AS _loaded_at
120
+ FROM {{ ref('stg_zoho__invoices') }} i
121
+ {% if is_incremental() %}
122
+ WHERE i._ingestion_timestamp > (SELECT MAX(_loaded_at) FROM {{ this }})
123
+ {% endif %}
124
+ ```
125
+
126
+ ## Pre-Computed KPIs
127
+
128
+ ```sql
129
+ -- models/marts/kpi_daily_snapshot.sql
130
+ {{
131
+ config(
132
+ materialized='incremental',
133
+ unique_key='snapshot_date',
134
+ partition_by={'field': 'snapshot_date', 'data_type': 'date'}
135
+ )
136
+ }}
137
+
138
+ SELECT
139
+ CURRENT_DATE() AS snapshot_date,
140
+ -- Revenue KPIs
141
+ SUM(CASE WHEN status = 'paid' AND invoice_date >= DATE_TRUNC(CURRENT_DATE(), MONTH)
142
+ THEN invoice_total ELSE 0 END) AS mtd_revenue,
143
+ SUM(CASE WHEN status = 'paid' AND invoice_date >= DATE_TRUNC(CURRENT_DATE(), YEAR)
144
+ THEN invoice_total ELSE 0 END) AS ytd_revenue,
145
+ -- Pipeline KPIs
146
+ (SELECT SUM(amount) FROM {{ ref('fct_deals') }}
147
+ WHERE stage NOT IN ('Closed Won', 'Closed Lost')) AS open_pipeline_value,
148
+ (SELECT COUNT(*) FROM {{ ref('fct_deals') }}
149
+ WHERE stage NOT IN ('Closed Won', 'Closed Lost')) AS open_deal_count,
150
+ -- AR KPIs
151
+ SUM(CASE WHEN status = 'overdue' THEN balance_due ELSE 0 END) AS total_overdue,
152
+ COUNT(CASE WHEN status = 'overdue' THEN 1 END) AS overdue_invoice_count,
153
+ AVG(days_to_payment) AS avg_days_to_payment,
154
+ CURRENT_TIMESTAMP() AS _computed_at
155
+ FROM {{ ref('fct_invoices') }}
156
+ ```
157
+
158
+ ## Refresh Strategies
159
+
160
+ ### Event-Driven Refresh (Recommended for Critical KPIs)
161
+
162
+ ```python
163
+ # Cloud Function triggered by silver table update
164
+ from google.cloud import bigquery
165
+ import functions_framework
166
+
167
+ @functions_framework.cloud_event
168
+ def refresh_gold_on_silver_update(cloud_event):
169
+ """Triggered by BigQuery audit log when silver tables are updated."""
170
+ client = bigquery.Client()
171
+
172
+ # Determine which gold models need refresh
173
+ source_table = cloud_event.data.get("protoPayload", {}).get(
174
+ "resourceName", ""
175
+ )
176
+
177
+ refresh_map = {
178
+ "silver.zoho_deals": ["gold.fct_deals", "gold.kpi_daily_snapshot"],
179
+ "silver.zoho_invoices": ["gold.fct_invoices", "gold.kpi_daily_snapshot"],
180
+ "silver.zoho_contacts": ["gold.dim_customers"],
181
+ }
182
+
183
+ for table_suffix, targets in refresh_map.items():
184
+ if table_suffix in source_table:
185
+ for target in targets:
186
+ job = client.query(f"CALL `project.gold.refresh_{target.split('.')[1]}`()")
187
+ job.result()
188
+ ```
189
+
190
+ ### Scheduled Refresh (Standard Pattern)
191
+
192
+ ```yaml
193
+ # Cloud Scheduler → dbt run for gold models
194
+ # Runs every 6 hours
195
+ schedule:
196
+ name: gold-layer-refresh
197
+ cron: "0 */6 * * *"
198
+ target:
199
+ command: "dbt run --select tag:gold --target prod"
200
+
201
+ # Critical KPIs refresh more frequently
202
+ schedule:
203
+ name: kpi-snapshot-refresh
204
+ cron: "0 * * * *" # Every hour during business hours
205
+ target:
206
+ command: "dbt run --select kpi_daily_snapshot --target prod"
207
+ ```
208
+
209
+ ## Downstream Consumer Patterns
210
+
211
+ ### Looker Studio
212
+
213
+ ```sql
214
+ -- Optimized view for Looker Studio dashboards
215
+ -- Use BI Engine reservation for sub-second queries
216
+ CREATE OR REPLACE VIEW `project.gold.v_looker_revenue_dashboard` AS
217
+ SELECT
218
+ snapshot_date,
219
+ mtd_revenue,
220
+ ytd_revenue,
221
+ open_pipeline_value,
222
+ total_overdue,
223
+ avg_days_to_payment,
224
+ -- Pre-computed period comparisons for Looker
225
+ LAG(mtd_revenue, 30) OVER (ORDER BY snapshot_date) AS prior_month_revenue,
226
+ SAFE_DIVIDE(
227
+ mtd_revenue - LAG(mtd_revenue, 30) OVER (ORDER BY snapshot_date),
228
+ LAG(mtd_revenue, 30) OVER (ORDER BY snapshot_date)
229
+ ) AS revenue_mom_growth
230
+ FROM `project.gold.kpi_daily_snapshot`
231
+ WHERE snapshot_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 13 MONTH);
232
+ ```
233
+
234
+ ### Zoho Analytics (via BigQuery Connector)
235
+
236
+ ```sql
237
+ -- Zoho Analytics pulls from dedicated views with flattened structure
238
+ -- Avoid nested/repeated fields - Zoho Analytics cannot handle them
239
+ CREATE OR REPLACE VIEW `project.gold.v_zoho_analytics_deals` AS
240
+ SELECT
241
+ deal_id,
242
+ deal_name,
243
+ customer_name, -- Denormalized, no joins needed
244
+ owner_name, -- Denormalized
245
+ stage,
246
+ amount,
247
+ FORMAT_DATE('%Y-%m-%d', close_date) AS close_date_str, -- String dates for Zoho
248
+ CAST(probability AS INT64) AS probability_pct
249
+ FROM `project.gold.fct_deals` d
250
+ JOIN `project.gold.dim_customers` c ON d.customer_id = c.customer_id;
251
+ ```
252
+
253
+ ## Access Control Per Gold Table
254
+
255
+ ```sql
256
+ -- Grant granular access to gold tables
257
+ -- Finance team: revenue and invoice data only
258
+ GRANT `roles/bigquery.dataViewer`
259
+ ON TABLE `project.gold.fct_invoices`
260
+ TO "group:finance@cloudstreamsoftware.com";
261
+
262
+ -- Sales team: deals and pipeline
263
+ GRANT `roles/bigquery.dataViewer`
264
+ ON TABLE `project.gold.fct_deals`
265
+ TO "group:sales@cloudstreamsoftware.com";
266
+
267
+ -- Executives: KPI snapshots
268
+ GRANT `roles/bigquery.dataViewer`
269
+ ON TABLE `project.gold.kpi_daily_snapshot`
270
+ TO "group:executives@cloudstreamsoftware.com";
271
+
272
+ -- Row-level security for multi-tenant data
273
+ CREATE OR REPLACE ROW ACCESS POLICY region_filter
274
+ ON `project.gold.fct_deals`
275
+ GRANT TO ("group:sales-na@cloudstreamsoftware.com")
276
+ FILTER USING (region = 'North America');
277
+ ```
278
+
279
+ ## Versioning Strategy
280
+
281
+ ```sql
282
+ -- Version gold tables for breaking changes
283
+ -- v1 remains available while consumers migrate to v2
284
+ CREATE OR REPLACE VIEW `project.gold.v1.fct_deals` AS
285
+ SELECT deal_id, amount, stage FROM `project.gold.fct_deals`;
286
+
287
+ CREATE OR REPLACE VIEW `project.gold.v2.fct_deals` AS
288
+ SELECT deal_id, amount, stage, probability, expected_revenue
289
+ FROM `project.gold.fct_deals`;
290
+
291
+ -- Track which consumers use which version
292
+ CREATE TABLE `project.gold._version_registry` (
293
+ table_name STRING,
294
+ version STRING,
295
+ consumer STRING,
296
+ migration_deadline DATE,
297
+ migrated BOOL DEFAULT FALSE
298
+ );
299
+ ```
300
+
301
+ ## Best Practices
302
+
303
+ 1. **Denormalize for consumers** - Gold tables should minimize joins for dashboard performance
304
+ 2. **Pre-compute period comparisons** - MoM, YoY, MTD built into the table, not at query time
305
+ 3. **Flatten nested structures** - Zoho Analytics and Looker prefer flat schemas
306
+ 4. **Use BI Engine for dashboards** - Reserve capacity for sub-second Looker queries
307
+ 5. **Version breaking changes** - Never modify gold schemas without deprecation period
308
+ 6. **Restrict access by role** - Not everyone needs all gold tables
309
+ 7. **Monitor query patterns** - Use INFORMATION_SCHEMA to identify optimization opportunities
310
+
311
+ > **COST TIP**: Materialized views are free to store and automatically refresh. Use them for any single-table aggregation that is queried more than once per day. The break-even is typically 2-3 queries/day vs re-running the aggregation each time.