@happyvertical/smrt-subscriptions 0.49.3 → 0.49.4

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.
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-subscriptions",
5
- "packageVersion": "0.49.3",
5
+ "packageVersion": "0.49.4",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-subscriptions:SubscriptionPlanCollection": {
8
8
  "name": "subscriptionplancollection",
@@ -59,7 +59,7 @@
59
59
  "collectionExportName": "SubscriptionPlanCollectionCollection",
60
60
  "schema": {
61
61
  "tableName": "_smrt_subscription_plans",
62
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_subscription_plans\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
62
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_subscription_plans\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID,\n \"plan_key\" TEXT DEFAULT '',\n \"name\" TEXT DEFAULT '',\n \"description\" TEXT DEFAULT '',\n \"status\" TEXT DEFAULT 'active',\n \"sort_order\" INTEGER DEFAULT 0,\n \"price_amount\" INTEGER DEFAULT 0,\n \"currency\" TEXT DEFAULT 'USD',\n \"billing_interval\" TEXT DEFAULT 'month',\n \"external_provider\" TEXT DEFAULT 'stripe',\n \"stripe_product_id\" TEXT DEFAULT '',\n \"stripe_price_id\" TEXT DEFAULT '',\n \"features\" TEXT DEFAULT '[]',\n \"thresholds\" TEXT DEFAULT '[]',\n \"metadata\" TEXT DEFAULT '{}'\n);",
63
63
  "columns": {
64
64
  "id": {
65
65
  "type": "UUID",
@@ -85,25 +85,123 @@
85
85
  "type": "TIMESTAMP",
86
86
  "notNull": true,
87
87
  "default": "current_timestamp"
88
+ },
89
+ "tenant_id": {
90
+ "type": "UUID",
91
+ "referenceKind": "tenantId",
92
+ "notNull": false,
93
+ "unique": false
94
+ },
95
+ "plan_key": {
96
+ "type": "TEXT",
97
+ "notNull": false,
98
+ "unique": false,
99
+ "default": ""
100
+ },
101
+ "name": {
102
+ "type": "TEXT",
103
+ "notNull": false,
104
+ "unique": false,
105
+ "default": ""
106
+ },
107
+ "description": {
108
+ "type": "TEXT",
109
+ "notNull": false,
110
+ "unique": false,
111
+ "default": ""
112
+ },
113
+ "status": {
114
+ "type": "TEXT",
115
+ "notNull": false,
116
+ "unique": false,
117
+ "default": "active"
118
+ },
119
+ "sort_order": {
120
+ "type": "INTEGER",
121
+ "notNull": false,
122
+ "unique": false,
123
+ "default": 0
124
+ },
125
+ "price_amount": {
126
+ "type": "INTEGER",
127
+ "notNull": false,
128
+ "unique": false,
129
+ "default": 0
130
+ },
131
+ "currency": {
132
+ "type": "TEXT",
133
+ "notNull": false,
134
+ "unique": false,
135
+ "default": "USD"
136
+ },
137
+ "billing_interval": {
138
+ "type": "TEXT",
139
+ "notNull": false,
140
+ "unique": false,
141
+ "default": "month"
142
+ },
143
+ "external_provider": {
144
+ "type": "TEXT",
145
+ "notNull": false,
146
+ "unique": false,
147
+ "default": "stripe"
148
+ },
149
+ "stripe_product_id": {
150
+ "type": "TEXT",
151
+ "notNull": false,
152
+ "unique": false,
153
+ "default": ""
154
+ },
155
+ "stripe_price_id": {
156
+ "type": "TEXT",
157
+ "notNull": false,
158
+ "unique": false,
159
+ "default": ""
160
+ },
161
+ "features": {
162
+ "type": "TEXT",
163
+ "notNull": false,
164
+ "unique": false,
165
+ "default": "[]"
166
+ },
167
+ "thresholds": {
168
+ "type": "TEXT",
169
+ "notNull": false,
170
+ "unique": false,
171
+ "default": "[]"
172
+ },
173
+ "metadata": {
174
+ "type": "TEXT",
175
+ "notNull": false,
176
+ "unique": false,
177
+ "default": "{}"
88
178
  }
89
179
  },
90
180
  "indexes": [
181
+ {
182
+ "name": "_smrt_subscription_plans_plan_key_idx",
183
+ "columns": [
184
+ "plan_key"
185
+ ],
186
+ "unique": true,
187
+ "nullsNotDistinct": true
188
+ },
91
189
  {
92
190
  "name": "_smrt_subscription_plans_slug_context_idx",
93
191
  "columns": [
94
192
  "slug",
95
193
  "context"
96
- ],
97
- "unique": true
194
+ ]
98
195
  },
99
196
  {
100
- "name": "_smrt_subscription_plans_created_at_idx",
197
+ "name": "_smrt_subscription_plans_tenant_id_created_at_idx",
101
198
  "columns": [
199
+ "tenant_id",
102
200
  "created_at"
103
201
  ]
104
202
  }
105
203
  ],
