stripe-experiment-sync 0.0.4 → 1.0.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.
@@ -0,0 +1,1821 @@
1
+ -- Convert all tables to use jsonb raw_data as source of truth with generated columns
2
+ -- This migration adds raw_data column and converts all existing columns to generated columns
3
+
4
+ -- ============================================================================
5
+ -- ACTIVE_ENTITLEMENTS
6
+ -- ============================================================================
7
+
8
+ -- Add raw_data column
9
+ ALTER TABLE "stripe"."active_entitlements" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
10
+
11
+ -- Drop indexes (will be recreated on generated columns)
12
+ DROP INDEX IF EXISTS "stripe"."stripe_active_entitlements_customer_idx";
13
+ DROP INDEX IF EXISTS "stripe"."stripe_active_entitlements_feature_idx";
14
+
15
+ -- Drop unique constraint (will be recreated on generated column)
16
+ ALTER TABLE "stripe"."active_entitlements" DROP CONSTRAINT IF EXISTS "active_entitlements_lookup_key_key";
17
+
18
+ -- Drop existing columns and recreate as generated columns
19
+ ALTER TABLE "stripe"."active_entitlements" DROP COLUMN IF EXISTS "object";
20
+ ALTER TABLE "stripe"."active_entitlements" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
21
+
22
+ ALTER TABLE "stripe"."active_entitlements" DROP COLUMN IF EXISTS "livemode";
23
+ ALTER TABLE "stripe"."active_entitlements" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
24
+
25
+ ALTER TABLE "stripe"."active_entitlements" DROP COLUMN IF EXISTS "feature";
26
+ ALTER TABLE "stripe"."active_entitlements" ADD COLUMN "feature" text GENERATED ALWAYS AS ((raw_data->>'feature')::text) STORED;
27
+
28
+ ALTER TABLE "stripe"."active_entitlements" DROP COLUMN IF EXISTS "customer";
29
+ ALTER TABLE "stripe"."active_entitlements" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
30
+
31
+ ALTER TABLE "stripe"."active_entitlements" DROP COLUMN IF EXISTS "lookup_key";
32
+ ALTER TABLE "stripe"."active_entitlements" ADD COLUMN "lookup_key" text GENERATED ALWAYS AS ((raw_data->>'lookup_key')::text) STORED;
33
+
34
+ -- Recreate indexes
35
+ CREATE INDEX stripe_active_entitlements_customer_idx ON "stripe"."active_entitlements" USING btree (customer);
36
+ CREATE INDEX stripe_active_entitlements_feature_idx ON "stripe"."active_entitlements" USING btree (feature);
37
+
38
+ -- Recreate unique constraint
39
+ CREATE UNIQUE INDEX active_entitlements_lookup_key_key ON "stripe"."active_entitlements" (lookup_key) WHERE lookup_key IS NOT NULL;
40
+
41
+ -- ============================================================================
42
+ -- CHARGES
43
+ -- ============================================================================
44
+
45
+ ALTER TABLE "stripe"."charges" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
46
+
47
+ -- Drop and recreate columns as generated
48
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "object";
49
+ ALTER TABLE "stripe"."charges" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
50
+
51
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "paid";
52
+ ALTER TABLE "stripe"."charges" ADD COLUMN "paid" boolean GENERATED ALWAYS AS ((raw_data->>'paid')::boolean) STORED;
53
+
54
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "order";
55
+ ALTER TABLE "stripe"."charges" ADD COLUMN "order" text GENERATED ALWAYS AS ((raw_data->>'order')::text) STORED;
56
+
57
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "amount";
58
+ ALTER TABLE "stripe"."charges" ADD COLUMN "amount" bigint GENERATED ALWAYS AS ((raw_data->>'amount')::bigint) STORED;
59
+
60
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "review";
61
+ ALTER TABLE "stripe"."charges" ADD COLUMN "review" text GENERATED ALWAYS AS ((raw_data->>'review')::text) STORED;
62
+
63
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "source";
64
+ ALTER TABLE "stripe"."charges" ADD COLUMN "source" jsonb GENERATED ALWAYS AS (raw_data->'source') STORED;
65
+
66
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "status";
67
+ ALTER TABLE "stripe"."charges" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
68
+
69
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "created";
70
+ ALTER TABLE "stripe"."charges" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
71
+
72
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "dispute";
73
+ ALTER TABLE "stripe"."charges" ADD COLUMN "dispute" text GENERATED ALWAYS AS ((raw_data->>'dispute')::text) STORED;
74
+
75
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "invoice";
76
+ ALTER TABLE "stripe"."charges" ADD COLUMN "invoice" text GENERATED ALWAYS AS ((raw_data->>'invoice')::text) STORED;
77
+
78
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "outcome";
79
+ ALTER TABLE "stripe"."charges" ADD COLUMN "outcome" jsonb GENERATED ALWAYS AS (raw_data->'outcome') STORED;
80
+
81
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "refunds";
82
+ ALTER TABLE "stripe"."charges" ADD COLUMN "refunds" jsonb GENERATED ALWAYS AS (raw_data->'refunds') STORED;
83
+
84
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "updated";
85
+ ALTER TABLE "stripe"."charges" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
86
+
87
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "captured";
88
+ ALTER TABLE "stripe"."charges" ADD COLUMN "captured" boolean GENERATED ALWAYS AS ((raw_data->>'captured')::boolean) STORED;
89
+
90
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "currency";
91
+ ALTER TABLE "stripe"."charges" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
92
+
93
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "customer";
94
+ ALTER TABLE "stripe"."charges" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
95
+
96
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "livemode";
97
+ ALTER TABLE "stripe"."charges" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
98
+
99
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "metadata";
100
+ ALTER TABLE "stripe"."charges" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
101
+
102
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "refunded";
103
+ ALTER TABLE "stripe"."charges" ADD COLUMN "refunded" boolean GENERATED ALWAYS AS ((raw_data->>'refunded')::boolean) STORED;
104
+
105
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "shipping";
106
+ ALTER TABLE "stripe"."charges" ADD COLUMN "shipping" jsonb GENERATED ALWAYS AS (raw_data->'shipping') STORED;
107
+
108
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "application";
109
+ ALTER TABLE "stripe"."charges" ADD COLUMN "application" text GENERATED ALWAYS AS ((raw_data->>'application')::text) STORED;
110
+
111
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "description";
112
+ ALTER TABLE "stripe"."charges" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
113
+
114
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "destination";
115
+ ALTER TABLE "stripe"."charges" ADD COLUMN "destination" text GENERATED ALWAYS AS ((raw_data->>'destination')::text) STORED;
116
+
117
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "failure_code";
118
+ ALTER TABLE "stripe"."charges" ADD COLUMN "failure_code" text GENERATED ALWAYS AS ((raw_data->>'failure_code')::text) STORED;
119
+
120
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "on_behalf_of";
121
+ ALTER TABLE "stripe"."charges" ADD COLUMN "on_behalf_of" text GENERATED ALWAYS AS ((raw_data->>'on_behalf_of')::text) STORED;
122
+
123
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "fraud_details";
124
+ ALTER TABLE "stripe"."charges" ADD COLUMN "fraud_details" jsonb GENERATED ALWAYS AS (raw_data->'fraud_details') STORED;
125
+
126
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "receipt_email";
127
+ ALTER TABLE "stripe"."charges" ADD COLUMN "receipt_email" text GENERATED ALWAYS AS ((raw_data->>'receipt_email')::text) STORED;
128
+
129
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "payment_intent";
130
+ ALTER TABLE "stripe"."charges" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
131
+
132
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "receipt_number";
133
+ ALTER TABLE "stripe"."charges" ADD COLUMN "receipt_number" text GENERATED ALWAYS AS ((raw_data->>'receipt_number')::text) STORED;
134
+
135
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "transfer_group";
136
+ ALTER TABLE "stripe"."charges" ADD COLUMN "transfer_group" text GENERATED ALWAYS AS ((raw_data->>'transfer_group')::text) STORED;
137
+
138
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "amount_refunded";
139
+ ALTER TABLE "stripe"."charges" ADD COLUMN "amount_refunded" bigint GENERATED ALWAYS AS ((raw_data->>'amount_refunded')::bigint) STORED;
140
+
141
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "application_fee";
142
+ ALTER TABLE "stripe"."charges" ADD COLUMN "application_fee" text GENERATED ALWAYS AS ((raw_data->>'application_fee')::text) STORED;
143
+
144
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "failure_message";
145
+ ALTER TABLE "stripe"."charges" ADD COLUMN "failure_message" text GENERATED ALWAYS AS ((raw_data->>'failure_message')::text) STORED;
146
+
147
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "source_transfer";
148
+ ALTER TABLE "stripe"."charges" ADD COLUMN "source_transfer" text GENERATED ALWAYS AS ((raw_data->>'source_transfer')::text) STORED;
149
+
150
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "balance_transaction";
151
+ ALTER TABLE "stripe"."charges" ADD COLUMN "balance_transaction" text GENERATED ALWAYS AS ((raw_data->>'balance_transaction')::text) STORED;
152
+
153
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "statement_descriptor";
154
+ ALTER TABLE "stripe"."charges" ADD COLUMN "statement_descriptor" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor')::text) STORED;
155
+
156
+ ALTER TABLE "stripe"."charges" DROP COLUMN IF EXISTS "payment_method_details";
157
+ ALTER TABLE "stripe"."charges" ADD COLUMN "payment_method_details" jsonb GENERATED ALWAYS AS (raw_data->'payment_method_details') STORED;
158
+
159
+ -- ============================================================================
160
+ -- CHECKOUT_SESSION_LINE_ITEMS
161
+ -- ============================================================================
162
+
163
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
164
+
165
+ -- Drop indexes
166
+ DROP INDEX IF EXISTS "stripe"."stripe_checkout_session_line_items_session_idx";
167
+ DROP INDEX IF EXISTS "stripe"."stripe_checkout_session_line_items_price_idx";
168
+
169
+ -- Drop and recreate columns as generated
170
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "object";
171
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
172
+
173
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "amount_discount";
174
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "amount_discount" integer GENERATED ALWAYS AS ((raw_data->>'amount_discount')::integer) STORED;
175
+
176
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "amount_subtotal";
177
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "amount_subtotal" integer GENERATED ALWAYS AS ((raw_data->>'amount_subtotal')::integer) STORED;
178
+
179
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "amount_tax";
180
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "amount_tax" integer GENERATED ALWAYS AS ((raw_data->>'amount_tax')::integer) STORED;
181
+
182
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "amount_total";
183
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "amount_total" integer GENERATED ALWAYS AS ((raw_data->>'amount_total')::integer) STORED;
184
+
185
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "currency";
186
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
187
+
188
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "description";
189
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
190
+
191
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "price";
192
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "price" text GENERATED ALWAYS AS ((raw_data->>'price')::text) STORED;
193
+
194
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "quantity";
195
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "quantity" integer GENERATED ALWAYS AS ((raw_data->>'quantity')::integer) STORED;
196
+
197
+ ALTER TABLE "stripe"."checkout_session_line_items" DROP COLUMN IF EXISTS "checkout_session";
198
+ ALTER TABLE "stripe"."checkout_session_line_items" ADD COLUMN "checkout_session" text GENERATED ALWAYS AS ((raw_data->>'checkout_session')::text) STORED;
199
+
200
+ -- Recreate indexes
201
+ CREATE INDEX stripe_checkout_session_line_items_session_idx ON "stripe"."checkout_session_line_items" USING btree (checkout_session);
202
+ CREATE INDEX stripe_checkout_session_line_items_price_idx ON "stripe"."checkout_session_line_items" USING btree (price);
203
+
204
+ -- ============================================================================
205
+ -- CHECKOUT_SESSIONS
206
+ -- ============================================================================
207
+
208
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
209
+
210
+ -- Drop indexes
211
+ DROP INDEX IF EXISTS "stripe"."stripe_checkout_sessions_customer_idx";
212
+ DROP INDEX IF EXISTS "stripe"."stripe_checkout_sessions_subscription_idx";
213
+ DROP INDEX IF EXISTS "stripe"."stripe_checkout_sessions_payment_intent_idx";
214
+ DROP INDEX IF EXISTS "stripe"."stripe_checkout_sessions_invoice_idx";
215
+
216
+ -- Drop and recreate columns as generated (all columns from checkoutSessionSchema)
217
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "object";
218
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
219
+
220
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "adaptive_pricing";
221
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "adaptive_pricing" jsonb GENERATED ALWAYS AS (raw_data->'adaptive_pricing') STORED;
222
+
223
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "after_expiration";
224
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "after_expiration" jsonb GENERATED ALWAYS AS (raw_data->'after_expiration') STORED;
225
+
226
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "allow_promotion_codes";
227
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "allow_promotion_codes" boolean GENERATED ALWAYS AS ((raw_data->>'allow_promotion_codes')::boolean) STORED;
228
+
229
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "amount_subtotal";
230
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "amount_subtotal" integer GENERATED ALWAYS AS ((raw_data->>'amount_subtotal')::integer) STORED;
231
+
232
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "amount_total";
233
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "amount_total" integer GENERATED ALWAYS AS ((raw_data->>'amount_total')::integer) STORED;
234
+
235
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "automatic_tax";
236
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "automatic_tax" jsonb GENERATED ALWAYS AS (raw_data->'automatic_tax') STORED;
237
+
238
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "billing_address_collection";
239
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "billing_address_collection" text GENERATED ALWAYS AS ((raw_data->>'billing_address_collection')::text) STORED;
240
+
241
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "cancel_url";
242
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "cancel_url" text GENERATED ALWAYS AS ((raw_data->>'cancel_url')::text) STORED;
243
+
244
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "client_reference_id";
245
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "client_reference_id" text GENERATED ALWAYS AS ((raw_data->>'client_reference_id')::text) STORED;
246
+
247
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "client_secret";
248
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "client_secret" text GENERATED ALWAYS AS ((raw_data->>'client_secret')::text) STORED;
249
+
250
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "collected_information";
251
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "collected_information" jsonb GENERATED ALWAYS AS (raw_data->'collected_information') STORED;
252
+
253
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "consent";
254
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "consent" jsonb GENERATED ALWAYS AS (raw_data->'consent') STORED;
255
+
256
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "consent_collection";
257
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "consent_collection" jsonb GENERATED ALWAYS AS (raw_data->'consent_collection') STORED;
258
+
259
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "created";
260
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
261
+
262
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "currency";
263
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
264
+
265
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "currency_conversion";
266
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "currency_conversion" jsonb GENERATED ALWAYS AS (raw_data->'currency_conversion') STORED;
267
+
268
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "custom_fields";
269
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "custom_fields" jsonb GENERATED ALWAYS AS (raw_data->'custom_fields') STORED;
270
+
271
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "custom_text";
272
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "custom_text" jsonb GENERATED ALWAYS AS (raw_data->'custom_text') STORED;
273
+
274
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "customer";
275
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
276
+
277
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "customer_creation";
278
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "customer_creation" text GENERATED ALWAYS AS ((raw_data->>'customer_creation')::text) STORED;
279
+
280
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "customer_details";
281
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "customer_details" jsonb GENERATED ALWAYS AS (raw_data->'customer_details') STORED;
282
+
283
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "customer_email";
284
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "customer_email" text GENERATED ALWAYS AS ((raw_data->>'customer_email')::text) STORED;
285
+
286
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "discounts";
287
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "discounts" jsonb GENERATED ALWAYS AS (raw_data->'discounts') STORED;
288
+
289
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "expires_at";
290
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "expires_at" integer GENERATED ALWAYS AS ((raw_data->>'expires_at')::integer) STORED;
291
+
292
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "invoice";
293
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "invoice" text GENERATED ALWAYS AS ((raw_data->>'invoice')::text) STORED;
294
+
295
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "invoice_creation";
296
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "invoice_creation" jsonb GENERATED ALWAYS AS (raw_data->'invoice_creation') STORED;
297
+
298
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "livemode";
299
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
300
+
301
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "locale";
302
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "locale" text GENERATED ALWAYS AS ((raw_data->>'locale')::text) STORED;
303
+
304
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "metadata";
305
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
306
+
307
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "mode";
308
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "mode" text GENERATED ALWAYS AS ((raw_data->>'mode')::text) STORED;
309
+
310
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "optional_items";
311
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "optional_items" jsonb GENERATED ALWAYS AS (raw_data->'optional_items') STORED;
312
+
313
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_intent";
314
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
315
+
316
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_link";
317
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_link" text GENERATED ALWAYS AS ((raw_data->>'payment_link')::text) STORED;
318
+
319
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_method_collection";
320
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_method_collection" text GENERATED ALWAYS AS ((raw_data->>'payment_method_collection')::text) STORED;
321
+
322
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_method_configuration_details";
323
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_method_configuration_details" jsonb GENERATED ALWAYS AS (raw_data->'payment_method_configuration_details') STORED;
324
+
325
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_method_options";
326
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_method_options" jsonb GENERATED ALWAYS AS (raw_data->'payment_method_options') STORED;
327
+
328
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_method_types";
329
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_method_types" jsonb GENERATED ALWAYS AS (raw_data->'payment_method_types') STORED;
330
+
331
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "payment_status";
332
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "payment_status" text GENERATED ALWAYS AS ((raw_data->>'payment_status')::text) STORED;
333
+
334
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "permissions";
335
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "permissions" jsonb GENERATED ALWAYS AS (raw_data->'permissions') STORED;
336
+
337
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "phone_number_collection";
338
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "phone_number_collection" jsonb GENERATED ALWAYS AS (raw_data->'phone_number_collection') STORED;
339
+
340
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "presentment_details";
341
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "presentment_details" jsonb GENERATED ALWAYS AS (raw_data->'presentment_details') STORED;
342
+
343
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "recovered_from";
344
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "recovered_from" text GENERATED ALWAYS AS ((raw_data->>'recovered_from')::text) STORED;
345
+
346
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "redirect_on_completion";
347
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "redirect_on_completion" text GENERATED ALWAYS AS ((raw_data->>'redirect_on_completion')::text) STORED;
348
+
349
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "return_url";
350
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "return_url" text GENERATED ALWAYS AS ((raw_data->>'return_url')::text) STORED;
351
+
352
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "saved_payment_method_options";
353
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "saved_payment_method_options" jsonb GENERATED ALWAYS AS (raw_data->'saved_payment_method_options') STORED;
354
+
355
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "setup_intent";
356
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "setup_intent" text GENERATED ALWAYS AS ((raw_data->>'setup_intent')::text) STORED;
357
+
358
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "shipping_address_collection";
359
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "shipping_address_collection" jsonb GENERATED ALWAYS AS (raw_data->'shipping_address_collection') STORED;
360
+
361
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "shipping_cost";
362
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "shipping_cost" jsonb GENERATED ALWAYS AS (raw_data->'shipping_cost') STORED;
363
+
364
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "shipping_details";
365
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "shipping_details" jsonb GENERATED ALWAYS AS (raw_data->'shipping_details') STORED;
366
+
367
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "shipping_options";
368
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "shipping_options" jsonb GENERATED ALWAYS AS (raw_data->'shipping_options') STORED;
369
+
370
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "status";
371
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
372
+
373
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "submit_type";
374
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "submit_type" text GENERATED ALWAYS AS ((raw_data->>'submit_type')::text) STORED;
375
+
376
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "subscription";
377
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "subscription" text GENERATED ALWAYS AS ((raw_data->>'subscription')::text) STORED;
378
+
379
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "success_url";
380
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "success_url" text GENERATED ALWAYS AS ((raw_data->>'success_url')::text) STORED;
381
+
382
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "tax_id_collection";
383
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "tax_id_collection" jsonb GENERATED ALWAYS AS (raw_data->'tax_id_collection') STORED;
384
+
385
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "total_details";
386
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "total_details" jsonb GENERATED ALWAYS AS (raw_data->'total_details') STORED;
387
+
388
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "ui_mode";
389
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "ui_mode" text GENERATED ALWAYS AS ((raw_data->>'ui_mode')::text) STORED;
390
+
391
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "url";
392
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "url" text GENERATED ALWAYS AS ((raw_data->>'url')::text) STORED;
393
+
394
+ ALTER TABLE "stripe"."checkout_sessions" DROP COLUMN IF EXISTS "wallet_options";
395
+ ALTER TABLE "stripe"."checkout_sessions" ADD COLUMN "wallet_options" jsonb GENERATED ALWAYS AS (raw_data->'wallet_options') STORED;
396
+
397
+ -- Recreate indexes
398
+ CREATE INDEX stripe_checkout_sessions_customer_idx ON "stripe"."checkout_sessions" USING btree (customer);
399
+ CREATE INDEX stripe_checkout_sessions_subscription_idx ON "stripe"."checkout_sessions" USING btree (subscription);
400
+ CREATE INDEX stripe_checkout_sessions_payment_intent_idx ON "stripe"."checkout_sessions" USING btree (payment_intent);
401
+ CREATE INDEX stripe_checkout_sessions_invoice_idx ON "stripe"."checkout_sessions" USING btree (invoice);
402
+
403
+ -- ============================================================================
404
+ -- COUPONS
405
+ -- ============================================================================
406
+
407
+ ALTER TABLE "stripe"."coupons" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
408
+
409
+ -- Drop and recreate columns as generated
410
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "object";
411
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
412
+
413
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "name";
414
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "name" text GENERATED ALWAYS AS ((raw_data->>'name')::text) STORED;
415
+
416
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "valid";
417
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "valid" boolean GENERATED ALWAYS AS ((raw_data->>'valid')::boolean) STORED;
418
+
419
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "created";
420
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
421
+
422
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "updated";
423
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
424
+
425
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "currency";
426
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
427
+
428
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "duration";
429
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "duration" text GENERATED ALWAYS AS ((raw_data->>'duration')::text) STORED;
430
+
431
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "livemode";
432
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
433
+
434
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "metadata";
435
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
436
+
437
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "redeem_by";
438
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "redeem_by" integer GENERATED ALWAYS AS ((raw_data->>'redeem_by')::integer) STORED;
439
+
440
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "amount_off";
441
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "amount_off" bigint GENERATED ALWAYS AS ((raw_data->>'amount_off')::bigint) STORED;
442
+
443
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "percent_off";
444
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "percent_off" double precision GENERATED ALWAYS AS ((raw_data->>'percent_off')::double precision) STORED;
445
+
446
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "times_redeemed";
447
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "times_redeemed" bigint GENERATED ALWAYS AS ((raw_data->>'times_redeemed')::bigint) STORED;
448
+
449
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "max_redemptions";
450
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "max_redemptions" bigint GENERATED ALWAYS AS ((raw_data->>'max_redemptions')::bigint) STORED;
451
+
452
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "duration_in_months";
453
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "duration_in_months" bigint GENERATED ALWAYS AS ((raw_data->>'duration_in_months')::bigint) STORED;
454
+
455
+ ALTER TABLE "stripe"."coupons" DROP COLUMN IF EXISTS "percent_off_precise";
456
+ ALTER TABLE "stripe"."coupons" ADD COLUMN "percent_off_precise" double precision GENERATED ALWAYS AS ((raw_data->>'percent_off_precise')::double precision) STORED;
457
+
458
+ -- ============================================================================
459
+ -- CREDIT_NOTES
460
+ -- ============================================================================
461
+
462
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
463
+
464
+ -- Drop indexes
465
+ DROP INDEX IF EXISTS "stripe"."stripe_credit_notes_customer_idx";
466
+ DROP INDEX IF EXISTS "stripe"."stripe_credit_notes_invoice_idx";
467
+
468
+ -- Drop and recreate columns as generated
469
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "object";
470
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
471
+
472
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "amount";
473
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "amount" integer GENERATED ALWAYS AS ((raw_data->>'amount')::integer) STORED;
474
+
475
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "amount_shipping";
476
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "amount_shipping" integer GENERATED ALWAYS AS ((raw_data->>'amount_shipping')::integer) STORED;
477
+
478
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "created";
479
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
480
+
481
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "currency";
482
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
483
+
484
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "customer";
485
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
486
+
487
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "customer_balance_transaction";
488
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "customer_balance_transaction" text GENERATED ALWAYS AS ((raw_data->>'customer_balance_transaction')::text) STORED;
489
+
490
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "discount_amount";
491
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "discount_amount" integer GENERATED ALWAYS AS ((raw_data->>'discount_amount')::integer) STORED;
492
+
493
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "discount_amounts";
494
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "discount_amounts" jsonb GENERATED ALWAYS AS (raw_data->'discount_amounts') STORED;
495
+
496
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "invoice";
497
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "invoice" text GENERATED ALWAYS AS ((raw_data->>'invoice')::text) STORED;
498
+
499
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "lines";
500
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "lines" jsonb GENERATED ALWAYS AS (raw_data->'lines') STORED;
501
+
502
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "livemode";
503
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
504
+
505
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "memo";
506
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "memo" text GENERATED ALWAYS AS ((raw_data->>'memo')::text) STORED;
507
+
508
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "metadata";
509
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
510
+
511
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "number";
512
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "number" text GENERATED ALWAYS AS ((raw_data->>'number')::text) STORED;
513
+
514
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "out_of_band_amount";
515
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "out_of_band_amount" integer GENERATED ALWAYS AS ((raw_data->>'out_of_band_amount')::integer) STORED;
516
+
517
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "pdf";
518
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "pdf" text GENERATED ALWAYS AS ((raw_data->>'pdf')::text) STORED;
519
+
520
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "reason";
521
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "reason" text GENERATED ALWAYS AS ((raw_data->>'reason')::text) STORED;
522
+
523
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "refund";
524
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "refund" text GENERATED ALWAYS AS ((raw_data->>'refund')::text) STORED;
525
+
526
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "shipping_cost";
527
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "shipping_cost" jsonb GENERATED ALWAYS AS (raw_data->'shipping_cost') STORED;
528
+
529
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "status";
530
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
531
+
532
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "subtotal";
533
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "subtotal" integer GENERATED ALWAYS AS ((raw_data->>'subtotal')::integer) STORED;
534
+
535
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "subtotal_excluding_tax";
536
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "subtotal_excluding_tax" integer GENERATED ALWAYS AS ((raw_data->>'subtotal_excluding_tax')::integer) STORED;
537
+
538
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "tax_amounts";
539
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "tax_amounts" jsonb GENERATED ALWAYS AS (raw_data->'tax_amounts') STORED;
540
+
541
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "total";
542
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "total" integer GENERATED ALWAYS AS ((raw_data->>'total')::integer) STORED;
543
+
544
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "total_excluding_tax";
545
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "total_excluding_tax" integer GENERATED ALWAYS AS ((raw_data->>'total_excluding_tax')::integer) STORED;
546
+
547
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "type";
548
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "type" text GENERATED ALWAYS AS ((raw_data->>'type')::text) STORED;
549
+
550
+ ALTER TABLE "stripe"."credit_notes" DROP COLUMN IF EXISTS "voided_at";
551
+ ALTER TABLE "stripe"."credit_notes" ADD COLUMN "voided_at" text GENERATED ALWAYS AS ((raw_data->>'voided_at')::text) STORED;
552
+
553
+ -- Recreate indexes
554
+ CREATE INDEX stripe_credit_notes_customer_idx ON "stripe"."credit_notes" USING btree (customer);
555
+ CREATE INDEX stripe_credit_notes_invoice_idx ON "stripe"."credit_notes" USING btree (invoice);
556
+
557
+ -- ============================================================================
558
+ -- CUSTOMERS
559
+ -- ============================================================================
560
+
561
+ ALTER TABLE "stripe"."customers" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
562
+
563
+ -- Drop and recreate columns as generated
564
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "object";
565
+ ALTER TABLE "stripe"."customers" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
566
+
567
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "address";
568
+ ALTER TABLE "stripe"."customers" ADD COLUMN "address" jsonb GENERATED ALWAYS AS (raw_data->'address') STORED;
569
+
570
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "description";
571
+ ALTER TABLE "stripe"."customers" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
572
+
573
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "email";
574
+ ALTER TABLE "stripe"."customers" ADD COLUMN "email" text GENERATED ALWAYS AS ((raw_data->>'email')::text) STORED;
575
+
576
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "metadata";
577
+ ALTER TABLE "stripe"."customers" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
578
+
579
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "name";
580
+ ALTER TABLE "stripe"."customers" ADD COLUMN "name" text GENERATED ALWAYS AS ((raw_data->>'name')::text) STORED;
581
+
582
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "phone";
583
+ ALTER TABLE "stripe"."customers" ADD COLUMN "phone" text GENERATED ALWAYS AS ((raw_data->>'phone')::text) STORED;
584
+
585
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "shipping";
586
+ ALTER TABLE "stripe"."customers" ADD COLUMN "shipping" jsonb GENERATED ALWAYS AS (raw_data->'shipping') STORED;
587
+
588
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "balance";
589
+ ALTER TABLE "stripe"."customers" ADD COLUMN "balance" integer GENERATED ALWAYS AS ((raw_data->>'balance')::integer) STORED;
590
+
591
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "created";
592
+ ALTER TABLE "stripe"."customers" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
593
+
594
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "currency";
595
+ ALTER TABLE "stripe"."customers" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
596
+
597
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "default_source";
598
+ ALTER TABLE "stripe"."customers" ADD COLUMN "default_source" text GENERATED ALWAYS AS ((raw_data->>'default_source')::text) STORED;
599
+
600
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "delinquent";
601
+ ALTER TABLE "stripe"."customers" ADD COLUMN "delinquent" boolean GENERATED ALWAYS AS ((raw_data->>'delinquent')::boolean) STORED;
602
+
603
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "discount";
604
+ ALTER TABLE "stripe"."customers" ADD COLUMN "discount" jsonb GENERATED ALWAYS AS (raw_data->'discount') STORED;
605
+
606
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "invoice_prefix";
607
+ ALTER TABLE "stripe"."customers" ADD COLUMN "invoice_prefix" text GENERATED ALWAYS AS ((raw_data->>'invoice_prefix')::text) STORED;
608
+
609
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "invoice_settings";
610
+ ALTER TABLE "stripe"."customers" ADD COLUMN "invoice_settings" jsonb GENERATED ALWAYS AS (raw_data->'invoice_settings') STORED;
611
+
612
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "livemode";
613
+ ALTER TABLE "stripe"."customers" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
614
+
615
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "next_invoice_sequence";
616
+ ALTER TABLE "stripe"."customers" ADD COLUMN "next_invoice_sequence" integer GENERATED ALWAYS AS ((raw_data->>'next_invoice_sequence')::integer) STORED;
617
+
618
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "preferred_locales";
619
+ ALTER TABLE "stripe"."customers" ADD COLUMN "preferred_locales" jsonb GENERATED ALWAYS AS (raw_data->'preferred_locales') STORED;
620
+
621
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "tax_exempt";
622
+ ALTER TABLE "stripe"."customers" ADD COLUMN "tax_exempt" text GENERATED ALWAYS AS ((raw_data->>'tax_exempt')::text) STORED;
623
+
624
+ ALTER TABLE "stripe"."customers" DROP COLUMN IF EXISTS "deleted";
625
+ ALTER TABLE "stripe"."customers" ADD COLUMN "deleted" boolean GENERATED ALWAYS AS ((raw_data->>'deleted')::boolean) STORED;
626
+
627
+ -- ============================================================================
628
+ -- DISPUTES
629
+ -- ============================================================================
630
+
631
+ ALTER TABLE "stripe"."disputes" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
632
+
633
+ -- Drop indexes
634
+ DROP INDEX IF EXISTS "stripe"."stripe_dispute_created_idx";
635
+
636
+ -- Drop and recreate columns as generated
637
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "object";
638
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
639
+
640
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "amount";
641
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "amount" bigint GENERATED ALWAYS AS ((raw_data->>'amount')::bigint) STORED;
642
+
643
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "charge";
644
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "charge" text GENERATED ALWAYS AS ((raw_data->>'charge')::text) STORED;
645
+
646
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "reason";
647
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "reason" text GENERATED ALWAYS AS ((raw_data->>'reason')::text) STORED;
648
+
649
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "status";
650
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
651
+
652
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "created";
653
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
654
+
655
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "updated";
656
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
657
+
658
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "currency";
659
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
660
+
661
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "evidence";
662
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "evidence" jsonb GENERATED ALWAYS AS (raw_data->'evidence') STORED;
663
+
664
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "livemode";
665
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
666
+
667
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "metadata";
668
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
669
+
670
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "evidence_details";
671
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "evidence_details" jsonb GENERATED ALWAYS AS (raw_data->'evidence_details') STORED;
672
+
673
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "balance_transactions";
674
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "balance_transactions" jsonb GENERATED ALWAYS AS (raw_data->'balance_transactions') STORED;
675
+
676
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "is_charge_refundable";
677
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "is_charge_refundable" boolean GENERATED ALWAYS AS ((raw_data->>'is_charge_refundable')::boolean) STORED;
678
+
679
+ ALTER TABLE "stripe"."disputes" DROP COLUMN IF EXISTS "payment_intent";
680
+ ALTER TABLE "stripe"."disputes" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
681
+
682
+ -- Recreate indexes
683
+ CREATE INDEX stripe_dispute_created_idx ON "stripe"."disputes" USING btree (created);
684
+
685
+ -- ============================================================================
686
+ -- EARLY_FRAUD_WARNINGS
687
+ -- ============================================================================
688
+
689
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
690
+
691
+ -- Drop indexes
692
+ DROP INDEX IF EXISTS "stripe"."stripe_early_fraud_warnings_charge_idx";
693
+ DROP INDEX IF EXISTS "stripe"."stripe_early_fraud_warnings_payment_intent_idx";
694
+
695
+ -- Drop and recreate columns as generated
696
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "object";
697
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
698
+
699
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "actionable";
700
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "actionable" boolean GENERATED ALWAYS AS ((raw_data->>'actionable')::boolean) STORED;
701
+
702
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "charge";
703
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "charge" text GENERATED ALWAYS AS ((raw_data->>'charge')::text) STORED;
704
+
705
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "created";
706
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
707
+
708
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "fraud_type";
709
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "fraud_type" text GENERATED ALWAYS AS ((raw_data->>'fraud_type')::text) STORED;
710
+
711
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "livemode";
712
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
713
+
714
+ ALTER TABLE "stripe"."early_fraud_warnings" DROP COLUMN IF EXISTS "payment_intent";
715
+ ALTER TABLE "stripe"."early_fraud_warnings" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
716
+
717
+ -- Recreate indexes
718
+ CREATE INDEX stripe_early_fraud_warnings_charge_idx ON "stripe"."early_fraud_warnings" USING btree (charge);
719
+ CREATE INDEX stripe_early_fraud_warnings_payment_intent_idx ON "stripe"."early_fraud_warnings" USING btree (payment_intent);
720
+
721
+ -- ============================================================================
722
+ -- EVENTS
723
+ -- ============================================================================
724
+
725
+ ALTER TABLE "stripe"."events" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
726
+
727
+ -- Drop and recreate columns as generated
728
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "object";
729
+ ALTER TABLE "stripe"."events" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
730
+
731
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "data";
732
+ ALTER TABLE "stripe"."events" ADD COLUMN "data" jsonb GENERATED ALWAYS AS (raw_data->'data') STORED;
733
+
734
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "type";
735
+ ALTER TABLE "stripe"."events" ADD COLUMN "type" text GENERATED ALWAYS AS ((raw_data->>'type')::text) STORED;
736
+
737
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "created";
738
+ ALTER TABLE "stripe"."events" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
739
+
740
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "request";
741
+ ALTER TABLE "stripe"."events" ADD COLUMN "request" text GENERATED ALWAYS AS ((raw_data->>'request')::text) STORED;
742
+
743
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "updated";
744
+ ALTER TABLE "stripe"."events" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
745
+
746
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "livemode";
747
+ ALTER TABLE "stripe"."events" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
748
+
749
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "api_version";
750
+ ALTER TABLE "stripe"."events" ADD COLUMN "api_version" text GENERATED ALWAYS AS ((raw_data->>'api_version')::text) STORED;
751
+
752
+ ALTER TABLE "stripe"."events" DROP COLUMN IF EXISTS "pending_webhooks";
753
+ ALTER TABLE "stripe"."events" ADD COLUMN "pending_webhooks" bigint GENERATED ALWAYS AS ((raw_data->>'pending_webhooks')::bigint) STORED;
754
+
755
+ -- ============================================================================
756
+ -- FEATURES
757
+ -- ============================================================================
758
+
759
+ ALTER TABLE "stripe"."features" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
760
+
761
+ -- Drop unique constraint
762
+ ALTER TABLE "stripe"."features" DROP CONSTRAINT IF EXISTS "features_lookup_key_key";
763
+
764
+ -- Drop and recreate columns as generated
765
+ ALTER TABLE "stripe"."features" DROP COLUMN IF EXISTS "object";
766
+ ALTER TABLE "stripe"."features" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
767
+
768
+ ALTER TABLE "stripe"."features" DROP COLUMN IF EXISTS "livemode";
769
+ ALTER TABLE "stripe"."features" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
770
+
771
+ ALTER TABLE "stripe"."features" DROP COLUMN IF EXISTS "name";
772
+ ALTER TABLE "stripe"."features" ADD COLUMN "name" text GENERATED ALWAYS AS ((raw_data->>'name')::text) STORED;
773
+
774
+ ALTER TABLE "stripe"."features" DROP COLUMN IF EXISTS "lookup_key";
775
+ ALTER TABLE "stripe"."features" ADD COLUMN "lookup_key" text GENERATED ALWAYS AS ((raw_data->>'lookup_key')::text) STORED;
776
+
777
+ ALTER TABLE "stripe"."features" DROP COLUMN IF EXISTS "active";
778
+ ALTER TABLE "stripe"."features" ADD COLUMN "active" boolean GENERATED ALWAYS AS ((raw_data->>'active')::boolean) STORED;
779
+
780
+ ALTER TABLE "stripe"."features" DROP COLUMN IF EXISTS "metadata";
781
+ ALTER TABLE "stripe"."features" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
782
+
783
+ -- Recreate unique constraint
784
+ CREATE UNIQUE INDEX features_lookup_key_key ON "stripe"."features" (lookup_key) WHERE lookup_key IS NOT NULL;
785
+
786
+ -- ============================================================================
787
+ -- INVOICES
788
+ -- ============================================================================
789
+
790
+ ALTER TABLE "stripe"."invoices" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
791
+
792
+ -- Drop indexes
793
+ DROP INDEX IF EXISTS "stripe"."stripe_invoices_customer_idx";
794
+ DROP INDEX IF EXISTS "stripe"."stripe_invoices_subscription_idx";
795
+
796
+ -- Drop and recreate columns as generated (enum status converted to text)
797
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "object";
798
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
799
+
800
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "auto_advance";
801
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "auto_advance" boolean GENERATED ALWAYS AS ((raw_data->>'auto_advance')::boolean) STORED;
802
+
803
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "collection_method";
804
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "collection_method" text GENERATED ALWAYS AS ((raw_data->>'collection_method')::text) STORED;
805
+
806
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "currency";
807
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
808
+
809
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "description";
810
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
811
+
812
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "hosted_invoice_url";
813
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "hosted_invoice_url" text GENERATED ALWAYS AS ((raw_data->>'hosted_invoice_url')::text) STORED;
814
+
815
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "lines";
816
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "lines" jsonb GENERATED ALWAYS AS (raw_data->'lines') STORED;
817
+
818
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "period_end";
819
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "period_end" integer GENERATED ALWAYS AS ((raw_data->>'period_end')::integer) STORED;
820
+
821
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "period_start";
822
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "period_start" integer GENERATED ALWAYS AS ((raw_data->>'period_start')::integer) STORED;
823
+
824
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "status";
825
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
826
+
827
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "total";
828
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "total" bigint GENERATED ALWAYS AS ((raw_data->>'total')::bigint) STORED;
829
+
830
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "account_country";
831
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "account_country" text GENERATED ALWAYS AS ((raw_data->>'account_country')::text) STORED;
832
+
833
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "account_name";
834
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "account_name" text GENERATED ALWAYS AS ((raw_data->>'account_name')::text) STORED;
835
+
836
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "account_tax_ids";
837
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "account_tax_ids" jsonb GENERATED ALWAYS AS (raw_data->'account_tax_ids') STORED;
838
+
839
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "amount_due";
840
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "amount_due" bigint GENERATED ALWAYS AS ((raw_data->>'amount_due')::bigint) STORED;
841
+
842
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "amount_paid";
843
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "amount_paid" bigint GENERATED ALWAYS AS ((raw_data->>'amount_paid')::bigint) STORED;
844
+
845
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "amount_remaining";
846
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "amount_remaining" bigint GENERATED ALWAYS AS ((raw_data->>'amount_remaining')::bigint) STORED;
847
+
848
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "application_fee_amount";
849
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "application_fee_amount" bigint GENERATED ALWAYS AS ((raw_data->>'application_fee_amount')::bigint) STORED;
850
+
851
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "attempt_count";
852
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "attempt_count" integer GENERATED ALWAYS AS ((raw_data->>'attempt_count')::integer) STORED;
853
+
854
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "attempted";
855
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "attempted" boolean GENERATED ALWAYS AS ((raw_data->>'attempted')::boolean) STORED;
856
+
857
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "billing_reason";
858
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "billing_reason" text GENERATED ALWAYS AS ((raw_data->>'billing_reason')::text) STORED;
859
+
860
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "created";
861
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
862
+
863
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "custom_fields";
864
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "custom_fields" jsonb GENERATED ALWAYS AS (raw_data->'custom_fields') STORED;
865
+
866
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_address";
867
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_address" jsonb GENERATED ALWAYS AS (raw_data->'customer_address') STORED;
868
+
869
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_email";
870
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_email" text GENERATED ALWAYS AS ((raw_data->>'customer_email')::text) STORED;
871
+
872
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_name";
873
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_name" text GENERATED ALWAYS AS ((raw_data->>'customer_name')::text) STORED;
874
+
875
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_phone";
876
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_phone" text GENERATED ALWAYS AS ((raw_data->>'customer_phone')::text) STORED;
877
+
878
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_shipping";
879
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_shipping" jsonb GENERATED ALWAYS AS (raw_data->'customer_shipping') STORED;
880
+
881
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_tax_exempt";
882
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_tax_exempt" text GENERATED ALWAYS AS ((raw_data->>'customer_tax_exempt')::text) STORED;
883
+
884
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer_tax_ids";
885
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer_tax_ids" jsonb GENERATED ALWAYS AS (raw_data->'customer_tax_ids') STORED;
886
+
887
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "default_tax_rates";
888
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "default_tax_rates" jsonb GENERATED ALWAYS AS (raw_data->'default_tax_rates') STORED;
889
+
890
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "discount";
891
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "discount" jsonb GENERATED ALWAYS AS (raw_data->'discount') STORED;
892
+
893
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "discounts";
894
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "discounts" jsonb GENERATED ALWAYS AS (raw_data->'discounts') STORED;
895
+
896
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "due_date";
897
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "due_date" integer GENERATED ALWAYS AS ((raw_data->>'due_date')::integer) STORED;
898
+
899
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "ending_balance";
900
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "ending_balance" integer GENERATED ALWAYS AS ((raw_data->>'ending_balance')::integer) STORED;
901
+
902
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "footer";
903
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "footer" text GENERATED ALWAYS AS ((raw_data->>'footer')::text) STORED;
904
+
905
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "invoice_pdf";
906
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "invoice_pdf" text GENERATED ALWAYS AS ((raw_data->>'invoice_pdf')::text) STORED;
907
+
908
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "last_finalization_error";
909
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "last_finalization_error" jsonb GENERATED ALWAYS AS (raw_data->'last_finalization_error') STORED;
910
+
911
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "livemode";
912
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
913
+
914
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "next_payment_attempt";
915
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "next_payment_attempt" integer GENERATED ALWAYS AS ((raw_data->>'next_payment_attempt')::integer) STORED;
916
+
917
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "number";
918
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "number" text GENERATED ALWAYS AS ((raw_data->>'number')::text) STORED;
919
+
920
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "paid";
921
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "paid" boolean GENERATED ALWAYS AS ((raw_data->>'paid')::boolean) STORED;
922
+
923
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "payment_settings";
924
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "payment_settings" jsonb GENERATED ALWAYS AS (raw_data->'payment_settings') STORED;
925
+
926
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "post_payment_credit_notes_amount";
927
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "post_payment_credit_notes_amount" integer GENERATED ALWAYS AS ((raw_data->>'post_payment_credit_notes_amount')::integer) STORED;
928
+
929
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "pre_payment_credit_notes_amount";
930
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "pre_payment_credit_notes_amount" integer GENERATED ALWAYS AS ((raw_data->>'pre_payment_credit_notes_amount')::integer) STORED;
931
+
932
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "receipt_number";
933
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "receipt_number" text GENERATED ALWAYS AS ((raw_data->>'receipt_number')::text) STORED;
934
+
935
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "starting_balance";
936
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "starting_balance" integer GENERATED ALWAYS AS ((raw_data->>'starting_balance')::integer) STORED;
937
+
938
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "statement_descriptor";
939
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "statement_descriptor" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor')::text) STORED;
940
+
941
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "status_transitions";
942
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "status_transitions" jsonb GENERATED ALWAYS AS (raw_data->'status_transitions') STORED;
943
+
944
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "subtotal";
945
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "subtotal" integer GENERATED ALWAYS AS ((raw_data->>'subtotal')::integer) STORED;
946
+
947
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "tax";
948
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "tax" integer GENERATED ALWAYS AS ((raw_data->>'tax')::integer) STORED;
949
+
950
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "total_discount_amounts";
951
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "total_discount_amounts" jsonb GENERATED ALWAYS AS (raw_data->'total_discount_amounts') STORED;
952
+
953
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "total_tax_amounts";
954
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "total_tax_amounts" jsonb GENERATED ALWAYS AS (raw_data->'total_tax_amounts') STORED;
955
+
956
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "transfer_data";
957
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "transfer_data" jsonb GENERATED ALWAYS AS (raw_data->'transfer_data') STORED;
958
+
959
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "webhooks_delivered_at";
960
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "webhooks_delivered_at" integer GENERATED ALWAYS AS ((raw_data->>'webhooks_delivered_at')::integer) STORED;
961
+
962
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "customer";
963
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
964
+
965
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "subscription";
966
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "subscription" text GENERATED ALWAYS AS ((raw_data->>'subscription')::text) STORED;
967
+
968
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "payment_intent";
969
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
970
+
971
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "default_payment_method";
972
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "default_payment_method" text GENERATED ALWAYS AS ((raw_data->>'default_payment_method')::text) STORED;
973
+
974
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "default_source";
975
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "default_source" text GENERATED ALWAYS AS ((raw_data->>'default_source')::text) STORED;
976
+
977
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "on_behalf_of";
978
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "on_behalf_of" text GENERATED ALWAYS AS ((raw_data->>'on_behalf_of')::text) STORED;
979
+
980
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "charge";
981
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "charge" text GENERATED ALWAYS AS ((raw_data->>'charge')::text) STORED;
982
+
983
+ ALTER TABLE "stripe"."invoices" DROP COLUMN IF EXISTS "metadata";
984
+ ALTER TABLE "stripe"."invoices" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
985
+
986
+ -- Recreate indexes
987
+ CREATE INDEX stripe_invoices_customer_idx ON "stripe"."invoices" USING btree (customer);
988
+ CREATE INDEX stripe_invoices_subscription_idx ON "stripe"."invoices" USING btree (subscription);
989
+
990
+ -- ============================================================================
991
+ -- PAYMENT_INTENTS
992
+ -- ============================================================================
993
+
994
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
995
+
996
+ -- Drop indexes
997
+ DROP INDEX IF EXISTS "stripe"."stripe_payment_intents_customer_idx";
998
+ DROP INDEX IF EXISTS "stripe"."stripe_payment_intents_invoice_idx";
999
+
1000
+ -- Drop and recreate columns as generated
1001
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "object";
1002
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1003
+
1004
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "amount";
1005
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "amount" integer GENERATED ALWAYS AS ((raw_data->>'amount')::integer) STORED;
1006
+
1007
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "amount_capturable";
1008
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "amount_capturable" integer GENERATED ALWAYS AS ((raw_data->>'amount_capturable')::integer) STORED;
1009
+
1010
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "amount_details";
1011
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "amount_details" jsonb GENERATED ALWAYS AS (raw_data->'amount_details') STORED;
1012
+
1013
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "amount_received";
1014
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "amount_received" integer GENERATED ALWAYS AS ((raw_data->>'amount_received')::integer) STORED;
1015
+
1016
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "application";
1017
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "application" text GENERATED ALWAYS AS ((raw_data->>'application')::text) STORED;
1018
+
1019
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "application_fee_amount";
1020
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "application_fee_amount" integer GENERATED ALWAYS AS ((raw_data->>'application_fee_amount')::integer) STORED;
1021
+
1022
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "automatic_payment_methods";
1023
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "automatic_payment_methods" text GENERATED ALWAYS AS ((raw_data->>'automatic_payment_methods')::text) STORED;
1024
+
1025
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "canceled_at";
1026
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "canceled_at" integer GENERATED ALWAYS AS ((raw_data->>'canceled_at')::integer) STORED;
1027
+
1028
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "cancellation_reason";
1029
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "cancellation_reason" text GENERATED ALWAYS AS ((raw_data->>'cancellation_reason')::text) STORED;
1030
+
1031
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "capture_method";
1032
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "capture_method" text GENERATED ALWAYS AS ((raw_data->>'capture_method')::text) STORED;
1033
+
1034
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "client_secret";
1035
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "client_secret" text GENERATED ALWAYS AS ((raw_data->>'client_secret')::text) STORED;
1036
+
1037
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "confirmation_method";
1038
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "confirmation_method" text GENERATED ALWAYS AS ((raw_data->>'confirmation_method')::text) STORED;
1039
+
1040
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "created";
1041
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1042
+
1043
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "currency";
1044
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
1045
+
1046
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "customer";
1047
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
1048
+
1049
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "description";
1050
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
1051
+
1052
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "invoice";
1053
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "invoice" text GENERATED ALWAYS AS ((raw_data->>'invoice')::text) STORED;
1054
+
1055
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "last_payment_error";
1056
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "last_payment_error" text GENERATED ALWAYS AS ((raw_data->>'last_payment_error')::text) STORED;
1057
+
1058
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "livemode";
1059
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1060
+
1061
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "metadata";
1062
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1063
+
1064
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "next_action";
1065
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "next_action" text GENERATED ALWAYS AS ((raw_data->>'next_action')::text) STORED;
1066
+
1067
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "on_behalf_of";
1068
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "on_behalf_of" text GENERATED ALWAYS AS ((raw_data->>'on_behalf_of')::text) STORED;
1069
+
1070
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "payment_method";
1071
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "payment_method" text GENERATED ALWAYS AS ((raw_data->>'payment_method')::text) STORED;
1072
+
1073
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "payment_method_options";
1074
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "payment_method_options" jsonb GENERATED ALWAYS AS (raw_data->'payment_method_options') STORED;
1075
+
1076
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "payment_method_types";
1077
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "payment_method_types" jsonb GENERATED ALWAYS AS (raw_data->'payment_method_types') STORED;
1078
+
1079
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "processing";
1080
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "processing" text GENERATED ALWAYS AS ((raw_data->>'processing')::text) STORED;
1081
+
1082
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "receipt_email";
1083
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "receipt_email" text GENERATED ALWAYS AS ((raw_data->>'receipt_email')::text) STORED;
1084
+
1085
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "review";
1086
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "review" text GENERATED ALWAYS AS ((raw_data->>'review')::text) STORED;
1087
+
1088
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "setup_future_usage";
1089
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "setup_future_usage" text GENERATED ALWAYS AS ((raw_data->>'setup_future_usage')::text) STORED;
1090
+
1091
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "shipping";
1092
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "shipping" jsonb GENERATED ALWAYS AS (raw_data->'shipping') STORED;
1093
+
1094
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "statement_descriptor";
1095
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "statement_descriptor" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor')::text) STORED;
1096
+
1097
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "statement_descriptor_suffix";
1098
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "statement_descriptor_suffix" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor_suffix')::text) STORED;
1099
+
1100
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "status";
1101
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
1102
+
1103
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "transfer_data";
1104
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "transfer_data" jsonb GENERATED ALWAYS AS (raw_data->'transfer_data') STORED;
1105
+
1106
+ ALTER TABLE "stripe"."payment_intents" DROP COLUMN IF EXISTS "transfer_group";
1107
+ ALTER TABLE "stripe"."payment_intents" ADD COLUMN "transfer_group" text GENERATED ALWAYS AS ((raw_data->>'transfer_group')::text) STORED;
1108
+
1109
+ -- Recreate indexes
1110
+ CREATE INDEX stripe_payment_intents_customer_idx ON "stripe"."payment_intents" USING btree (customer);
1111
+ CREATE INDEX stripe_payment_intents_invoice_idx ON "stripe"."payment_intents" USING btree (invoice);
1112
+
1113
+ -- ============================================================================
1114
+ -- PAYMENT_METHODS
1115
+ -- ============================================================================
1116
+
1117
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1118
+
1119
+ -- Drop indexes
1120
+ DROP INDEX IF EXISTS "stripe"."stripe_payment_methods_customer_idx";
1121
+
1122
+ -- Drop and recreate columns as generated
1123
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "object";
1124
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1125
+
1126
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "created";
1127
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1128
+
1129
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "customer";
1130
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
1131
+
1132
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "type";
1133
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "type" text GENERATED ALWAYS AS ((raw_data->>'type')::text) STORED;
1134
+
1135
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "billing_details";
1136
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "billing_details" jsonb GENERATED ALWAYS AS (raw_data->'billing_details') STORED;
1137
+
1138
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "metadata";
1139
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1140
+
1141
+ ALTER TABLE "stripe"."payment_methods" DROP COLUMN IF EXISTS "card";
1142
+ ALTER TABLE "stripe"."payment_methods" ADD COLUMN "card" jsonb GENERATED ALWAYS AS (raw_data->'card') STORED;
1143
+
1144
+ -- Recreate indexes
1145
+ CREATE INDEX stripe_payment_methods_customer_idx ON "stripe"."payment_methods" USING btree (customer);
1146
+
1147
+ -- ============================================================================
1148
+ -- PAYOUTS
1149
+ -- ============================================================================
1150
+
1151
+ ALTER TABLE "stripe"."payouts" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1152
+
1153
+ -- Drop and recreate columns as generated
1154
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "object";
1155
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1156
+
1157
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "date";
1158
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "date" text GENERATED ALWAYS AS ((raw_data->>'date')::text) STORED;
1159
+
1160
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "type";
1161
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "type" text GENERATED ALWAYS AS ((raw_data->>'type')::text) STORED;
1162
+
1163
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "amount";
1164
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "amount" bigint GENERATED ALWAYS AS ((raw_data->>'amount')::bigint) STORED;
1165
+
1166
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "method";
1167
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "method" text GENERATED ALWAYS AS ((raw_data->>'method')::text) STORED;
1168
+
1169
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "status";
1170
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
1171
+
1172
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "created";
1173
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1174
+
1175
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "updated";
1176
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
1177
+
1178
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "currency";
1179
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
1180
+
1181
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "livemode";
1182
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1183
+
1184
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "metadata";
1185
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1186
+
1187
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "automatic";
1188
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "automatic" boolean GENERATED ALWAYS AS ((raw_data->>'automatic')::boolean) STORED;
1189
+
1190
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "recipient";
1191
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "recipient" text GENERATED ALWAYS AS ((raw_data->>'recipient')::text) STORED;
1192
+
1193
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "description";
1194
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
1195
+
1196
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "destination";
1197
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "destination" text GENERATED ALWAYS AS ((raw_data->>'destination')::text) STORED;
1198
+
1199
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "source_type";
1200
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "source_type" text GENERATED ALWAYS AS ((raw_data->>'source_type')::text) STORED;
1201
+
1202
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "arrival_date";
1203
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "arrival_date" text GENERATED ALWAYS AS ((raw_data->>'arrival_date')::text) STORED;
1204
+
1205
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "bank_account";
1206
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "bank_account" jsonb GENERATED ALWAYS AS (raw_data->'bank_account') STORED;
1207
+
1208
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "failure_code";
1209
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "failure_code" text GENERATED ALWAYS AS ((raw_data->>'failure_code')::text) STORED;
1210
+
1211
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "transfer_group";
1212
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "transfer_group" text GENERATED ALWAYS AS ((raw_data->>'transfer_group')::text) STORED;
1213
+
1214
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "amount_reversed";
1215
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "amount_reversed" bigint GENERATED ALWAYS AS ((raw_data->>'amount_reversed')::bigint) STORED;
1216
+
1217
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "failure_message";
1218
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "failure_message" text GENERATED ALWAYS AS ((raw_data->>'failure_message')::text) STORED;
1219
+
1220
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "source_transaction";
1221
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "source_transaction" text GENERATED ALWAYS AS ((raw_data->>'source_transaction')::text) STORED;
1222
+
1223
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "balance_transaction";
1224
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "balance_transaction" text GENERATED ALWAYS AS ((raw_data->>'balance_transaction')::text) STORED;
1225
+
1226
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "statement_descriptor";
1227
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "statement_descriptor" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor')::text) STORED;
1228
+
1229
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "statement_description";
1230
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "statement_description" text GENERATED ALWAYS AS ((raw_data->>'statement_description')::text) STORED;
1231
+
1232
+ ALTER TABLE "stripe"."payouts" DROP COLUMN IF EXISTS "failure_balance_transaction";
1233
+ ALTER TABLE "stripe"."payouts" ADD COLUMN "failure_balance_transaction" text GENERATED ALWAYS AS ((raw_data->>'failure_balance_transaction')::text) STORED;
1234
+
1235
+ -- ============================================================================
1236
+ -- PLANS
1237
+ -- ============================================================================
1238
+
1239
+ ALTER TABLE "stripe"."plans" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1240
+
1241
+ -- Drop and recreate columns as generated
1242
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "object";
1243
+ ALTER TABLE "stripe"."plans" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1244
+
1245
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "name";
1246
+ ALTER TABLE "stripe"."plans" ADD COLUMN "name" text GENERATED ALWAYS AS ((raw_data->>'name')::text) STORED;
1247
+
1248
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "tiers";
1249
+ ALTER TABLE "stripe"."plans" ADD COLUMN "tiers" jsonb GENERATED ALWAYS AS (raw_data->'tiers') STORED;
1250
+
1251
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "active";
1252
+ ALTER TABLE "stripe"."plans" ADD COLUMN "active" boolean GENERATED ALWAYS AS ((raw_data->>'active')::boolean) STORED;
1253
+
1254
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "amount";
1255
+ ALTER TABLE "stripe"."plans" ADD COLUMN "amount" bigint GENERATED ALWAYS AS ((raw_data->>'amount')::bigint) STORED;
1256
+
1257
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "created";
1258
+ ALTER TABLE "stripe"."plans" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1259
+
1260
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "product";
1261
+ ALTER TABLE "stripe"."plans" ADD COLUMN "product" text GENERATED ALWAYS AS ((raw_data->>'product')::text) STORED;
1262
+
1263
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "updated";
1264
+ ALTER TABLE "stripe"."plans" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
1265
+
1266
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "currency";
1267
+ ALTER TABLE "stripe"."plans" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
1268
+
1269
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "interval";
1270
+ ALTER TABLE "stripe"."plans" ADD COLUMN "interval" text GENERATED ALWAYS AS ((raw_data->>'interval')::text) STORED;
1271
+
1272
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "livemode";
1273
+ ALTER TABLE "stripe"."plans" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1274
+
1275
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "metadata";
1276
+ ALTER TABLE "stripe"."plans" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1277
+
1278
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "nickname";
1279
+ ALTER TABLE "stripe"."plans" ADD COLUMN "nickname" text GENERATED ALWAYS AS ((raw_data->>'nickname')::text) STORED;
1280
+
1281
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "tiers_mode";
1282
+ ALTER TABLE "stripe"."plans" ADD COLUMN "tiers_mode" text GENERATED ALWAYS AS ((raw_data->>'tiers_mode')::text) STORED;
1283
+
1284
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "usage_type";
1285
+ ALTER TABLE "stripe"."plans" ADD COLUMN "usage_type" text GENERATED ALWAYS AS ((raw_data->>'usage_type')::text) STORED;
1286
+
1287
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "billing_scheme";
1288
+ ALTER TABLE "stripe"."plans" ADD COLUMN "billing_scheme" text GENERATED ALWAYS AS ((raw_data->>'billing_scheme')::text) STORED;
1289
+
1290
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "interval_count";
1291
+ ALTER TABLE "stripe"."plans" ADD COLUMN "interval_count" bigint GENERATED ALWAYS AS ((raw_data->>'interval_count')::bigint) STORED;
1292
+
1293
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "aggregate_usage";
1294
+ ALTER TABLE "stripe"."plans" ADD COLUMN "aggregate_usage" text GENERATED ALWAYS AS ((raw_data->>'aggregate_usage')::text) STORED;
1295
+
1296
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "transform_usage";
1297
+ ALTER TABLE "stripe"."plans" ADD COLUMN "transform_usage" text GENERATED ALWAYS AS ((raw_data->>'transform_usage')::text) STORED;
1298
+
1299
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "trial_period_days";
1300
+ ALTER TABLE "stripe"."plans" ADD COLUMN "trial_period_days" bigint GENERATED ALWAYS AS ((raw_data->>'trial_period_days')::bigint) STORED;
1301
+
1302
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "statement_descriptor";
1303
+ ALTER TABLE "stripe"."plans" ADD COLUMN "statement_descriptor" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor')::text) STORED;
1304
+
1305
+ ALTER TABLE "stripe"."plans" DROP COLUMN IF EXISTS "statement_description";
1306
+ ALTER TABLE "stripe"."plans" ADD COLUMN "statement_description" text GENERATED ALWAYS AS ((raw_data->>'statement_description')::text) STORED;
1307
+
1308
+ -- ============================================================================
1309
+ -- PRICES
1310
+ -- ============================================================================
1311
+
1312
+ ALTER TABLE "stripe"."prices" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1313
+
1314
+ -- Drop and recreate columns as generated (enum types converted to text)
1315
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "object";
1316
+ ALTER TABLE "stripe"."prices" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1317
+
1318
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "active";
1319
+ ALTER TABLE "stripe"."prices" ADD COLUMN "active" boolean GENERATED ALWAYS AS ((raw_data->>'active')::boolean) STORED;
1320
+
1321
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "currency";
1322
+ ALTER TABLE "stripe"."prices" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
1323
+
1324
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "metadata";
1325
+ ALTER TABLE "stripe"."prices" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1326
+
1327
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "nickname";
1328
+ ALTER TABLE "stripe"."prices" ADD COLUMN "nickname" text GENERATED ALWAYS AS ((raw_data->>'nickname')::text) STORED;
1329
+
1330
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "recurring";
1331
+ ALTER TABLE "stripe"."prices" ADD COLUMN "recurring" jsonb GENERATED ALWAYS AS (raw_data->'recurring') STORED;
1332
+
1333
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "type";
1334
+ ALTER TABLE "stripe"."prices" ADD COLUMN "type" text GENERATED ALWAYS AS ((raw_data->>'type')::text) STORED;
1335
+
1336
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "unit_amount";
1337
+ ALTER TABLE "stripe"."prices" ADD COLUMN "unit_amount" integer GENERATED ALWAYS AS ((raw_data->>'unit_amount')::integer) STORED;
1338
+
1339
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "billing_scheme";
1340
+ ALTER TABLE "stripe"."prices" ADD COLUMN "billing_scheme" text GENERATED ALWAYS AS ((raw_data->>'billing_scheme')::text) STORED;
1341
+
1342
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "created";
1343
+ ALTER TABLE "stripe"."prices" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1344
+
1345
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "livemode";
1346
+ ALTER TABLE "stripe"."prices" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1347
+
1348
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "lookup_key";
1349
+ ALTER TABLE "stripe"."prices" ADD COLUMN "lookup_key" text GENERATED ALWAYS AS ((raw_data->>'lookup_key')::text) STORED;
1350
+
1351
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "tiers_mode";
1352
+ ALTER TABLE "stripe"."prices" ADD COLUMN "tiers_mode" text GENERATED ALWAYS AS ((raw_data->>'tiers_mode')::text) STORED;
1353
+
1354
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "transform_quantity";
1355
+ ALTER TABLE "stripe"."prices" ADD COLUMN "transform_quantity" jsonb GENERATED ALWAYS AS (raw_data->'transform_quantity') STORED;
1356
+
1357
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "unit_amount_decimal";
1358
+ ALTER TABLE "stripe"."prices" ADD COLUMN "unit_amount_decimal" text GENERATED ALWAYS AS ((raw_data->>'unit_amount_decimal')::text) STORED;
1359
+
1360
+ ALTER TABLE "stripe"."prices" DROP COLUMN IF EXISTS "product";
1361
+ ALTER TABLE "stripe"."prices" ADD COLUMN "product" text GENERATED ALWAYS AS ((raw_data->>'product')::text) STORED;
1362
+
1363
+ -- ============================================================================
1364
+ -- PRODUCTS
1365
+ -- ============================================================================
1366
+
1367
+ ALTER TABLE "stripe"."products" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1368
+
1369
+ -- Drop and recreate columns as generated
1370
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "object";
1371
+ ALTER TABLE "stripe"."products" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1372
+
1373
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "active";
1374
+ ALTER TABLE "stripe"."products" ADD COLUMN "active" boolean GENERATED ALWAYS AS ((raw_data->>'active')::boolean) STORED;
1375
+
1376
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "default_price";
1377
+ ALTER TABLE "stripe"."products" ADD COLUMN "default_price" text GENERATED ALWAYS AS ((raw_data->>'default_price')::text) STORED;
1378
+
1379
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "description";
1380
+ ALTER TABLE "stripe"."products" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
1381
+
1382
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "metadata";
1383
+ ALTER TABLE "stripe"."products" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1384
+
1385
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "name";
1386
+ ALTER TABLE "stripe"."products" ADD COLUMN "name" text GENERATED ALWAYS AS ((raw_data->>'name')::text) STORED;
1387
+
1388
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "created";
1389
+ ALTER TABLE "stripe"."products" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1390
+
1391
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "images";
1392
+ ALTER TABLE "stripe"."products" ADD COLUMN "images" jsonb GENERATED ALWAYS AS (raw_data->'images') STORED;
1393
+
1394
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "marketing_features";
1395
+ ALTER TABLE "stripe"."products" ADD COLUMN "marketing_features" jsonb GENERATED ALWAYS AS (raw_data->'marketing_features') STORED;
1396
+
1397
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "livemode";
1398
+ ALTER TABLE "stripe"."products" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1399
+
1400
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "package_dimensions";
1401
+ ALTER TABLE "stripe"."products" ADD COLUMN "package_dimensions" jsonb GENERATED ALWAYS AS (raw_data->'package_dimensions') STORED;
1402
+
1403
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "shippable";
1404
+ ALTER TABLE "stripe"."products" ADD COLUMN "shippable" boolean GENERATED ALWAYS AS ((raw_data->>'shippable')::boolean) STORED;
1405
+
1406
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "statement_descriptor";
1407
+ ALTER TABLE "stripe"."products" ADD COLUMN "statement_descriptor" text GENERATED ALWAYS AS ((raw_data->>'statement_descriptor')::text) STORED;
1408
+
1409
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "unit_label";
1410
+ ALTER TABLE "stripe"."products" ADD COLUMN "unit_label" text GENERATED ALWAYS AS ((raw_data->>'unit_label')::text) STORED;
1411
+
1412
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "updated";
1413
+ ALTER TABLE "stripe"."products" ADD COLUMN "updated" integer GENERATED ALWAYS AS ((raw_data->>'updated')::integer) STORED;
1414
+
1415
+ ALTER TABLE "stripe"."products" DROP COLUMN IF EXISTS "url";
1416
+ ALTER TABLE "stripe"."products" ADD COLUMN "url" text GENERATED ALWAYS AS ((raw_data->>'url')::text) STORED;
1417
+
1418
+ -- ============================================================================
1419
+ -- REFUNDS
1420
+ -- ============================================================================
1421
+
1422
+ ALTER TABLE "stripe"."refunds" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1423
+
1424
+ -- Drop indexes
1425
+ DROP INDEX IF EXISTS "stripe"."stripe_refunds_charge_idx";
1426
+ DROP INDEX IF EXISTS "stripe"."stripe_refunds_payment_intent_idx";
1427
+
1428
+ -- Drop and recreate columns as generated
1429
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "object";
1430
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1431
+
1432
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "amount";
1433
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "amount" integer GENERATED ALWAYS AS ((raw_data->>'amount')::integer) STORED;
1434
+
1435
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "balance_transaction";
1436
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "balance_transaction" text GENERATED ALWAYS AS ((raw_data->>'balance_transaction')::text) STORED;
1437
+
1438
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "charge";
1439
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "charge" text GENERATED ALWAYS AS ((raw_data->>'charge')::text) STORED;
1440
+
1441
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "created";
1442
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1443
+
1444
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "currency";
1445
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "currency" text GENERATED ALWAYS AS ((raw_data->>'currency')::text) STORED;
1446
+
1447
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "destination_details";
1448
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "destination_details" jsonb GENERATED ALWAYS AS (raw_data->'destination_details') STORED;
1449
+
1450
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "metadata";
1451
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1452
+
1453
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "payment_intent";
1454
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
1455
+
1456
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "reason";
1457
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "reason" text GENERATED ALWAYS AS ((raw_data->>'reason')::text) STORED;
1458
+
1459
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "receipt_number";
1460
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "receipt_number" text GENERATED ALWAYS AS ((raw_data->>'receipt_number')::text) STORED;
1461
+
1462
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "source_transfer_reversal";
1463
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "source_transfer_reversal" text GENERATED ALWAYS AS ((raw_data->>'source_transfer_reversal')::text) STORED;
1464
+
1465
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "status";
1466
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
1467
+
1468
+ ALTER TABLE "stripe"."refunds" DROP COLUMN IF EXISTS "transfer_reversal";
1469
+ ALTER TABLE "stripe"."refunds" ADD COLUMN "transfer_reversal" text GENERATED ALWAYS AS ((raw_data->>'transfer_reversal')::text) STORED;
1470
+
1471
+ -- Recreate indexes
1472
+ CREATE INDEX stripe_refunds_charge_idx ON "stripe"."refunds" USING btree (charge);
1473
+ CREATE INDEX stripe_refunds_payment_intent_idx ON "stripe"."refunds" USING btree (payment_intent);
1474
+
1475
+ -- ============================================================================
1476
+ -- REVIEWS
1477
+ -- ============================================================================
1478
+
1479
+ ALTER TABLE "stripe"."reviews" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1480
+
1481
+ -- Drop indexes
1482
+ DROP INDEX IF EXISTS "stripe"."stripe_reviews_charge_idx";
1483
+ DROP INDEX IF EXISTS "stripe"."stripe_reviews_payment_intent_idx";
1484
+
1485
+ -- Drop and recreate columns as generated
1486
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "object";
1487
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1488
+
1489
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "billing_zip";
1490
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "billing_zip" text GENERATED ALWAYS AS ((raw_data->>'billing_zip')::text) STORED;
1491
+
1492
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "charge";
1493
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "charge" text GENERATED ALWAYS AS ((raw_data->>'charge')::text) STORED;
1494
+
1495
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "created";
1496
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1497
+
1498
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "closed_reason";
1499
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "closed_reason" text GENERATED ALWAYS AS ((raw_data->>'closed_reason')::text) STORED;
1500
+
1501
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "livemode";
1502
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1503
+
1504
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "ip_address";
1505
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "ip_address" text GENERATED ALWAYS AS ((raw_data->>'ip_address')::text) STORED;
1506
+
1507
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "ip_address_location";
1508
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "ip_address_location" jsonb GENERATED ALWAYS AS (raw_data->'ip_address_location') STORED;
1509
+
1510
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "open";
1511
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "open" boolean GENERATED ALWAYS AS ((raw_data->>'open')::boolean) STORED;
1512
+
1513
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "opened_reason";
1514
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "opened_reason" text GENERATED ALWAYS AS ((raw_data->>'opened_reason')::text) STORED;
1515
+
1516
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "payment_intent";
1517
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "payment_intent" text GENERATED ALWAYS AS ((raw_data->>'payment_intent')::text) STORED;
1518
+
1519
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "reason";
1520
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "reason" text GENERATED ALWAYS AS ((raw_data->>'reason')::text) STORED;
1521
+
1522
+ ALTER TABLE "stripe"."reviews" DROP COLUMN IF EXISTS "session";
1523
+ ALTER TABLE "stripe"."reviews" ADD COLUMN "session" text GENERATED ALWAYS AS ((raw_data->>'session')::text) STORED;
1524
+
1525
+ -- Recreate indexes
1526
+ CREATE INDEX stripe_reviews_charge_idx ON "stripe"."reviews" USING btree (charge);
1527
+ CREATE INDEX stripe_reviews_payment_intent_idx ON "stripe"."reviews" USING btree (payment_intent);
1528
+
1529
+ -- ============================================================================
1530
+ -- SETUP_INTENTS
1531
+ -- ============================================================================
1532
+
1533
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1534
+
1535
+ -- Drop indexes
1536
+ DROP INDEX IF EXISTS "stripe"."stripe_setup_intents_customer_idx";
1537
+
1538
+ -- Drop and recreate columns as generated
1539
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "object";
1540
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1541
+
1542
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "created";
1543
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1544
+
1545
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "customer";
1546
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
1547
+
1548
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "description";
1549
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "description" text GENERATED ALWAYS AS ((raw_data->>'description')::text) STORED;
1550
+
1551
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "payment_method";
1552
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "payment_method" text GENERATED ALWAYS AS ((raw_data->>'payment_method')::text) STORED;
1553
+
1554
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "status";
1555
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
1556
+
1557
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "usage";
1558
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "usage" text GENERATED ALWAYS AS ((raw_data->>'usage')::text) STORED;
1559
+
1560
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "cancellation_reason";
1561
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "cancellation_reason" text GENERATED ALWAYS AS ((raw_data->>'cancellation_reason')::text) STORED;
1562
+
1563
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "latest_attempt";
1564
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "latest_attempt" text GENERATED ALWAYS AS ((raw_data->>'latest_attempt')::text) STORED;
1565
+
1566
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "mandate";
1567
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "mandate" text GENERATED ALWAYS AS ((raw_data->>'mandate')::text) STORED;
1568
+
1569
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "single_use_mandate";
1570
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "single_use_mandate" text GENERATED ALWAYS AS ((raw_data->>'single_use_mandate')::text) STORED;
1571
+
1572
+ ALTER TABLE "stripe"."setup_intents" DROP COLUMN IF EXISTS "on_behalf_of";
1573
+ ALTER TABLE "stripe"."setup_intents" ADD COLUMN "on_behalf_of" text GENERATED ALWAYS AS ((raw_data->>'on_behalf_of')::text) STORED;
1574
+
1575
+ -- Recreate indexes
1576
+ CREATE INDEX stripe_setup_intents_customer_idx ON "stripe"."setup_intents" USING btree (customer);
1577
+
1578
+ -- ============================================================================
1579
+ -- SUBSCRIPTION_ITEMS
1580
+ -- ============================================================================
1581
+
1582
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1583
+
1584
+ -- Drop and recreate columns as generated
1585
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "object";
1586
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1587
+
1588
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "billing_thresholds";
1589
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "billing_thresholds" jsonb GENERATED ALWAYS AS (raw_data->'billing_thresholds') STORED;
1590
+
1591
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "created";
1592
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1593
+
1594
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "deleted";
1595
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "deleted" boolean GENERATED ALWAYS AS ((raw_data->>'deleted')::boolean) STORED;
1596
+
1597
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "metadata";
1598
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1599
+
1600
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "quantity";
1601
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "quantity" integer GENERATED ALWAYS AS ((raw_data->>'quantity')::integer) STORED;
1602
+
1603
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "price";
1604
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "price" text GENERATED ALWAYS AS ((raw_data->>'price')::text) STORED;
1605
+
1606
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "subscription";
1607
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "subscription" text GENERATED ALWAYS AS ((raw_data->>'subscription')::text) STORED;
1608
+
1609
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "tax_rates";
1610
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "tax_rates" jsonb GENERATED ALWAYS AS (raw_data->'tax_rates') STORED;
1611
+
1612
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "current_period_end";
1613
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "current_period_end" integer GENERATED ALWAYS AS ((raw_data->>'current_period_end')::integer) STORED;
1614
+
1615
+ ALTER TABLE "stripe"."subscription_items" DROP COLUMN IF EXISTS "current_period_start";
1616
+ ALTER TABLE "stripe"."subscription_items" ADD COLUMN "current_period_start" integer GENERATED ALWAYS AS ((raw_data->>'current_period_start')::integer) STORED;
1617
+
1618
+ -- ============================================================================
1619
+ -- SUBSCRIPTION_SCHEDULES
1620
+ -- ============================================================================
1621
+
1622
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1623
+
1624
+ -- Drop and recreate columns as generated (enum status converted to text)
1625
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "object";
1626
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1627
+
1628
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "application";
1629
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "application" text GENERATED ALWAYS AS ((raw_data->>'application')::text) STORED;
1630
+
1631
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "canceled_at";
1632
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "canceled_at" integer GENERATED ALWAYS AS ((raw_data->>'canceled_at')::integer) STORED;
1633
+
1634
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "completed_at";
1635
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "completed_at" integer GENERATED ALWAYS AS ((raw_data->>'completed_at')::integer) STORED;
1636
+
1637
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "created";
1638
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1639
+
1640
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "current_phase";
1641
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "current_phase" jsonb GENERATED ALWAYS AS (raw_data->'current_phase') STORED;
1642
+
1643
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "customer";
1644
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
1645
+
1646
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "default_settings";
1647
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "default_settings" jsonb GENERATED ALWAYS AS (raw_data->'default_settings') STORED;
1648
+
1649
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "end_behavior";
1650
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "end_behavior" text GENERATED ALWAYS AS ((raw_data->>'end_behavior')::text) STORED;
1651
+
1652
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "livemode";
1653
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1654
+
1655
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "metadata";
1656
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1657
+
1658
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "phases";
1659
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "phases" jsonb GENERATED ALWAYS AS (raw_data->'phases') STORED;
1660
+
1661
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "released_at";
1662
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "released_at" integer GENERATED ALWAYS AS ((raw_data->>'released_at')::integer) STORED;
1663
+
1664
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "released_subscription";
1665
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "released_subscription" text GENERATED ALWAYS AS ((raw_data->>'released_subscription')::text) STORED;
1666
+
1667
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "status";
1668
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
1669
+
1670
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "subscription";
1671
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "subscription" text GENERATED ALWAYS AS ((raw_data->>'subscription')::text) STORED;
1672
+
1673
+ ALTER TABLE "stripe"."subscription_schedules" DROP COLUMN IF EXISTS "test_clock";
1674
+ ALTER TABLE "stripe"."subscription_schedules" ADD COLUMN "test_clock" text GENERATED ALWAYS AS ((raw_data->>'test_clock')::text) STORED;
1675
+
1676
+ -- ============================================================================
1677
+ -- SUBSCRIPTIONS
1678
+ -- ============================================================================
1679
+
1680
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1681
+
1682
+ -- Drop and recreate columns as generated (enum status converted to text)
1683
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "object";
1684
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1685
+
1686
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "cancel_at_period_end";
1687
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "cancel_at_period_end" boolean GENERATED ALWAYS AS ((raw_data->>'cancel_at_period_end')::boolean) STORED;
1688
+
1689
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "current_period_end";
1690
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "current_period_end" integer GENERATED ALWAYS AS ((raw_data->>'current_period_end')::integer) STORED;
1691
+
1692
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "current_period_start";
1693
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "current_period_start" integer GENERATED ALWAYS AS ((raw_data->>'current_period_start')::integer) STORED;
1694
+
1695
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "default_payment_method";
1696
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "default_payment_method" text GENERATED ALWAYS AS ((raw_data->>'default_payment_method')::text) STORED;
1697
+
1698
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "items";
1699
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "items" jsonb GENERATED ALWAYS AS (raw_data->'items') STORED;
1700
+
1701
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "metadata";
1702
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "metadata" jsonb GENERATED ALWAYS AS (raw_data->'metadata') STORED;
1703
+
1704
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "pending_setup_intent";
1705
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "pending_setup_intent" text GENERATED ALWAYS AS ((raw_data->>'pending_setup_intent')::text) STORED;
1706
+
1707
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "pending_update";
1708
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "pending_update" jsonb GENERATED ALWAYS AS (raw_data->'pending_update') STORED;
1709
+
1710
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "status";
1711
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "status" text GENERATED ALWAYS AS ((raw_data->>'status')::text) STORED;
1712
+
1713
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "application_fee_percent";
1714
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "application_fee_percent" double precision GENERATED ALWAYS AS ((raw_data->>'application_fee_percent')::double precision) STORED;
1715
+
1716
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "billing_cycle_anchor";
1717
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "billing_cycle_anchor" integer GENERATED ALWAYS AS ((raw_data->>'billing_cycle_anchor')::integer) STORED;
1718
+
1719
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "billing_thresholds";
1720
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "billing_thresholds" jsonb GENERATED ALWAYS AS (raw_data->'billing_thresholds') STORED;
1721
+
1722
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "cancel_at";
1723
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "cancel_at" integer GENERATED ALWAYS AS ((raw_data->>'cancel_at')::integer) STORED;
1724
+
1725
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "canceled_at";
1726
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "canceled_at" integer GENERATED ALWAYS AS ((raw_data->>'canceled_at')::integer) STORED;
1727
+
1728
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "collection_method";
1729
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "collection_method" text GENERATED ALWAYS AS ((raw_data->>'collection_method')::text) STORED;
1730
+
1731
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "created";
1732
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1733
+
1734
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "days_until_due";
1735
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "days_until_due" integer GENERATED ALWAYS AS ((raw_data->>'days_until_due')::integer) STORED;
1736
+
1737
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "default_source";
1738
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "default_source" text GENERATED ALWAYS AS ((raw_data->>'default_source')::text) STORED;
1739
+
1740
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "default_tax_rates";
1741
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "default_tax_rates" jsonb GENERATED ALWAYS AS (raw_data->'default_tax_rates') STORED;
1742
+
1743
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "discount";
1744
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "discount" jsonb GENERATED ALWAYS AS (raw_data->'discount') STORED;
1745
+
1746
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "ended_at";
1747
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "ended_at" integer GENERATED ALWAYS AS ((raw_data->>'ended_at')::integer) STORED;
1748
+
1749
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "livemode";
1750
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1751
+
1752
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "next_pending_invoice_item_invoice";
1753
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "next_pending_invoice_item_invoice" integer GENERATED ALWAYS AS ((raw_data->>'next_pending_invoice_item_invoice')::integer) STORED;
1754
+
1755
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "pause_collection";
1756
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "pause_collection" jsonb GENERATED ALWAYS AS (raw_data->'pause_collection') STORED;
1757
+
1758
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "pending_invoice_item_interval";
1759
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "pending_invoice_item_interval" jsonb GENERATED ALWAYS AS (raw_data->'pending_invoice_item_interval') STORED;
1760
+
1761
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "start_date";
1762
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "start_date" integer GENERATED ALWAYS AS ((raw_data->>'start_date')::integer) STORED;
1763
+
1764
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "transfer_data";
1765
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "transfer_data" jsonb GENERATED ALWAYS AS (raw_data->'transfer_data') STORED;
1766
+
1767
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "trial_end";
1768
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "trial_end" jsonb GENERATED ALWAYS AS (raw_data->'trial_end') STORED;
1769
+
1770
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "trial_start";
1771
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "trial_start" jsonb GENERATED ALWAYS AS (raw_data->'trial_start') STORED;
1772
+
1773
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "schedule";
1774
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "schedule" text GENERATED ALWAYS AS ((raw_data->>'schedule')::text) STORED;
1775
+
1776
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "customer";
1777
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
1778
+
1779
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "latest_invoice";
1780
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "latest_invoice" text GENERATED ALWAYS AS ((raw_data->>'latest_invoice')::text) STORED;
1781
+
1782
+ ALTER TABLE "stripe"."subscriptions" DROP COLUMN IF EXISTS "plan";
1783
+ ALTER TABLE "stripe"."subscriptions" ADD COLUMN "plan" text GENERATED ALWAYS AS ((raw_data->>'plan')::text) STORED;
1784
+
1785
+ -- ============================================================================
1786
+ -- TAX_IDS
1787
+ -- ============================================================================
1788
+
1789
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN IF NOT EXISTS "raw_data" jsonb;
1790
+
1791
+ -- Drop indexes
1792
+ DROP INDEX IF EXISTS "stripe"."stripe_tax_ids_customer_idx";
1793
+
1794
+ -- Drop and recreate columns as generated
1795
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "object";
1796
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "object" text GENERATED ALWAYS AS ((raw_data->>'object')::text) STORED;
1797
+
1798
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "country";
1799
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "country" text GENERATED ALWAYS AS ((raw_data->>'country')::text) STORED;
1800
+
1801
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "customer";
1802
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "customer" text GENERATED ALWAYS AS ((raw_data->>'customer')::text) STORED;
1803
+
1804
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "type";
1805
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "type" text GENERATED ALWAYS AS ((raw_data->>'type')::text) STORED;
1806
+
1807
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "value";
1808
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "value" text GENERATED ALWAYS AS ((raw_data->>'value')::text) STORED;
1809
+
1810
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "created";
1811
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "created" integer GENERATED ALWAYS AS ((raw_data->>'created')::integer) STORED;
1812
+
1813
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "livemode";
1814
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "livemode" boolean GENERATED ALWAYS AS ((raw_data->>'livemode')::boolean) STORED;
1815
+
1816
+ ALTER TABLE "stripe"."tax_ids" DROP COLUMN IF EXISTS "owner";
1817
+ ALTER TABLE "stripe"."tax_ids" ADD COLUMN "owner" jsonb GENERATED ALWAYS AS (raw_data->'owner') STORED;
1818
+
1819
+ -- Recreate indexes
1820
+ CREATE INDEX stripe_tax_ids_customer_idx ON "stripe"."tax_ids" USING btree (customer);
1821
+