@zodic/shared 0.0.401 → 0.0.403

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/app/api/index.ts +0 -99
  2. package/app/base/AppContext.ts +0 -41
  3. package/app/services/ConceptService.ts +172 -244
  4. package/app/services/PaymentService.ts +61 -2
  5. package/db/migrations/{0000_little_sleeper.sql → 0000_workable_the_hand.sql} +197 -24
  6. package/db/migrations/meta/0000_snapshot.json +1663 -451
  7. package/db/migrations/meta/_journal.json +2 -156
  8. package/db/schema.ts +0 -31
  9. package/drizzle.config.ts +2 -2
  10. package/package.json +10 -5
  11. package/types/scopes/cloudflare.ts +2 -118
  12. package/types/scopes/generic.ts +0 -1
  13. package/utils/buildMessages.ts +1 -32
  14. package/wrangler.toml +24 -3
  15. package/app/durable/ConceptNameDO.ts +0 -199
  16. package/app/durable/index.ts +0 -1
  17. package/app/workflow/old/ArchetypeWorkflow.ts +0 -156
  18. package/db/migrations/0001_mysterious_mystique.sql +0 -47
  19. package/db/migrations/0002_reflective_firelord.sql +0 -13
  20. package/db/migrations/0003_thin_valeria_richards.sql +0 -28
  21. package/db/migrations/0004_loose_iron_monger.sql +0 -15
  22. package/db/migrations/0005_famous_cammi.sql +0 -26
  23. package/db/migrations/0006_fine_manta.sql +0 -1
  24. package/db/migrations/0007_typical_grim_reaper.sql +0 -1
  25. package/db/migrations/0008_fine_betty_brant.sql +0 -1
  26. package/db/migrations/0009_spooky_doctor_spectrum.sql +0 -20
  27. package/db/migrations/0010_tricky_lord_hawal.sql +0 -23
  28. package/db/migrations/0011_hard_king_bedlam.sql +0 -1
  29. package/db/migrations/0012_sudden_doctor_spectrum.sql +0 -27
  30. package/db/migrations/0013_lean_frightful_four.sql +0 -7
  31. package/db/migrations/0014_green_marvel_apes.sql +0 -10
  32. package/db/migrations/0015_zippy_sersi.sql +0 -10
  33. package/db/migrations/0016_awesome_squadron_sinister.sql +0 -1
  34. package/db/migrations/0017_vengeful_electro.sql +0 -1
  35. package/db/migrations/0018_wooden_sersi.sql +0 -16
  36. package/db/migrations/0019_abandoned_orphan.sql +0 -59
  37. package/db/migrations/0020_smiling_blob.sql +0 -1
  38. package/db/migrations/0021_flawless_wallflower.sql +0 -1
  39. package/db/migrations/0022_pale_marvex.sql +0 -1
  40. package/db/migrations/meta/0001_snapshot.json +0 -2200
  41. package/db/migrations/meta/0002_snapshot.json +0 -2284
  42. package/db/migrations/meta/0003_snapshot.json +0 -2417
  43. package/db/migrations/meta/0004_snapshot.json +0 -2417
  44. package/db/migrations/meta/0005_snapshot.json +0 -2417
  45. package/db/migrations/meta/0006_snapshot.json +0 -2425
  46. package/db/migrations/meta/0007_snapshot.json +0 -2433
  47. package/db/migrations/meta/0008_snapshot.json +0 -2425
  48. package/db/migrations/meta/0009_snapshot.json +0 -2425
  49. package/db/migrations/meta/0010_snapshot.json +0 -2594
  50. package/db/migrations/meta/0011_snapshot.json +0 -2602
  51. package/db/migrations/meta/0012_snapshot.json +0 -2602
  52. package/db/migrations/meta/0013_snapshot.json +0 -2649
  53. package/db/migrations/meta/0014_snapshot.json +0 -2723
  54. package/db/migrations/meta/0015_snapshot.json +0 -2711
  55. package/db/migrations/meta/0016_snapshot.json +0 -2715
  56. package/db/migrations/meta/0017_snapshot.json +0 -2723
  57. package/db/migrations/meta/0018_snapshot.json +0 -2834
  58. package/db/migrations/meta/0019_snapshot.json +0 -3244
  59. package/db/migrations/meta/0020_snapshot.json +0 -3252
  60. package/db/migrations/meta/0021_snapshot.json +0 -3254
  61. package/db/migrations/meta/0022_snapshot.json +0 -3260