106
- "version": "e693208d"
204
+ "version": "65765fd0"
107
205
  }
108
206
  },
109
207
  "@happyvertical/smrt-subscriptions:TenantSubscriptionCollection": {
@@ -191,7 +289,7 @@
191
289
  "collectionExportName": "TenantSubscriptionCollectionCollection",
192
290
  "schema": {
193
291
  "tableName": "_smrt_tenant_subscriptions",
194
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_tenant_subscriptions\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
292
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_tenant_subscriptions\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID NOT NULL,\n \"subscriber_kind\" TEXT DEFAULT 'tenant',\n \"subscriber_external_id\" TEXT DEFAULT '',\n \"plan_id\" UUID,\n \"status\" TEXT DEFAULT 'incomplete',\n \"started_at\" TIMESTAMP,\n \"current_period_start\" TIMESTAMP,\n \"current_period_end\" TIMESTAMP,\n \"trial_ends_at\" TIMESTAMP,\n \"cancel_at_period_end\" BOOLEAN DEFAULT FALSE,\n \"canceled_at\" TIMESTAMP,\n \"external_provider\" TEXT DEFAULT 'stripe',\n \"stripe_customer_id\" TEXT DEFAULT '',\n \"stripe_subscription_id\" TEXT DEFAULT '',\n \"stripe_checkout_session_id\" TEXT DEFAULT '',\n \"metadata\" TEXT DEFAULT '{}'\n);",
195
293
  "columns": {
196
294
  "id": {
197
295
  "type": "UUID",
@@ -217,25 +315,138 @@
217
315
  "type": "TIMESTAMP",
218
316
  "notNull": true,
219
317
  "default": "current_timestamp"
318
+ },
319
+ "tenant_id": {
320
+ "type": "UUID",
321
+ "referenceKind": "tenantId",
322
+ "notNull": true,
323
+ "unique": false
324
+ },
325
+ "subscriber_kind": {
326
+ "type": "TEXT",
327
+ "notNull": false,
328
+ "unique": false,
329
+ "default": "tenant"
330
+ },
331
+ "subscriber_external_id": {
332
+ "type": "TEXT",
333
+ "notNull": false,
334
+ "unique": false,
335
+ "default": ""
336
+ },
337
+ "plan_id": {
338
+ "type": "UUID",
339
+ "referenceKind": "foreignKey",
340
+ "notNull": false,
341
+ "unique": false,
342
+ "foreignKey": {
343
+ "table": "_smrt_subscription_plans",
344
+ "column": "id",
345
+ "onDelete": "NO ACTION",
346
+ "onUpdate": "CASCADE"
347
+ }
348
+ },
349
+ "status": {
350
+ "type": "TEXT",
351
+ "notNull": false,
352
+ "unique": false,
353
+ "default": "incomplete"
354
+ },
355
+ "started_at": {
356
+ "type": "TIMESTAMP",
357
+ "notNull": false,
358
+ "unique": false
359
+ },
360
+ "current_period_start": {
361
+ "type": "TIMESTAMP",
362
+ "notNull": false,
363
+ "unique": false
364
+ },
365
+ "current_period_end": {
366
+ "type": "TIMESTAMP",
367
+ "notNull": false,
368
+ "unique": false
369
+ },
370
+ "trial_ends_at": {
371
+ "type": "TIMESTAMP",
372
+ "notNull": false,
373
+ "unique": false
374
+ },
375
+ "cancel_at_period_end": {
376
+ "type": "BOOLEAN",
377
+ "notNull": false,
378
+ "unique": false,
379
+ "default": false
380
+ },
381
+ "canceled_at": {
382
+ "type": "TIMESTAMP",
383
+ "notNull": false,
384
+ "unique": false
385
+ },
386
+ "external_provider": {
387
+ "type": "TEXT",
388
+ "notNull": false,
389
+ "unique": false,
390
+ "default": "stripe"
391
+ },
392
+ "stripe_customer_id": {
393
+ "type": "TEXT",
394
+ "notNull": false,
395
+ "unique": false,
396
+ "default": ""
397
+ },
398
+ "stripe_subscription_id": {
399
+ "type": "TEXT",
400
+ "notNull": false,
401
+ "unique": false,
402
+ "default": ""
403
+ },
404
+ "stripe_checkout_session_id": {
405
+ "type": "TEXT",
406
+ "notNull": false,
407
+ "unique": false,
408
+ "default": ""
409
+ },
410
+ "metadata": {
411
+ "type": "TEXT",
412
+ "notNull": false,
413
+ "unique": false,
414
+ "default": "{}"
220
415
  }
221
416
  },
222
417
  "indexes": [
418
+ {
419
+ "name": "_smrt_tenant_subscriptions_tenant_id_subscriber_kind_idx",
420
+ "columns": [
421
+ "tenant_id",
422
+ "subscriber_kind",
423
+ "subscriber_external_id"
424
+ ],
425
+ "unique": true,
426
+ "nullsNotDistinct": true
427
+ },
223
428
  {
224
429
  "name": "_smrt_tenant_subscriptions_slug_context_idx",
225
430
  "columns": [
226
431
  "slug",
227
432
  "context"
228
- ],
229
- "unique": true
433
+ ]
230
434
  },
231
435
  {
232
- "name": "_smrt_tenant_subscriptions_created_at_idx",
436
+ "name": "_smrt_tenant_subscriptions_tenant_id_created_at_idx",
233
437
  "columns": [
438
+ "tenant_id",
234
439
  "created_at"
235
440
  ]
441
+ },
442
+ {
443
+ "name": "_smrt_tenant_subscriptions_plan_id_idx",
444
+ "columns": [
445
+ "plan_id"
446
+ ]
236
447
  }
237
448
  ],
238
- "version": "1d17f963"
449
+ "version": "ac93fb43"
239
450
  }
