@@ -358,6 +358,224 @@ Clustered by: to_date, griffin_tier_name
358358| base_fortress_user_login | Login events (Fortress auth) | bq_partitiondate |
359359| base_join_ltxstudio_web_process_started_ended | Joined start + end with duration | bq_partitiondate |
360360
361+ ### Enterprise Token & Billing Tables (backend_griffin_market)
362+
363+ > Use these tables to track token purchases, consumption, and credit limit monitoring for enterprise accounts.
364+ > See ` shared/enterprise-token-pools.md ` for detailed logic on shared vs non-shared token pools.
365+
366+ | Table | Description | Partition |
367+ | -------| -------------| -----------|
368+ | base_backend_griffin_market_purchased_consumables | Token purchases (initial balance) | None |
369+ | base_backend_griffin_market_consumed_consumables | Token consumption (transactions) | None |
370+ | base_backend_griffin_market_unified_payment_source | Payment sources & code redemptions | None |
371+ | base_backend_griffin_shared_subscription_group | Shared subscription groups & seat details | None |
372+
373+ #### backend_griffin_market_purchased_consumables
374+
375+ ** Token purchases and initial balances.** One row per purchased consumable (token package).
376+
377+ ```
378+ Table: `ltx-dwh-prod-processed.base.backend_griffin_market_purchased_consumables`
379+ Grain: One row per consumable_id
380+ ```
381+
382+ ** Key Fields:**
383+
384+ | Column | Type | Description |
385+ | --------| ------| -------------|
386+ | consumable_id | STRING | Unique identifier of this consumable |
387+ | consumable_type | STRING | "Coin" or "YOUniverse_pack" |
388+ | ltid | STRING | Owner of consumable (NULL when org-level, see is_shared_token_pool) |
389+ | organization_id | STRING | Organization ID (when consumable belongs to org) |
390+ | payment_source_id | STRING | Where this consumable came from |
391+ | quantity | INT | Units purchased |
392+ | group_id | STRING | Shared subscription group ID |
393+ | ** is_shared_token_pool** | ** BOOL** | ** If TRUE: ltid = group_id (org-level record)** |
394+ | is_cap | BOOL | Whether this is a cap allocation |
395+ | is_unlimited | BOOL | Unlimited tokens flag |
396+ | expiration_ms | TIMESTAMP | When this consumable expires |
397+ | payment_id | STRING | Only for single product purchases (not bundles) |
398+ | revoked_at_ms | TIMESTAMP | Revocation timestamp (NULL if not revoked) |
399+ | revocation_reason | STRING | Reason for revocation |
400+ | created_at_ms | TIMESTAMP | Creation timestamp |
401+ | updated_at_ms | TIMESTAMP | Last update timestamp |
402+
403+ ** Critical Logic:**
404+
405+ ``` sql
406+ -- Shared token pool (most enterprise orgs)
407+ IF is_shared_token_pool = TRUE:
408+ - ltid = group_id (this is an ORG- level record)
409+ - All users in the group consume from this pool
410+ - See consumed_consumables .consumed_by_ltid for individual user consumption
411+
412+ -- Non-shared pool (McCann, Cylndr SSO users, code users)
413+ IF is_shared_token_pool = FALSE:
414+ - ltid = individual user
415+ - Only this user can consume from this balance
416+ ```
417+
418+ #### backend_griffin_market_consumed_consumables
419+
420+ ** Token consumption transactions.** One row per consumption event.
421+
422+ ```
423+ Table: `ltx-dwh-prod-processed.base.backend_griffin_market_consumed_consumables`
424+ Grain: One row per consumption event
425+ ```
426+
427+ ** Key Fields:**
428+
429+ | Column | Type | Description |
430+ | --------| ------| -------------|
431+ | consumable_id | STRING | References purchased_consumables.consumable_id |
432+ | consumable_type | STRING | "Coin" or "YOUniverse_pack" |
433+ | ltid | STRING | Owner of the purchased consumable (NULL when org-level) |
434+ | organization_id | STRING | Organization ID (when org-level) |
435+ | ** consumed_by_ltid** | ** STRING** | ** Who actually consumed (key for shared pools)** |
436+ | product_consumed_id | STRING | Product ID that was consumed |
437+ | product_consumed_description | STRING | Product description |
438+ | quantity | INT | Units consumed |
439+ | group_id | STRING | Shared subscription group ID |
440+ | ** is_shared_token_pool** | ** BOOL** | ** If TRUE: ltid = group_id** |
441+ | is_cap | BOOL | Whether from cap allocation |
442+ | is_unlimited | BOOL | Unlimited tokens flag |
443+ | created_at_ms | TIMESTAMP | Consumption timestamp |
444+ | updated_at_ms | TIMESTAMP | Last update timestamp |
445+
446+ ** Critical Logic:**
447+
448+ ``` sql
449+ -- For shared token pools
450+ IF is_shared_token_pool = TRUE:
451+ - ltid = group_id (matches purchased_consumables)
452+ - consumed_by_ltid = individual user who consumed
453+ - Use consumed_by_ltid to attribute consumption to users
454+
455+ -- For non-shared pools
456+ IF is_shared_token_pool = FALSE:
457+ - ltid = individual user
458+ - consumed_by_ltid may be same as ltid or NULL
459+ ```
460+
461+ ** Example Query — Credit Limit by Org:**
462+
463+ ``` sql
464+ WITH shared_pool_orgs AS (
465+ SELECT
466+ p .ltid AS group_id, -- This is group_id when is_shared_token_pool = true
467+ p .organization_id ,
468+ SUM (p .quantity ) AS total_purchased,
469+ SUM (CASE WHEN c .quantity IS NOT NULL THEN c .quantity ELSE 0 END) AS total_consumed,
470+ COUNT (DISTINCT c .consumed_by_ltid ) AS users_consuming
471+ FROM ` ltx-dwh-prod-processed.base.backend_griffin_market_purchased_consumables` p
472+ LEFT JOIN ` ltx-dwh-prod-processed.base.backend_griffin_market_consumed_consumables` c
473+ ON p .consumable_id = c .consumable_id
474+ WHERE p .is_shared_token_pool = TRUE
475+ AND p .revoked_at_ms IS NULL
476+ GROUP BY 1 , 2
477+ ),
478+
479+ non_shared_pool_users AS (
480+ SELECT
481+ p .ltid ,
482+ p .organization_id ,
483+ SUM (p .quantity ) AS total_purchased,
484+ SUM (CASE WHEN c .quantity IS NOT NULL THEN c .quantity ELSE 0 END) AS total_consumed
485+ FROM ` ltx-dwh-prod-processed.base.backend_griffin_market_purchased_consumables` p
486+ LEFT JOIN ` ltx-dwh-prod-processed.base.backend_griffin_market_consumed_consumables` c
487+ ON p .consumable_id = c .consumable_id
488+ WHERE p .is_shared_token_pool = FALSE
489+ AND p .revoked_at_ms IS NULL
490+ GROUP BY 1 , 2
491+ )
492+
493+ SELECT * FROM shared_pool_orgs
494+ UNION ALL
495+ SELECT ltid AS group_id, organization_id, total_purchased, total_consumed, 1 AS users_consuming
496+ FROM non_shared_pool_users
497+ ```
498+
499+ #### backend_griffin_market_unified_payment_source
500+
501+ ** Payment sources and complimentary code redemptions.** One row per payment source.
502+
503+ ```
504+ Table: `ltx-dwh-prod-processed.base.backend_griffin_market_unified_payment_source`
505+ Grain: One row per payment_source_id
506+ ```
507+
508+ ** Key Fields:**
509+
510+ | Column | Type | Description |
511+ | --------| ------| -------------|
512+ | payment_source_id | STRING | Unique identifier |
513+ | full_payment_source_id | STRING | Identifier with vendor prefix |
514+ | ltid | STRING | User who owns this payment source |
515+ | vendor | STRING | "adyencc", "appstore", "stripe", "paypal" |
516+ | ** complimentary_code** | ** STRING** | ** Complimentary code redeemed (for code tracking)** |
517+ | is_sandbox | BOOL | Sandbox flag |
518+ | quote_id | STRING | Original quote ID |
519+ | renewal_details | RECORD | Auto-renew info (complex nested object) |
520+ | geolocation | RECORD | Country, region, city, postal code |
521+ | purchasing_device_details | RECORD | App, version, platform |
522+ | credit_card_details | RECORD | Card info (when applicable) |
523+ | created_at_ms | TIMESTAMP | Creation timestamp |
524+ | updated_at_ms | TIMESTAMP | Last update timestamp |
525+
526+ ** Example Query — Code Redemption Tracking:**
527+
528+ ``` sql
529+ SELECT
530+ u .ltid ,
531+ u .complimentary_code ,
532+ u .created_at_ms AS redemption_ts,
533+ p .quantity AS tokens_granted,
534+ p .consumable_type
535+ FROM ` ltx-dwh-prod-processed.base.backend_griffin_market_unified_payment_source` u
536+ INNER JOIN ` ltx-dwh-prod-processed.base.backend_griffin_market_purchased_consumables` p
537+ ON u .payment_source_id = p .payment_source_id
538+ WHERE u .complimentary_code IS NOT NULL
539+ ORDER BY u .created_at_ms DESC
540+ ```
541+
542+ #### backend_griffin_shared_subscription_group
543+
544+ ** Shared subscription groups and seat configurations.** One row per group.
545+
546+ ```
547+ Table: `ltx-dwh-prod-processed.base.backend_griffin_shared_subscription_group`
548+ Grain: One row per group_id (item_identifier)
549+ ```
550+
551+ ** Key Fields:**
552+
553+ | Column | Type | Description |
554+ | --------| ------| -------------|
555+ | seats | ARRAY<RECORD > | Seat types, quantities, consumable offerings |
556+ | apps | ARRAY<STRING > | "ltxstudio", "facetune", "popular-pays.brands" |
557+ | platforms | ARRAY<STRING > | "w" (web), "a" (android), "i" (iOS) |
558+ | admin_ltid | STRING | Group admin user ID (NULL if pending) |
559+ | ** has_shared_token_pool** | ** BOOL** | ** Shared pool managed under admin's ltid** |
560+ | product_id | STRING | Associated product |
561+ | payment_source_id | STRING | Associated payment source |
562+ | expiration_ms | TIMESTAMP | When group expires |
563+ | revoked_at_ms | TIMESTAMP | Revocation timestamp (NULL if active) |
564+ | created_at_ms | TIMESTAMP | Creation timestamp |
565+ | updated_at_ms | TIMESTAMP | Last update timestamp |
566+
567+ ** Seats Array Structure:**
568+
569+ ``` sql
570+ -- seats[].type: "admin", "regular"
571+ -- seats[].quantity: Max seats allowed
572+ -- seats[].feature_tags[]: Enabled features
573+ -- seats[].consumable_offerings[].consumable_type: "Coin"
574+ -- seats[].consumable_offerings[].quantity: Tokens per cycle
575+ -- seats[].consumable_offerings[].timespan: ISO-8601 duration
576+ -- seats[].consumable_offerings[].is_unlimited: Unlimited flag
577+ ```
578+
361579### Common Base Columns
362580
363581Most base tables share these columns:
0 commit comments