@@ -1,3 +1,25 @@
1
+ CREATE TABLE `archetypes_data` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `language` text NOT NULL,
4
+ `gender` text,
5
+ `combination` text NOT NULL,
6
+ `archetype_index` text NOT NULL,
7
+ `name` text NOT NULL,
8
+ `essence_line` text NOT NULL,
9
+ `description` text,
10
+ `content` text DEFAULT '[]' NOT NULL,
11
+ `virtues` text DEFAULT '[]' NOT NULL,
12
+ `leonardo_prompt` text,
13
+ `status` text DEFAULT 'idle',
14
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
15
+ `images` text DEFAULT '[]' NOT NULL,
16
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP
17
+ );
18
+ --> statement-breakpoint
19
+ CREATE INDEX `archetypes_data_language_idx` ON `archetypes_data` (`language`);--> statement-breakpoint
20
+ CREATE INDEX `archetypes_data_combination_idx` ON `archetypes_data` (`combination`);--> statement-breakpoint
21
+ CREATE INDEX `archetypes_data_archetype_index_idx` ON `archetypes_data` (`archetype_index`);--> statement-breakpoint
22
+ CREATE INDEX `archetypes_data_gender_idx` ON `archetypes_data` (`gender`);--> statement-breakpoint
1
23
  CREATE TABLE `artifact_faceswap` (
2
24
  `id` text PRIMARY KEY NOT NULL,
3
25
  `user_artifact_id` text NOT NULL,
@@ -35,6 +57,35 @@ CREATE TABLE `artifacts` (
35
57
  --> statement-breakpoint
36
58
  CREATE UNIQUE INDEX `artifacts_slug_unique` ON `artifacts` (`slug`);--> statement-breakpoint
37
59
  CREATE INDEX `artifacts_concept_id_idx` ON `artifacts` (`concept_id`);--> statement-breakpoint
60
+ CREATE TABLE `asaas_events` (
61
+ `id` text PRIMARY KEY NOT NULL,
62
+ `asaas_event_id` text NOT NULL,
63
+ `payload` text NOT NULL,
64
+ `status` text DEFAULT 'pending' NOT NULL,
65
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
66
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL
67
+ );
68
+ --> statement-breakpoint
69
+ CREATE UNIQUE INDEX `asaas_events_asaas_event_id_unique` ON `asaas_events` (`asaas_event_id`);--> statement-breakpoint
70
+ CREATE INDEX `asaas_events_asaas_event_id_idx` ON `asaas_events` (`asaas_event_id`);--> statement-breakpoint
71
+ CREATE TABLE `aspect_reports` (
72
+ `id` text PRIMARY KEY NOT NULL,
73
+ `aspecting_planet` text NOT NULL,
74
+ `aspected_planet` text NOT NULL,
75
+ `aspect` text NOT NULL,
76
+ `description_template_id` text,
77
+ `en_report` text,
78
+ `pt_report` text,
79
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
80
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP,
81
+ FOREIGN KEY (`description_template_id`) REFERENCES `astro_description_templates`(`id`) ON UPDATE no action ON DELETE set null
82
+ );
83
+ --> statement-breakpoint
84
+ CREATE INDEX `aspect_reports_aspecting_idx` ON `aspect_reports` (`aspecting_planet`);--> statement-breakpoint
85
+ CREATE INDEX `aspect_reports_aspected_idx` ON `aspect_reports` (`aspected_planet`);--> statement-breakpoint
86
+ CREATE INDEX `aspect_reports_aspect_idx` ON `aspect_reports` (`aspect`);--> statement-breakpoint
87
+ CREATE INDEX `aspect_reports_combined_idx` ON `aspect_reports` (`aspecting_planet`,`aspected_planet`,`aspect`);--> statement-breakpoint
88
+ CREATE INDEX `aspect_reports_description_template_idx` ON `aspect_reports` (`description_template_id`);--> statement-breakpoint
38
89
  CREATE TABLE `astro_aspects` (
39
90
  `id` text PRIMARY KEY NOT NULL,
40
91
  `user_id` text NOT NULL,
@@ -49,6 +100,33 @@ CREATE TABLE `astro_aspects` (
49
100
  );
50
101
  --> statement-breakpoint
51
102
  CREATE INDEX `astro_aspects_user_id_idx` ON `astro_aspects` (`user_id`);--> statement-breakpoint
103
+ CREATE TABLE `astro_description_templates` (
104
+ `id` text PRIMARY KEY NOT NULL,
105
+ `entity_type` text NOT NULL,
106
+ `name` text NOT NULL,
107
+ `en_name` text,
108
+ `pt_name` text,
109
+ `en_description` text NOT NULL,
110
+ `pt_description` text NOT NULL,
111
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
112
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP
113
+ );
114
+ --> statement-breakpoint
115
+ CREATE INDEX `astro_description_templates_type_name_idx` ON `astro_description_templates` (`entity_type`,`name`);--> statement-breakpoint
116
+ CREATE TABLE `astro_feature_reports` (
117
+ `id` text PRIMARY KEY NOT NULL,
118
+ `feature_type` text NOT NULL,
119
+ `name` text NOT NULL,
120
+ `description_template_id` text,
121
+ `en_report` text,
122
+ `pt_report` text,
123
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
124
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP,
125
+ FOREIGN KEY (`description_template_id`) REFERENCES `astro_description_templates`(`id`) ON UPDATE no action ON DELETE set null
126
+ );
127
+ --> statement-breakpoint
128
+ CREATE INDEX `astro_feature_reports_type_name_idx` ON `astro_feature_reports` (`feature_type`,`name`);--> statement-breakpoint
129
+ CREATE INDEX `astro_feature_reports_description_template_idx` ON `astro_feature_reports` (`description_template_id`);--> statement-breakpoint
52
130
  CREATE TABLE `astro_features` (
53
131
  `id` text PRIMARY KEY NOT NULL,
54
132
  `user_id` text NOT NULL,
@@ -56,7 +134,6 @@ CREATE TABLE `astro_features` (
56
134
  `name` text NOT NULL,
57
135
  `description` text,
58
136
  `percentage` real,
59
- `order` integer,
60
137
  `prominent_id` integer,
61
138
  FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
62
139
  );
@@ -87,6 +164,23 @@ CREATE TABLE `astro_planets` (
87
164
  );
88
165
  --> statement-breakpoint
89
166
  CREATE INDEX `astro_planets_user_id_idx` ON `astro_planets` (`user_id`);--> statement-breakpoint
167
+ CREATE TABLE `astro_reports` (
168
+ `id` text PRIMARY KEY NOT NULL,
169
+ `type` text NOT NULL,
170
+ `name` text NOT NULL,
171
+ `sign` text,
172
+ `house` integer,
173
+ `description_template_id` text,
174
+ `en_report` text,
175
+ `pt_report` text,
176
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
177
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP,
178
+ FOREIGN KEY (`description_template_id`) REFERENCES `astro_description_templates`(`id`) ON UPDATE no action ON DELETE set null
179
+ );
180
+ --> statement-breakpoint
181
+ CREATE INDEX `astro_reports_type_idx` ON `astro_reports` (`type`);--> statement-breakpoint
182
+ CREATE INDEX `astro_reports_name_sign_idx` ON `astro_reports` (`name`,`sign`);--> statement-breakpoint
183
+ CREATE INDEX `astro_reports_name_house_idx` ON `astro_reports` (`name`,`house`);--> statement-breakpoint
90
184
  CREATE TABLE `concept_combinations` (
91
185
  `id` text PRIMARY KEY NOT NULL,
92
186
  `concept_id` text NOT NULL,
@@ -104,7 +198,7 @@ CREATE TABLE `concepts` (
104
198
  `slug` text NOT NULL,
105
199
  `planet1` text NOT NULL,
106
200
  `planet2` text NOT NULL,
107
- `planet3` text
201
+ `planet3` text NOT NULL
108
202
  );
109
203
  --> statement-breakpoint
110
204
  CREATE INDEX `concepts_name_idx` ON `concepts` (`name`);--> statement-breakpoint
@@ -115,10 +209,11 @@ CREATE TABLE `concepts_data` (
115
209
  `combination` text NOT NULL,
116
210
  `name` text NOT NULL,
117
211
  `description` text NOT NULL,
118
- `content` text DEFAULT '[]',
119
- `poem` text DEFAULT '[]',
212
+ `content` text DEFAULT '[]' NOT NULL,
213
+ `poem` text DEFAULT '[]' NOT NULL,
120
214
  `leonardo_prompt` text,
121
215
  `post_images` text DEFAULT '[]',
216
+ `framed_images` text DEFAULT '[]',
122
217
  `reel_images` text DEFAULT '[]',
123
218
  `status` text DEFAULT 'idle',
124
219
  `created_at` integer DEFAULT CURRENT_TIMESTAMP,
@@ -129,21 +224,22 @@ CREATE INDEX `concepts_data_language_idx` ON `concepts_data` (`language`);--> st
129
224
  CREATE INDEX `concepts_data_concept_slug_idx` ON `concepts_data` (`concept_slug`);--> statement-breakpoint
130
225
  CREATE INDEX `concepts_data_combination_idx` ON `concepts_data` (`combination`);--> statement-breakpoint
131
226
  CREATE INDEX `concepts_data_name_idx` ON `concepts_data` (`name`);--> statement-breakpoint
132
- CREATE TABLE `credits_transactions` (
227
+ CREATE TABLE `cosmic_mirror_images` (
133
228
  `id` text PRIMARY KEY NOT NULL,
134
- `user_id` text NOT NULL,
135
- `type` text NOT NULL,
136
- `amount` integer NOT NULL,
137
- `description` text,
138
- `product_type` text,
139
- `product_id` text,
140
- `payment_id` text NOT NULL,
229
+ `user_artifact_id` text NOT NULL,
230
+ `leonardo_id` text NOT NULL,
231
+ `url` text NOT NULL,
232
+ `width` integer NOT NULL,
233
+ `height` integer NOT NULL,
234
+ `generation_type` text NOT NULL,
235
+ `timestamp` integer NOT NULL,
141
236
  `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
142
237
  `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
143
- FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
238
+ FOREIGN KEY (`user_artifact_id`) REFERENCES `user_artifacts`(`id`) ON UPDATE no action ON DELETE cascade
144
239
  );
145
240
  --> statement-breakpoint
146
- CREATE INDEX `credits_transactions_user_id_idx` ON `credits_transactions` (`user_id`);--> statement-breakpoint
241
+ CREATE INDEX `cosmic_mirror_images_user_artifact_idx` ON `cosmic_mirror_images` (`user_artifact_id`);--> statement-breakpoint
242
+ CREATE INDEX `cosmic_mirror_images_type_idx` ON `cosmic_mirror_images` (`generation_type`);--> statement-breakpoint
147
243
  CREATE TABLE `generations` (
148
244
  `id` text PRIMARY KEY NOT NULL,
149
245
  `user_id` text,
@@ -152,6 +248,7 @@ CREATE TABLE `generations` (
152
248
  `user_artifact_id` text,
153
249
  `gender` text,
154
250
  `concept_combination_id` text,
251
+ `archetype_data_id` text,
155
252
  `type` text NOT NULL,
156
253
  `status` text DEFAULT 'pending' NOT NULL,
157
254
  `url` text,
@@ -160,12 +257,62 @@ CREATE TABLE `generations` (
160
257
  FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
161
258
  FOREIGN KEY (`artifact_id`) REFERENCES `artifacts`(`id`) ON UPDATE no action ON DELETE cascade,
162
259
  FOREIGN KEY (`user_artifact_id`) REFERENCES `user_artifacts`(`id`) ON UPDATE no action ON DELETE cascade,
163
- FOREIGN KEY (`concept_combination_id`) REFERENCES `concept_combinations`(`id`) ON UPDATE no action ON DELETE cascade
260
+ FOREIGN KEY (`concept_combination_id`) REFERENCES `concept_combinations`(`id`) ON UPDATE no action ON DELETE cascade,
261
+ FOREIGN KEY (`archetype_data_id`) REFERENCES `archetypes_data`(`id`) ON UPDATE no action ON DELETE cascade
164
262
  );
165
263
  --> statement-breakpoint
166
264
  CREATE INDEX `generations_user_id_idx` ON `generations` (`user_id`);--> statement-breakpoint
167
265
  CREATE INDEX `generations_concept_combination_id_idx` ON `generations` (`concept_combination_id`);--> statement-breakpoint
168
266
  CREATE INDEX `generations_archetype_index_idx` ON `generations` (`archetype_index`);--> statement-breakpoint
267
+ CREATE INDEX `generations_archetype_data_id_idx` ON `generations` (`archetype_data_id`);--> statement-breakpoint
268
+ CREATE TABLE `house_reports` (
269
+ `id` text PRIMARY KEY NOT NULL,
270
+ `sign` text NOT NULL,
271
+ `house` integer NOT NULL,
272
+ `description_template_id` text,
273
+ `en_report` text,
274
+ `pt_report` text,
275
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
276
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP,
277
+ FOREIGN KEY (`description_template_id`) REFERENCES `astro_description_templates`(`id`) ON UPDATE no action ON DELETE set null
278
+ );
279
+ --> statement-breakpoint
280
+ CREATE INDEX `house_reports_sign_house_idx` ON `house_reports` (`sign`,`house`);--> statement-breakpoint
281
+ CREATE INDEX `house_reports_description_template_idx` ON `house_reports` (`description_template_id`);--> statement-breakpoint
282
+ CREATE TABLE `logs` (
283
+ `id` text PRIMARY KEY NOT NULL,
284
+ `level` text NOT NULL,
285
+ `message` text NOT NULL,
286
+ `context` text DEFAULT '{}' NOT NULL,
287
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP
288
+ );
289
+ --> statement-breakpoint
290
+ CREATE TABLE `payments` (
291
+ `id` text PRIMARY KEY NOT NULL,
292
+ `user_id` text NOT NULL,
293
+ `checkout_id` text NOT NULL,
294
+ `amount` real NOT NULL,
295
+ `status` text DEFAULT 'pending' NOT NULL,
296
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
297
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
298
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade
299
+ );
300
+ --> statement-breakpoint
301
+ CREATE UNIQUE INDEX `payments_checkout_id_unique` ON `payments` (`checkout_id`);--> statement-breakpoint
302
+ CREATE INDEX `payments_user_id_idx` ON `payments` (`user_id`);--> statement-breakpoint
303
+ CREATE INDEX `payments_checkout_id_idx` ON `payments` (`checkout_id`);--> statement-breakpoint
304
+ CREATE TABLE `products` (
305
+ `id` text PRIMARY KEY NOT NULL,
306
+ `slug` text NOT NULL,
307
+ `price` real NOT NULL,
308
+ `image_url` text,
309
+ `image_base64` text,
310
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
311
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL
312
+ );
313
+ --> statement-breakpoint
314
+ CREATE UNIQUE INDEX `products_slug_unique` ON `products` (`slug`);--> statement-breakpoint
315
+ CREATE INDEX `products_slug_idx` ON `products` (`slug`);--> statement-breakpoint
169
316
  CREATE TABLE `tokens` (
170
317
  `id` text PRIMARY KEY NOT NULL,
171
318
  `user_id` text NOT NULL,
@@ -182,26 +329,30 @@ CREATE TABLE `user_artifacts` (
182
329
  `id` text PRIMARY KEY NOT NULL,
183
330
  `user_id` text NOT NULL,
184
331
  `user_concept_id` text NOT NULL,
332
+ `concept_id` text NOT NULL,
185
333
  `artifact_id` text NOT NULL,
186
- `gender` text NOT NULL,
187
- `archetype_index` text NOT NULL,
188
- `post_image_id` text,
189
- `reel_image_id` text,
190
- `post_image_url` text,
191
- `reel_image_url` text,
192
- `post_generation_id` text,
193
- `reel_generation_id` text,
334
+ `archetype_data_id` text,
335
+ `post_images` text,
336
+ `reel_images` text,
337
+ `chosen_image_url` text,
338
+ `upscaled_image` text,
339
+ `framed_image_url` text,
194
340
  `status` text DEFAULT 'pending' NOT NULL,
341
+ `version` integer DEFAULT 0 NOT NULL,
195
342
  `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
196
343
  `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
197
344
  FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
198
345
  FOREIGN KEY (`user_concept_id`) REFERENCES `user_concepts`(`id`) ON UPDATE no action ON DELETE cascade,
199
- FOREIGN KEY (`artifact_id`) REFERENCES `artifacts`(`id`) ON UPDATE no action ON DELETE cascade
346
+ FOREIGN KEY (`concept_id`) REFERENCES `concepts`(`id`) ON UPDATE no action ON DELETE cascade,
347
+ FOREIGN KEY (`artifact_id`) REFERENCES `artifacts`(`id`) ON UPDATE no action ON DELETE cascade,
348
+ FOREIGN KEY (`archetype_data_id`) REFERENCES `archetypes_data`(`id`) ON UPDATE no action ON DELETE cascade
200
349
  );
201
350
  --> statement-breakpoint
202
351
  CREATE INDEX `user_artifacts_user_id_idx` ON `user_artifacts` (`user_id`);--> statement-breakpoint
203
352
  CREATE INDEX `user_artifacts_artifact_id_idx` ON `user_artifacts` (`artifact_id`);--> statement-breakpoint
204
353
  CREATE INDEX `user_artifacts_status_idx` ON `user_artifacts` (`status`);--> statement-breakpoint
354
+ CREATE INDEX `user_artifacts_archetype_data_id_idx` ON `user_artifacts` (`archetype_data_id`);--> statement-breakpoint
355
+ CREATE INDEX `user_artifacts_concept_id_idx` ON `user_artifacts` (`concept_id`);--> statement-breakpoint
205
356
  CREATE TABLE `user_concepts` (
206
357
  `id` text PRIMARY KEY NOT NULL,
207
358
  `user_id` text NOT NULL,
@@ -209,6 +360,7 @@ CREATE TABLE `user_concepts` (
209
360
  `concept_combination_id` text NOT NULL,
210
361
  `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
211
362
  `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
363
+ `image_idx` integer DEFAULT 0 NOT NULL,
212
364
  FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
213
365
  FOREIGN KEY (`concept_id`) REFERENCES `concepts`(`id`) ON UPDATE no action ON DELETE cascade,
214
366
  FOREIGN KEY (`concept_combination_id`) REFERENCES `concept_combinations`(`id`) ON UPDATE no action ON DELETE cascade
@@ -216,6 +368,25 @@ CREATE TABLE `user_concepts` (
216
368
  --> statement-breakpoint
217
369
  CREATE INDEX `user_concepts_user_id_idx` ON `user_concepts` (`user_id`);--> statement-breakpoint
218
370
  CREATE INDEX `user_concepts_concept_id_idx` ON `user_concepts` (`concept_id`);--> statement-breakpoint
371
+ CREATE TABLE `user_products` (
372
+ `id` text PRIMARY KEY NOT NULL,
373
+ `user_id` text NOT NULL,
374
+ `product_id` text NOT NULL,
375
+ `checkout_id` text,
376
+ `payment_id` text,
377
+ `status` text DEFAULT 'locked' NOT NULL,
378
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
379
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP NOT NULL,
380
+ FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade,
381
+ FOREIGN KEY (`product_id`) REFERENCES `products`(`id`) ON UPDATE no action ON DELETE cascade,
382
+ FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON UPDATE no action ON DELETE set null
383
+ );
384
+ --> statement-breakpoint
385
+ CREATE INDEX `user_products_user_id_idx` ON `user_products` (`user_id`);--> statement-breakpoint
386
+ CREATE INDEX `user_products_product_id_idx` ON `user_products` (`product_id`);--> statement-breakpoint
387
+ CREATE INDEX `user_products_payment_id_idx` ON `user_products` (`payment_id`);--> statement-breakpoint
388
+ CREATE INDEX `user_products_checkout_id_idx` ON `user_products` (`checkout_id`);--> statement-breakpoint
389
+ CREATE UNIQUE INDEX `user_product_unique` ON `user_products` (`user_id`,`product_id`);--> statement-breakpoint
219
390
  CREATE TABLE `users` (
220
391
  `id` text PRIMARY KEY NOT NULL,
221
392
  `email` text NOT NULL,
@@ -238,6 +409,7 @@ CREATE TABLE `users` (
238
409
  `tiktok_username` text,
239
410
  `oauth_provider` text,
240
411
  `oauth_provider_id` text,
412
+ `customer_id` text,
241
413
  `credits_balance` integer DEFAULT 0 NOT NULL,
242
414
  `total_credits_earned` integer DEFAULT 0 NOT NULL,
243
415
  `last_transaction_at` integer,
@@ -252,6 +424,7 @@ CREATE UNIQUE INDEX `users_tiktok_username_unique` ON `users` (`tiktok_username`
252
424
  CREATE UNIQUE INDEX `users_oauth_provider_id_unique` ON `users` (`oauth_provider_id`);--> statement-breakpoint
253
425
  CREATE INDEX `users_email_idx` ON `users` (`email`);--> statement-breakpoint
254
426
  CREATE INDEX `users_oauth_provider_idx` ON `users` (`oauth_provider`,`oauth_provider_id`);--> statement-breakpoint
427
+ CREATE INDEX `users_customer_id_idx` ON `users` (`customer_id`);--> statement-breakpoint
255
428
  CREATE TABLE `users_temp` (
256
429
  `id` text PRIMARY KEY NOT NULL,
257
430
  `email` text NOT NULL,