240
451
  },
241
452
  "@happyvertical/smrt-subscriptions:TenantUsageMetricCollection": {
@@ -332,7 +543,7 @@
332
543
  "collectionExportName": "TenantUsageMetricCollectionCollection",
333
544
  "schema": {
334
545
  "tableName": "_smrt_tenant_usage_metrics",
335
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_tenant_usage_metrics\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
546
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_tenant_usage_metrics\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID NOT NULL,\n \"subscriber_kind\" TEXT DEFAULT 'tenant',\n \"subscriber_external_id\" TEXT DEFAULT '',\n \"metric_key\" TEXT DEFAULT '',\n \"quantity\" REAL DEFAULT 0,\n \"window_start\" TIMESTAMP,\n \"window_end\" TIMESTAMP,\n \"source\" TEXT DEFAULT '',\n \"source_id\" TEXT DEFAULT '',\n \"project_id\" TEXT DEFAULT '',\n \"work_ref_type\" TEXT DEFAULT '',\n \"work_ref_id\" TEXT DEFAULT '',\n \"provider\" TEXT DEFAULT '',\n \"dimensions\" TEXT DEFAULT '{}'\n);",
336
547
  "columns": {
337
548
  "id": {
338
549
  "type": "UUID",
@@ -358,43 +569,127 @@
358
569
  "type": "TIMESTAMP",
359
570
  "notNull": true,
360
571
  "default": "current_timestamp"
361
- }
362
- },
363
- "indexes": [
364
- {
365
- "name": "_smrt_tenant_usage_metrics_slug_context_idx",
366
- "columns": [
367
- "slug",
368
- "context"
369
- ],
370
- "unique": true
371
572
  },
372
- {
373
- "name": "_smrt_tenant_usage_metrics_created_at_idx",
374
- "columns": [
375
- "created_at"
376
- ]
377
- }
378
- ],
379
- "version": "8617d4ac"
380
- }
381
- },
382
- "@happyvertical/smrt-subscriptions:SubscriptionPlan": {
383
- "name": "subscriptionplan",
384
- "className": "SubscriptionPlan",
385
- "qualifiedName": "@happyvertical/smrt-subscriptions:SubscriptionPlan",
386
- "collection": "subscriptionplans",
387
- "filePath": "/home/runner/work/smrt/smrt/packages/subscriptions/src/models/SubscriptionPlan.ts",
388
- "packageName": "@happyvertical/smrt-subscriptions",
389
- "fields": {
390
- "tenantId": {
391
- "type": "text",
392
- "required": false,
393
- "_meta": {
394
- "sqlType": "UUID",
395
- "nullable": true,
396
- "__tenancy": {
397
- "isTenantIdField": true,
573
+ "tenant_id": {
574
+ "type": "UUID",
575
+ "referenceKind": "tenantId",
576
+ "notNull": true,
577
+ "unique": false
578
+ },
579
+ "subscriber_kind": {
580
+ "type": "TEXT",
581
+ "notNull": false,
582
+ "unique": false,
583
+ "default": "tenant"
584
+ },
585
+ "subscriber_external_id": {
586
+ "type": "TEXT",
587
+ "notNull": false,
588
+ "unique": false,
589
+ "default": ""
590
+ },
591
+ "metric_key": {
592
+ "type": "TEXT",
593
+ "notNull": false,
594
+ "unique": false,
595
+ "default": ""
596
+ },
597
+ "quantity": {
598
+ "type": "REAL",
599
+ "notNull": false,
600
+ "unique": false,
601
+ "default": 0
602
+ },
603
+ "window_start": {
604
+ "type": "TIMESTAMP",
605
+ "notNull": false,
606
+ "unique": false
607
+ },
608
+ "window_end": {
609
+ "type": "TIMESTAMP",
610
+ "notNull": false,
611
+ "unique": false
612
+ },
613
+ "source": {
614
+ "type": "TEXT",
615
+ "notNull": false,
616
+ "unique": false,
617
+ "default": ""
618
+ },
619
+ "source_id": {
620
+ "type": "TEXT",
621
+ "notNull": false,
622
+ "unique": false,
623
+ "default": ""
624
+ },
625
+ "project_id": {
626
+ "type": "TEXT",
627
+ "notNull": false,
628
+ "unique": false,
629
+ "default": ""
630
+ },
631
+ "work_ref_type": {
632
+ "type": "TEXT",
633
+ "notNull": false,
634
+ "unique": false,
635
+ "default": ""
636
+ },
637
+ "work_ref_id": {
638
+ "type": "TEXT",
639
+ "notNull": false,
640
+ "unique": false,
641
+ "default": ""
642
+ },
643
+ "provider": {
644
+ "type": "TEXT",
645
+ "notNull": false,
646
+ "unique": false,
647
+ "default": ""
648
+ },
649
+ "dimensions": {
650
+ "type": "TEXT",
651
+ "notNull": false,
652
+ "unique": false,
653
+ "default": "{}"
654
+ }
655
+ },
656
+ "indexes": [
657
+ {
658
+ "name": "_smrt_tenant_usage_metrics_slug_context_idx",
659
+ "columns": [
660
+ "tenant_id",
661
+ "slug",
662
+ "context"
663
+ ],
664
+ "unique": true
665
+ },
666
+ {
667
+ "name": "_smrt_tenant_usage_metrics_tenant_id_created_at_idx",
668
+ "columns": [
669
+ "tenant_id",
670
+ "created_at"
671
+ ]
672
+ }
673
+ ],
674
+ "version": "b799c746"
675
+ }
676
+ },
677
+ "@happyvertical/smrt-subscriptions:SubscriptionPlan": {
678
+ "name": "subscriptionplan",
679
+ "className": "SubscriptionPlan",
680
+ "qualifiedName": "@happyvertical/smrt-subscriptions:SubscriptionPlan",
681
+ "collection": "subscriptionplans",
682
+ "filePath": "/home/runner/work/smrt/smrt/packages/subscriptions/src/models/SubscriptionPlan.ts",
683
+ "packageName": "@happyvertical/smrt-subscriptions",
684
+ "fields": {
685
+ "tenantId": {
686
+ "type": "text",
687
+ "required": false,
688
+ "_meta": {
689
+ "sqlType": "UUID",
690
+ "nullable": true,
691
+ "__tenancy": {
692
+ "isTenantIdField": true,
398
693
  "autoFilter": true,
399
694
  "required": false,
400
695
  "autoPopulate": true,
@@ -715,7 +1010,8 @@
715
1010
  "columns": [
716
1011
  "plan_key"
717
1012
  ],
718
- "unique": true
1013
+ "unique": true,
1014
+ "nullsNotDistinct": true
719
1015
  },
720
1016
  {
721
1017
  "name": "_smrt_subscription_plans_slug_context_idx",
@@ -1044,7 +1340,8 @@
1044
1340
  "subscriber_kind",
1045
1341
  "subscriber_external_id"
1046
1342
  ],
1047
- "unique": true
1343
+ "unique": true,
1344
+ "nullsNotDistinct": true
1048
1345
  },
1049
1346
  {
1050
1347
  "name": "_smrt_tenant_subscriptions_slug_context_idx",
@@ -1885,7 +2182,8 @@
1885
2182
  "columns": [
1886
2183
  "usage_event_id"
1887
2184
  ],
1888
- "unique": true
2185
+ "unique": true,
2186
+ "nullsNotDistinct": true
1889
2187
  },
1890
2188
  {
1891
2189
  "name": "_smrt_client_charges_slug_context_idx",
@@ -2359,7 +2657,8 @@
2359
2657
  "period",
2360
2658
  "name"
2361
2659
  ],
2362
- "unique": true
2660
+ "unique": true,
2661
+ "nullsNotDistinct": true
2363
2662
  },
2364
2663
  {
2365
2664
  "name": "_smrt_spending_policies_slug_context_idx",
@@ -2397,7 +2696,7 @@
2397
2696
  "collectionExportName": "PricingRuleCollectionCollection",
2398
2697
  "schema": {
2399
2698
  "tableName": "_smrt_pricing_rules",
2400
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_pricing_rules\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
2699
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_pricing_rules\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID NOT NULL,\n \"rule_key\" TEXT DEFAULT '',\n \"metric_key\" TEXT DEFAULT '',\n \"service_key\" TEXT DEFAULT '',\n \"strategy\" TEXT DEFAULT 'fixed_unit',\n \"currency\" TEXT DEFAULT 'USD',\n \"effective_from\" TIMESTAMP,\n \"effective_to\" TIMESTAMP,\n \"priority\" INTEGER DEFAULT 0,\n \"terms\" TEXT DEFAULT '{}',\n \"active\" BOOLEAN DEFAULT TRUE\n);",
2401
2700
  "columns": {
2402
2701
  "id": {
2403
2702
  "type": "UUID",
@@ -2423,25 +2722,91 @@
2423
2722
  "type": "TIMESTAMP",
2424
2723
  "notNull": true,
2425
2724
  "default": "current_timestamp"
2725
+ },
2726
+ "tenant_id": {
2727
+ "type": "UUID",
2728
+ "referenceKind": "tenantId",
2729
+ "notNull": true,
2730
+ "unique": false
2731
+ },
2732
+ "rule_key": {
2733
+ "type": "TEXT",
2734
+ "notNull": false,
2735
+ "unique": false,
2736
+ "default": ""
2737
+ },
2738
+ "metric_key": {
2739
+ "type": "TEXT",
2740
+ "notNull": false,
2741
+ "unique": false,
2742
+ "default": ""
2743
+ },
2744
+ "service_key": {
2745
+ "type": "TEXT",
2746
+ "notNull": false,
2747
+ "unique": false,
2748
+ "default": ""
2749
+ },
2750
+ "strategy": {
2751
+ "type": "TEXT",
2752
+ "notNull": false,
2753
+ "unique": false,
2754
+ "default": "fixed_unit"
2755
+ },
2756
+ "currency": {
2757
+ "type": "TEXT",
2758
+ "notNull": false,
2759
+ "unique": false,
2760
+ "default": "USD"
2761
+ },
2762
+ "effective_from": {
2763
+ "type": "TIMESTAMP",
2764
+ "notNull": false,
2765
+ "unique": false
2766
+ },
2767
+ "effective_to": {
2768
+ "type": "TIMESTAMP",
2769
+ "notNull": false,
2770
+ "unique": false
2771
+ },
2772
+ "priority": {
2773
+ "type": "INTEGER",
2774
+ "notNull": false,
2775
+ "unique": false,
2776
+ "default": 0
2777
+ },
2778
+ "terms": {
2779
+ "type": "TEXT",
2780
+ "notNull": false,
2781
+ "unique": false,
2782
+ "default": "{}"
2783
+ },
2784
+ "active": {
2785
+ "type": "BOOLEAN",
2786
+ "notNull": false,
2787
+ "unique": false,
2788
+ "default": true
2426
2789
  }
2427
2790
  },
2428
2791
  "indexes": [
2429
2792
  {
2430
2793
  "name": "_smrt_pricing_rules_slug_context_idx",
2431
2794
  "columns": [
2795
+ "tenant_id",
2432
2796
  "slug",
2433
2797
  "context"
2434
2798
  ],
2435
2799
  "unique": true
2436
2800
  },
2437
2801
  {
2438
- "name": "_smrt_pricing_rules_created_at_idx",
2802
+ "name": "_smrt_pricing_rules_tenant_id_created_at_idx",
2439
2803
  "columns": [
2804
+ "tenant_id",
2440
2805
  "created_at"
2441
2806
  ]
2442
2807
  }
2443
2808
  ],
2444
- "version": "3fb55a6a"
2809
+ "version": "88642897"
2445
2810
  }
2446
2811
  },
2447
2812
  "@happyvertical/smrt-subscriptions:ClientChargeCollection": {
@@ -2462,7 +2827,7 @@
2462
2827
  "collectionExportName": "ClientChargeCollectionCollection",
2463
2828
  "schema": {
2464
2829
  "tableName": "_smrt_client_charges",
2465
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_client_charges\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
2830
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_client_charges\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID NOT NULL,\n \"usage_event_id\" UUID,\n \"subscriber_kind\" TEXT DEFAULT 'tenant',\n \"subscriber_external_id\" TEXT DEFAULT '',\n \"project_id\" TEXT DEFAULT '',\n \"work_ref_type\" TEXT DEFAULT '',\n \"work_ref_id\" TEXT DEFAULT '',\n \"provider\" TEXT DEFAULT '',\n \"service_key\" TEXT DEFAULT '',\n \"metric_key\" TEXT DEFAULT '',\n \"quantity\" REAL DEFAULT 0,\n \"amount\" INTEGER DEFAULT 0,\n \"currency\" TEXT DEFAULT 'USD',\n \"pricing_rule_id\" UUID,\n \"pricing_snapshot\" TEXT DEFAULT '{}',\n \"status\" TEXT DEFAULT 'draft',\n \"approved_at\" TIMESTAMP\n);",
2466
2831
  "columns": {
2467
2832
  "id": {
2468
2833
  "type": "UUID",
@@ -2488,25 +2853,152 @@
2488
2853
  "type": "TIMESTAMP",
2489
2854
  "notNull": true,
2490
2855
  "default": "current_timestamp"
2856
+ },
2857
+ "tenant_id": {
2858
+ "type": "UUID",
2859
+ "referenceKind": "tenantId",
2860
+ "notNull": true,
2861
+ "unique": false
2862
+ },
2863
+ "usage_event_id": {
2864
+ "type": "UUID",
2865
+ "referenceKind": "foreignKey",
2866
+ "notNull": false,
2867
+ "unique": false,
2868
+ "foreignKey": {
2869
+ "table": "_smrt_tenant_usage_metrics",
2870
+ "column": "id",
2871
+ "onDelete": "CASCADE",
2872
+ "onUpdate": "CASCADE"
2873
+ }
2874
+ },
2875
+ "subscriber_kind": {
2876
+ "type": "TEXT",
2877
+ "notNull": false,
2878
+ "unique": false,
2879
+ "default": "tenant"
2880
+ },
2881
+ "subscriber_external_id": {
2882
+ "type": "TEXT",
2883
+ "notNull": false,
2884
+ "unique": false,
2885
+ "default": ""
2886
+ },
2887
+ "project_id": {
2888
+ "type": "TEXT",
2889
+ "notNull": false,
2890
+ "unique": false,
2891
+ "default": ""
2892
+ },
2893
+ "work_ref_type": {
2894
+ "type": "TEXT",
2895
+ "notNull": false,
2896
+ "unique": false,
2897
+ "default": ""
2898
+ },
2899
+ "work_ref_id": {
2900
+ "type": "TEXT",
2901
+ "notNull": false,
2902
+ "unique": false,
2903
+ "default": ""
2904
+ },
2905
+ "provider": {
2906
+ "type": "TEXT",
2907
+ "notNull": false,
2908
+ "unique": false,
2909
+ "default": ""
2910
+ },
2911
+ "service_key": {
2912
+ "type": "TEXT",
2913
+ "notNull": false,
2914
+ "unique": false,
2915
+ "default": ""
2916
+ },
2917
+ "metric_key": {
2918
+ "type": "TEXT",
2919
+ "notNull": false,
2920
+ "unique": false,
2921
+ "default": ""
2922
+ },
2923
+ "quantity": {
2924
+ "type": "REAL",
2925
+ "notNull": false,
2926
+ "unique": false,
2927
+ "default": 0
2928
+ },
2929
+ "amount": {
2930
+ "type": "INTEGER",
2931
+ "notNull": false,
2932
+ "unique": false,
2933
+ "default": 0
2934
+ },
2935
+ "currency": {
2936
+ "type": "TEXT",
2937
+ "notNull": false,
2938
+ "unique": false,
2939
+ "default": "USD"
2940
+ },
2941
+ "pricing_rule_id": {
2942
+ "type": "UUID",
2943
+ "referenceKind": "foreignKey",
2944
+ "notNull": false,
2945
+ "unique": false,
2946
+ "foreignKey": {
2947
+ "table": "_smrt_pricing_rules",
2948
+ "column": "id",
2949
+ "onDelete": "NO ACTION",
2950
+ "onUpdate": "CASCADE"
2951
+ }
2952
+ },
2953
+ "pricing_snapshot": {
2954
+ "type": "TEXT",
2955
+ "notNull": false,
2956
+ "unique": false,
2957
+ "default": "{}"
2958
+ },
2959
+ "status": {
2960
+ "type": "TEXT",
2961
+ "notNull": false,
2962
+ "unique": false,
2963
+ "default": "draft"
2964
+ },
2965
+ "approved_at": {
2966
+ "type": "TIMESTAMP",
2967
+ "notNull": false,
2968
+ "unique": false
2491
2969
  }
2492
2970
  },
2493
2971
  "indexes": [
2972
+ {
2973
+ "name": "_smrt_client_charges_usage_event_id_idx",
2974
+ "columns": [
2975
+ "usage_event_id"
2976
+ ],
2977
+ "unique": true,
2978
+ "nullsNotDistinct": true
2979
+ },
2494
2980
  {
2495
2981
  "name": "_smrt_client_charges_slug_context_idx",
2496
2982
  "columns": [
2497
2983
  "slug",
2498
2984
  "context"
2499
- ],
2500
- "unique": true
2985
+ ]
2501
2986
  },
2502
2987
  {
2503
- "name": "_smrt_client_charges_created_at_idx",
2988
+ "name": "_smrt_client_charges_tenant_id_created_at_idx",
2504
2989
  "columns": [
2990
+ "tenant_id",
2505
2991
  "created_at"
2506
2992
  ]
2993
+ },
2994
+ {
2995
+ "name": "_smrt_client_charges_pricing_rule_id_idx",
2996
+ "columns": [
2997
+ "pricing_rule_id"
2998
+ ]
2507
2999
  }
2508
3000
  ],
2509
- "version": "96756a5d"
3001
+ "version": "a1a33c54"
2510
3002
  }
2511
3003
  },
2512
3004
  "@happyvertical/smrt-subscriptions:BillingAdjustmentCollection": {
@@ -2527,7 +3019,7 @@
2527
3019
  "collectionExportName": "BillingAdjustmentCollectionCollection",
2528
3020
  "schema": {
2529
3021
  "tableName": "_smrt_billing_adjustments",
2530
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_billing_adjustments\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
3022
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_billing_adjustments\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID NOT NULL,\n \"client_charge_id\" UUID,\n \"amount\" INTEGER DEFAULT 0,\n \"currency\" TEXT DEFAULT 'USD',\n \"reason\" TEXT DEFAULT '',\n \"source\" TEXT DEFAULT '',\n \"source_id\" TEXT DEFAULT '',\n \"created_by\" TEXT DEFAULT ''\n);",
2531
3023
  "columns": {
2532
3024
  "id": {
2533
3025
  "type": "UUID",
@@ -2553,25 +3045,87 @@
2553
3045
  "type": "TIMESTAMP",
2554
3046
  "notNull": true,
2555
3047
  "default": "current_timestamp"
3048
+ },
3049
+ "tenant_id": {
3050
+ "type": "UUID",
3051
+ "referenceKind": "tenantId",
3052
+ "notNull": true,
3053
+ "unique": false
3054
+ },
3055
+ "client_charge_id": {
3056
+ "type": "UUID",
3057
+ "referenceKind": "foreignKey",
3058
+ "notNull": false,
3059
+ "unique": false,
3060
+ "foreignKey": {
3061
+ "table": "_smrt_client_charges",
3062
+ "column": "id",
3063
+ "onDelete": "NO ACTION",
3064
+ "onUpdate": "CASCADE"
3065
+ }
3066
+ },
3067
+ "amount": {
3068
+ "type": "INTEGER",
3069
+ "notNull": false,
3070
+ "unique": false,
3071
+ "default": 0
3072
+ },
3073
+ "currency": {
3074
+ "type": "TEXT",
3075
+ "notNull": false,
3076
+ "unique": false,
3077
+ "default": "USD"
3078
+ },
3079
+ "reason": {
3080
+ "type": "TEXT",
3081
+ "notNull": false,
3082
+ "unique": false,
3083
+ "default": ""
3084
+ },
3085
+ "source": {
3086
+ "type": "TEXT",
3087
+ "notNull": false,
3088
+ "unique": false,
3089
+ "default": ""
3090
+ },
3091
+ "source_id": {
3092
+ "type": "TEXT",
3093
+ "notNull": false,
3094
+ "unique": false,
3095
+ "default": ""
3096
+ },
3097
+ "created_by": {
3098
+ "type": "TEXT",
3099
+ "notNull": false,
3100
+ "unique": false,
3101
+ "default": ""
2556
3102
  }
2557
3103
  },
2558
3104
  "indexes": [
2559
3105
  {
2560
3106
  "name": "_smrt_billing_adjustments_slug_context_idx",
2561
3107
  "columns": [
3108
+ "tenant_id",
2562
3109
  "slug",
2563
3110
  "context"
2564
3111
  ],
2565
3112
  "unique": true
2566
3113
  },
2567
3114
  {
2568
- "name": "_smrt_billing_adjustments_created_at_idx",
3115
+ "name": "_smrt_billing_adjustments_tenant_id_created_at_idx",
2569
3116
  "columns": [
3117
+ "tenant_id",
2570
3118
  "created_at"
2571
3119
  ]
3120
+ },
3121
+ {
3122
+ "name": "_smrt_billing_adjustments_client_charge_id_idx",
3123
+ "columns": [
3124
+ "client_charge_id"
3125
+ ]
2572
3126
  }
2573
3127
  ],
2574
- "version": "5ca89c74"
3128
+ "version": "cded0b52"
2575
3129
  }
2576
3130
  },
2577
3131
  "@happyvertical/smrt-subscriptions:SpendingPolicyCollection": {
@@ -2592,7 +3146,7 @@
2592
3146
  "collectionExportName": "SpendingPolicyCollectionCollection",
2593
3147
  "schema": {
2594
3148
  "tableName": "_smrt_spending_policies",
2595
- "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_spending_policies\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp\n);",
3149
+ "ddl": "CREATE TABLE IF NOT EXISTS \"_smrt_spending_policies\" (\n \"id\" UUID PRIMARY KEY NOT NULL,\n \"slug\" TEXT NOT NULL,\n \"context\" TEXT NOT NULL DEFAULT '',\n \"created_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"updated_at\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\n \"tenant_id\" UUID NOT NULL,\n \"name\" TEXT DEFAULT '',\n \"subscriber_kind\" TEXT DEFAULT '',\n \"subscriber_external_id\" TEXT DEFAULT '',\n \"project_id\" TEXT DEFAULT '',\n \"service_key\" TEXT DEFAULT '',\n \"metric_key\" TEXT DEFAULT '',\n \"period\" TEXT DEFAULT 'month',\n \"rolling_seconds\" INTEGER DEFAULT 0,\n \"limit_amount\" INTEGER DEFAULT 0,\n \"currency\" TEXT DEFAULT 'USD',\n \"behavior\" TEXT DEFAULT 'observe',\n \"priority\" INTEGER DEFAULT 0,\n \"active\" BOOLEAN DEFAULT TRUE\n);",
2596
3150
  "columns": {
2597
3151
  "id": {
2598
3152
  "type": "UUID",
@@ -2618,25 +3172,124 @@
2618
3172
  "type": "TIMESTAMP",
2619
3173
  "notNull": true,
2620
3174
  "default": "current_timestamp"
3175
+ },
3176
+ "tenant_id": {
3177
+ "type": "UUID",
3178
+ "referenceKind": "tenantId",
3179
+ "notNull": true,
3180
+ "unique": false
3181
+ },
3182
+ "name": {
3183
+ "type": "TEXT",
3184
+ "notNull": false,
3185
+ "unique": false,
3186
+ "default": ""
3187
+ },
3188
+ "subscriber_kind": {
3189
+ "type": "TEXT",
3190
+ "notNull": false,
3191
+ "unique": false,
3192
+ "default": ""
3193
+ },
3194
+ "subscriber_external_id": {
3195
+ "type": "TEXT",
3196
+ "notNull": false,
3197
+ "unique": false,
3198
+ "default": ""
3199
+ },
3200
+ "project_id": {
3201
+ "type": "TEXT",
3202
+ "notNull": false,
3203
+ "unique": false,
3204
+ "default": ""
3205
+ },
3206
+ "service_key": {
3207
+ "type": "TEXT",
3208
+ "notNull": false,
3209
+ "unique": false,
3210
+ "default": ""
3211
+ },
3212
+ "metric_key": {
3213
+ "type": "TEXT",
3214
+ "notNull": false,
3215
+ "unique": false,
3216
+ "default": ""
3217
+ },
3218
+ "period": {
3219
+ "type": "TEXT",
3220
+ "notNull": false,
3221
+ "unique": false,
3222
+ "default": "month"
3223
+ },
3224
+ "rolling_seconds": {
3225
+ "type": "INTEGER",
3226
+ "notNull": false,
3227
+ "unique": false,
3228
+ "default": 0
3229
+ },
3230
+ "limit_amount": {
3231
+ "type": "INTEGER",
3232
+ "notNull": false,
3233
+ "unique": false,
3234
+ "default": 0
3235
+ },
3236
+ "currency": {
3237
+ "type": "TEXT",
3238
+ "notNull": false,
3239
+ "unique": false,
3240
+ "default": "USD"
3241
+ },
3242
+ "behavior": {
3243
+ "type": "TEXT",
3244
+ "notNull": false,
3245
+ "unique": false,
3246
+ "default": "observe"
3247
+ },
3248
+ "priority": {
3249
+ "type": "INTEGER",
3250
+ "notNull": false,
3251
+ "unique": false,
3252
+ "default": 0
3253
+ },
3254
+ "active": {
3255
+ "type": "BOOLEAN",
3256
+ "notNull": false,
3257
+ "unique": false,
3258
+ "default": true
2621
3259
  }
2622
3260
  },
2623
3261
  "indexes": [
3262
+ {
3263
+ "name": "_smrt_spending_policies_tenant_id_subscriber_kind_idx",
3264
+ "columns": [
3265
+ "tenant_id",
3266
+ "subscriber_kind",
3267
+ "subscriber_external_id",
3268
+ "project_id",
3269
+ "service_key",
3270
+ "metric_key",
3271
+ "period",
3272
+ "name"
3273
+ ],
3274
+ "unique": true,
3275
+ "nullsNotDistinct": true
3276
+ },
2624
3277
  {
2625
3278
  "name": "_smrt_spending_policies_slug_context_idx",
2626
3279
  "columns": [
2627
3280
  "slug",
2628
3281
  "context"
2629
- ],
2630
- "unique": true
3282
+ ]
2631
3283
  },
2632
3284
  {
2633
- "name": "_smrt_spending_policies_created_at_idx",
3285
+ "name": "_smrt_spending_policies_tenant_id_created_at_idx",
2634
3286
  "columns": [
3287
+ "tenant_id",
2635
3288
  "created_at"
2636
3289
  ]
2637
3290
  }
2638
3291
  ],
2639
- "version": "4f25df0f"
3292
+ "version": "6a413cf4"
2640
3293
  }
2641
3294
  }
2642
3295
  },