@wopr-network/platform-core 1.66.0 → 1.66.1

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.
@@ -1,6 +1,6 @@
1
1
  CREATE TYPE "public"."rate_override_status" AS ENUM('scheduled', 'active', 'expired', 'cancelled');
2
2
  --> statement-breakpoint
3
- CREATE TABLE "admin_notes" (
3
+ CREATE TABLE IF NOT EXISTS "admin_notes" (
4
4
  "id" text PRIMARY KEY NOT NULL,
5
5
  "tenant_id" text NOT NULL,
6
6
  "author_id" text NOT NULL,
@@ -10,7 +10,7 @@ CREATE TABLE "admin_notes" (
10
10
  "updated_at" bigint DEFAULT (extract(epoch from now()))::bigint NOT NULL
11
11
  );
12
12
  --> statement-breakpoint
13
- CREATE TABLE "audit_log" (
13
+ CREATE TABLE IF NOT EXISTS "audit_log" (
14
14
  "id" text PRIMARY KEY NOT NULL,
15
15
  "timestamp" bigint NOT NULL,
16
16
  "user_id" text NOT NULL,
@@ -23,7 +23,7 @@ CREATE TABLE "audit_log" (
23
23
  "user_agent" text
24
24
  );
25
25
  --> statement-breakpoint
26
- CREATE TABLE "backup_status" (
26
+ CREATE TABLE IF NOT EXISTS "backup_status" (
27
27
  "container_id" text PRIMARY KEY NOT NULL,
28
28
  "node_id" text NOT NULL,
29
29
  "last_backup_at" text,
@@ -36,7 +36,7 @@ CREATE TABLE "backup_status" (
36
36
  "updated_at" text DEFAULT (now()) NOT NULL
37
37
  );
38
38
  --> statement-breakpoint
39
- CREATE TABLE "bot_instances" (
39
+ CREATE TABLE IF NOT EXISTS "bot_instances" (
40
40
  "id" text PRIMARY KEY NOT NULL,
41
41
  "tenant_id" text NOT NULL,
42
42
  "name" text NOT NULL,
@@ -51,7 +51,7 @@ CREATE TABLE "bot_instances" (
51
51
  "created_by_user_id" text
52
52
  );
53
53
  --> statement-breakpoint
54
- CREATE TABLE "bot_profiles" (
54
+ CREATE TABLE IF NOT EXISTS "bot_profiles" (
55
55
  "id" text PRIMARY KEY NOT NULL,
56
56
  "tenant_id" text NOT NULL,
57
57
  "name" text NOT NULL,
@@ -67,7 +67,7 @@ CREATE TABLE "bot_profiles" (
67
67
  "updated_at" text DEFAULT (now()) NOT NULL
68
68
  );
69
69
  --> statement-breakpoint
70
- CREATE TABLE "bulk_undo_grants" (
70
+ CREATE TABLE IF NOT EXISTS "bulk_undo_grants" (
71
71
  "operation_id" text PRIMARY KEY NOT NULL,
72
72
  "tenant_ids" text NOT NULL,
73
73
  "amount_cents" integer NOT NULL,
@@ -77,14 +77,14 @@ CREATE TABLE "bulk_undo_grants" (
77
77
  "undone" boolean DEFAULT false NOT NULL
78
78
  );
79
79
  --> statement-breakpoint
80
- CREATE TABLE "circuit_breaker_states" (
80
+ CREATE TABLE IF NOT EXISTS "circuit_breaker_states" (
81
81
  "instance_id" text PRIMARY KEY NOT NULL,
82
82
  "count" integer DEFAULT 0 NOT NULL,
83
83
  "window_start" bigint NOT NULL,
84
84
  "tripped_at" bigint
85
85
  );
86
86
  --> statement-breakpoint
87
- CREATE TABLE "fleet_events" (
87
+ CREATE TABLE IF NOT EXISTS "fleet_events" (
88
88
  "id" serial PRIMARY KEY NOT NULL,
89
89
  "event_type" text NOT NULL,
90
90
  "fired" boolean DEFAULT false NOT NULL,
@@ -92,7 +92,7 @@ CREATE TABLE "fleet_events" (
92
92
  "cleared_at" bigint
93
93
  );
94
94
  --> statement-breakpoint
95
- CREATE TABLE "gateway_metrics" (
95
+ CREATE TABLE IF NOT EXISTS "gateway_metrics" (
96
96
  "id" serial PRIMARY KEY NOT NULL,
97
97
  "minute_key" bigint NOT NULL,
98
98
  "capability" text NOT NULL,
@@ -101,7 +101,7 @@ CREATE TABLE "gateway_metrics" (
101
101
  "credit_failures" integer DEFAULT 0 NOT NULL
102
102
  );
103
103
  --> statement-breakpoint
104
- CREATE TABLE "gpu_nodes" (
104
+ CREATE TABLE IF NOT EXISTS "gpu_nodes" (
105
105
  "id" text PRIMARY KEY NOT NULL,
106
106
  "droplet_id" text,
107
107
  "host" text,
@@ -117,7 +117,7 @@ CREATE TABLE "gpu_nodes" (
117
117
  "updated_at" bigint DEFAULT (extract(epoch from now()))::bigint NOT NULL
118
118
  );
119
119
  --> statement-breakpoint
120
- CREATE TABLE "node_registration_tokens" (
120
+ CREATE TABLE IF NOT EXISTS "node_registration_tokens" (
121
121
  "id" text PRIMARY KEY NOT NULL,
122
122
  "user_id" text NOT NULL,
123
123
  "label" text,
@@ -128,7 +128,7 @@ CREATE TABLE "node_registration_tokens" (
128
128
  "used_at" bigint
129
129
  );
130
130
  --> statement-breakpoint
131
- CREATE TABLE "node_transitions" (
131
+ CREATE TABLE IF NOT EXISTS "node_transitions" (
132
132
  "id" text PRIMARY KEY NOT NULL,
133
133
  "node_id" text NOT NULL,
134
134
  "from_status" text NOT NULL,
@@ -138,7 +138,7 @@ CREATE TABLE "node_transitions" (
138
138
  "created_at" bigint NOT NULL
139
139
  );
140
140
  --> statement-breakpoint
141
- CREATE TABLE "nodes" (
141
+ CREATE TABLE IF NOT EXISTS "nodes" (
142
142
  "id" text PRIMARY KEY NOT NULL,
143
143
  "host" text NOT NULL,
144
144
  "status" text DEFAULT 'active' NOT NULL,
@@ -162,7 +162,7 @@ CREATE TABLE "nodes" (
162
162
  "label" text
163
163
  );
164
164
  --> statement-breakpoint
165
- CREATE TABLE "oauth_states" (
165
+ CREATE TABLE IF NOT EXISTS "oauth_states" (
166
166
  "state" text PRIMARY KEY NOT NULL,
167
167
  "provider" text NOT NULL,
168
168
  "user_id" text NOT NULL,
@@ -173,7 +173,7 @@ CREATE TABLE "oauth_states" (
173
173
  "expires_at" bigint NOT NULL
174
174
  );
175
175
  --> statement-breakpoint
176
- CREATE TABLE "plugin_configs" (
176
+ CREATE TABLE IF NOT EXISTS "plugin_configs" (
177
177
  "id" text PRIMARY KEY NOT NULL,
178
178
  "bot_id" text NOT NULL,
179
179
  "plugin_id" text NOT NULL,
@@ -185,7 +185,7 @@ CREATE TABLE "plugin_configs" (
185
185
  CONSTRAINT "plugin_configs_bot_plugin_uniq" UNIQUE("bot_id","plugin_id")
186
186
  );
187
187
  --> statement-breakpoint
188
- CREATE TABLE "plugin_marketplace_content" (
188
+ CREATE TABLE IF NOT EXISTS "plugin_marketplace_content" (
189
189
  "plugin_id" text PRIMARY KEY NOT NULL,
190
190
  "version" text NOT NULL,
191
191
  "markdown" text NOT NULL,
@@ -193,13 +193,13 @@ CREATE TABLE "plugin_marketplace_content" (
193
193
  "updated_at" bigint NOT NULL
194
194
  );
195
195
  --> statement-breakpoint
196
- CREATE TABLE "provider_health_overrides" (
196
+ CREATE TABLE IF NOT EXISTS "provider_health_overrides" (
197
197
  "adapter" text PRIMARY KEY NOT NULL,
198
198
  "healthy" integer DEFAULT 1 NOT NULL,
199
199
  "marked_at" bigint NOT NULL
200
200
  );
201
201
  --> statement-breakpoint
202
- CREATE TABLE "provisioned_phone_numbers" (
202
+ CREATE TABLE IF NOT EXISTS "provisioned_phone_numbers" (
203
203
  "sid" text PRIMARY KEY NOT NULL,
204
204
  "tenant_id" text NOT NULL,
205
205
  "phone_number" text NOT NULL,
@@ -207,7 +207,7 @@ CREATE TABLE "provisioned_phone_numbers" (
207
207
  "last_billed_at" text
208
208
  );
209
209
  --> statement-breakpoint
210
- CREATE TABLE "recovery_events" (
210
+ CREATE TABLE IF NOT EXISTS "recovery_events" (
211
211
  "id" text PRIMARY KEY NOT NULL,
212
212
  "node_id" text NOT NULL,
213
213
  "trigger" text NOT NULL,
@@ -221,7 +221,7 @@ CREATE TABLE "recovery_events" (
221
221
  "report_json" text
222
222
  );
223
223
  --> statement-breakpoint
224
- CREATE TABLE "restore_log" (
224
+ CREATE TABLE IF NOT EXISTS "restore_log" (
225
225
  "id" text PRIMARY KEY NOT NULL,
226
226
  "tenant" text NOT NULL,
227
227
  "snapshot_key" text NOT NULL,
@@ -231,13 +231,13 @@ CREATE TABLE "restore_log" (
231
231
  "reason" text
232
232
  );
233
233
  --> statement-breakpoint
234
- CREATE TABLE "tenant_security_settings" (
234
+ CREATE TABLE IF NOT EXISTS "tenant_security_settings" (
235
235
  "tenant_id" text PRIMARY KEY NOT NULL,
236
236
  "require_two_factor" boolean DEFAULT false NOT NULL,
237
237
  "updated_at" bigint NOT NULL
238
238
  );
239
239
  --> statement-breakpoint
240
- CREATE TABLE "snapshots" (
240
+ CREATE TABLE IF NOT EXISTS "snapshots" (
241
241
  "id" text PRIMARY KEY NOT NULL,
242
242
  "tenant" text DEFAULT '' NOT NULL,
243
243
  "instance_id" text NOT NULL,
@@ -259,13 +259,13 @@ CREATE TABLE "snapshots" (
259
259
  CONSTRAINT "type_check" CHECK (type IN ('nightly', 'on-demand', 'pre-restore'))
260
260
  );
261
261
  --> statement-breakpoint
262
- CREATE TABLE "tenant_model_selection" (
262
+ CREATE TABLE IF NOT EXISTS "tenant_model_selection" (
263
263
  "tenant_id" text PRIMARY KEY NOT NULL,
264
264
  "default_model" text DEFAULT 'openrouter/auto' NOT NULL,
265
265
  "updated_at" text NOT NULL
266
266
  );
267
267
  --> statement-breakpoint
268
- CREATE TABLE "tenant_status" (
268
+ CREATE TABLE IF NOT EXISTS "tenant_status" (
269
269
  "tenant_id" text PRIMARY KEY NOT NULL,
270
270
  "status" text DEFAULT 'active' NOT NULL,
271
271
  "status_reason" text,
@@ -277,7 +277,7 @@ CREATE TABLE "tenant_status" (
277
277
  "updated_at" bigint DEFAULT (extract(epoch from now()))::bigint NOT NULL
278
278
  );
279
279
  --> statement-breakpoint
280
- CREATE TABLE "vps_subscriptions" (
280
+ CREATE TABLE IF NOT EXISTS "vps_subscriptions" (
281
281
  "bot_id" text PRIMARY KEY NOT NULL,
282
282
  "tenant_id" text NOT NULL,
283
283
  "stripe_subscription_id" text NOT NULL,
@@ -292,7 +292,7 @@ CREATE TABLE "vps_subscriptions" (
292
292
  CONSTRAINT "vps_subscriptions_stripe_subscription_id_unique" UNIQUE("stripe_subscription_id")
293
293
  );
294
294
  --> statement-breakpoint
295
- CREATE TABLE "webhook_sig_penalties" (
295
+ CREATE TABLE IF NOT EXISTS "webhook_sig_penalties" (
296
296
  "ip" text NOT NULL,
297
297
  "source" text NOT NULL,
298
298
  "failures" integer DEFAULT 0 NOT NULL,
@@ -301,7 +301,7 @@ CREATE TABLE "webhook_sig_penalties" (
301
301
  CONSTRAINT "webhook_sig_penalties_ip_source_pk" PRIMARY KEY("ip","source")
302
302
  );
303
303
  --> statement-breakpoint
304
- CREATE TABLE "marketplace_plugins" (
304
+ CREATE TABLE IF NOT EXISTS "marketplace_plugins" (
305
305
  "plugin_id" text PRIMARY KEY NOT NULL,
306
306
  "npm_package" text NOT NULL,
307
307
  "version" text NOT NULL,
@@ -317,7 +317,7 @@ CREATE TABLE "marketplace_plugins" (
317
317
  "install_error" text
318
318
  );
319
319
  --> statement-breakpoint
320
- CREATE TABLE "onboarding_sessions" (
320
+ CREATE TABLE IF NOT EXISTS "onboarding_sessions" (
321
321
  "id" text PRIMARY KEY NOT NULL,
322
322
  "user_id" text,
323
323
  "anonymous_id" text,
@@ -331,7 +331,7 @@ CREATE TABLE "onboarding_sessions" (
331
331
  CONSTRAINT "onboarding_sessions_wopr_session_name_unique" UNIQUE("wopr_session_name")
332
332
  );
333
333
  --> statement-breakpoint
334
- CREATE TABLE "onboarding_scripts" (
334
+ CREATE TABLE IF NOT EXISTS "onboarding_scripts" (
335
335
  "id" text PRIMARY KEY NOT NULL,
336
336
  "content" text NOT NULL,
337
337
  "version" integer NOT NULL,
@@ -340,7 +340,7 @@ CREATE TABLE "onboarding_scripts" (
340
340
  CONSTRAINT "onboarding_scripts_version_unique" UNIQUE("version")
341
341
  );
342
342
  --> statement-breakpoint
343
- CREATE TABLE "setup_sessions" (
343
+ CREATE TABLE IF NOT EXISTS "setup_sessions" (
344
344
  "id" text PRIMARY KEY NOT NULL,
345
345
  "session_id" text NOT NULL,
346
346
  "plugin_id" text NOT NULL,
@@ -353,7 +353,7 @@ CREATE TABLE "setup_sessions" (
353
353
  CONSTRAINT "setup_sessions_session_in_progress_uniq" UNIQUE("session_id","status")
354
354
  );
355
355
  --> statement-breakpoint
356
- CREATE TABLE "fleet_event_history" (
356
+ CREATE TABLE IF NOT EXISTS "fleet_event_history" (
357
357
  "id" serial PRIMARY KEY NOT NULL,
358
358
  "event_type" text NOT NULL,
359
359
  "bot_id" text NOT NULL,
@@ -361,7 +361,7 @@ CREATE TABLE "fleet_event_history" (
361
361
  "created_at" bigint NOT NULL
362
362
  );
363
363
  --> statement-breakpoint
364
- CREATE TABLE "gpu_allocations" (
364
+ CREATE TABLE IF NOT EXISTS "gpu_allocations" (
365
365
  "id" text PRIMARY KEY NOT NULL,
366
366
  "gpu_node_id" text NOT NULL,
367
367
  "tenant_id" text NOT NULL,
@@ -371,7 +371,7 @@ CREATE TABLE "gpu_allocations" (
371
371
  "updated_at" bigint DEFAULT (extract(epoch from now()))::bigint NOT NULL
372
372
  );
373
373
  --> statement-breakpoint
374
- CREATE TABLE "gpu_configurations" (
374
+ CREATE TABLE IF NOT EXISTS "gpu_configurations" (
375
375
  "gpu_node_id" text PRIMARY KEY NOT NULL,
376
376
  "memory_limit_mib" integer,
377
377
  "model_assignments" text,
@@ -380,7 +380,7 @@ CREATE TABLE "gpu_configurations" (
380
380
  "updated_at" bigint DEFAULT (extract(epoch from now()))::bigint NOT NULL
381
381
  );
382
382
  --> statement-breakpoint
383
- CREATE TABLE "provider_costs" (
383
+ CREATE TABLE IF NOT EXISTS "provider_costs" (
384
384
  "id" text PRIMARY KEY NOT NULL,
385
385
  "capability" text NOT NULL,
386
386
  "adapter" text NOT NULL,
@@ -394,7 +394,7 @@ CREATE TABLE "provider_costs" (
394
394
  "updated_at" text DEFAULT (now()) NOT NULL
395
395
  );
396
396
  --> statement-breakpoint
397
- CREATE TABLE "recovery_items" (
397
+ CREATE TABLE IF NOT EXISTS "recovery_items" (
398
398
  "id" text PRIMARY KEY NOT NULL,
399
399
  "recovery_event_id" text NOT NULL,
400
400
  "tenant" text NOT NULL,
@@ -408,7 +408,7 @@ CREATE TABLE "recovery_items" (
408
408
  "completed_at" bigint
409
409
  );
410
410
  --> statement-breakpoint
411
- CREATE TABLE "sell_rates" (
411
+ CREATE TABLE IF NOT EXISTS "sell_rates" (
412
412
  "id" text PRIMARY KEY NOT NULL,
413
413
  "capability" text NOT NULL,
414
414
  "display_name" text NOT NULL,
@@ -441,143 +441,143 @@ CREATE TABLE IF NOT EXISTS "page_contexts" (
441
441
  "updated_at" bigint NOT NULL
442
442
  );
443
443
  --> statement-breakpoint
444
- CREATE INDEX "onboarding_scripts_version_idx" ON "onboarding_scripts" ("version" DESC);
444
+ CREATE INDEX IF NOT EXISTS "onboarding_scripts_version_idx" ON "onboarding_scripts" ("version" DESC);
445
445
  --> statement-breakpoint
446
- CREATE INDEX "idx_admin_notes_tenant" ON "admin_notes" USING btree ("tenant_id","created_at");
446
+ CREATE INDEX IF NOT EXISTS "idx_admin_notes_tenant" ON "admin_notes" USING btree ("tenant_id","created_at");
447
447
  --> statement-breakpoint
448
- CREATE INDEX "idx_admin_notes_author" ON "admin_notes" USING btree ("author_id");
448
+ CREATE INDEX IF NOT EXISTS "idx_admin_notes_author" ON "admin_notes" USING btree ("author_id");
449
449
  --> statement-breakpoint
450
- CREATE INDEX "idx_admin_notes_pinned" ON "admin_notes" USING btree ("tenant_id","is_pinned");
450
+ CREATE INDEX IF NOT EXISTS "idx_admin_notes_pinned" ON "admin_notes" USING btree ("tenant_id","is_pinned");
451
451
  --> statement-breakpoint
452
- CREATE INDEX "idx_audit_timestamp" ON "audit_log" USING btree ("timestamp");
452
+ CREATE INDEX IF NOT EXISTS "idx_audit_timestamp" ON "audit_log" USING btree ("timestamp");
453
453
  --> statement-breakpoint
454
- CREATE INDEX "idx_audit_user_id" ON "audit_log" USING btree ("user_id");
454
+ CREATE INDEX IF NOT EXISTS "idx_audit_user_id" ON "audit_log" USING btree ("user_id");
455
455
  --> statement-breakpoint
456
- CREATE INDEX "idx_audit_action" ON "audit_log" USING btree ("action");
456
+ CREATE INDEX IF NOT EXISTS "idx_audit_action" ON "audit_log" USING btree ("action");
457
457
  --> statement-breakpoint
458
- CREATE INDEX "idx_audit_resource" ON "audit_log" USING btree ("resource_type","resource_id");
458
+ CREATE INDEX IF NOT EXISTS "idx_audit_resource" ON "audit_log" USING btree ("resource_type","resource_id");
459
459
  --> statement-breakpoint
460
- CREATE INDEX "idx_backup_status_node" ON "backup_status" USING btree ("node_id");
460
+ CREATE INDEX IF NOT EXISTS "idx_backup_status_node" ON "backup_status" USING btree ("node_id");
461
461
  --> statement-breakpoint
462
- CREATE INDEX "idx_backup_status_last_backup" ON "backup_status" USING btree ("last_backup_at");
462
+ CREATE INDEX IF NOT EXISTS "idx_backup_status_last_backup" ON "backup_status" USING btree ("last_backup_at");
463
463
  --> statement-breakpoint
464
- CREATE INDEX "idx_bot_instances_tenant" ON "bot_instances" USING btree ("tenant_id");
464
+ CREATE INDEX IF NOT EXISTS "idx_bot_instances_tenant" ON "bot_instances" USING btree ("tenant_id");
465
465
  --> statement-breakpoint
466
- CREATE INDEX "idx_bot_instances_billing_state" ON "bot_instances" USING btree ("billing_state");
466
+ CREATE INDEX IF NOT EXISTS "idx_bot_instances_billing_state" ON "bot_instances" USING btree ("billing_state");
467
467
  --> statement-breakpoint
468
- CREATE INDEX "idx_bot_instances_destroy_after" ON "bot_instances" USING btree ("destroy_after");
468
+ CREATE INDEX IF NOT EXISTS "idx_bot_instances_destroy_after" ON "bot_instances" USING btree ("destroy_after");
469
469
  --> statement-breakpoint
470
- CREATE INDEX "idx_bot_instances_node" ON "bot_instances" USING btree ("node_id");
470
+ CREATE INDEX IF NOT EXISTS "idx_bot_instances_node" ON "bot_instances" USING btree ("node_id");
471
471
  --> statement-breakpoint
472
- CREATE INDEX "idx_bot_profiles_tenant" ON "bot_profiles" USING btree ("tenant_id");
472
+ CREATE INDEX IF NOT EXISTS "idx_bot_profiles_tenant" ON "bot_profiles" USING btree ("tenant_id");
473
473
  --> statement-breakpoint
474
- CREATE INDEX "idx_bot_profiles_name" ON "bot_profiles" USING btree ("tenant_id","name");
474
+ CREATE INDEX IF NOT EXISTS "idx_bot_profiles_name" ON "bot_profiles" USING btree ("tenant_id","name");
475
475
  --> statement-breakpoint
476
- CREATE INDEX "idx_bot_profiles_release_channel" ON "bot_profiles" USING btree ("release_channel");
476
+ CREATE INDEX IF NOT EXISTS "idx_bot_profiles_release_channel" ON "bot_profiles" USING btree ("release_channel");
477
477
  --> statement-breakpoint
478
- CREATE INDEX "idx_bulk_undo_deadline" ON "bulk_undo_grants" USING btree ("undo_deadline");
478
+ CREATE INDEX IF NOT EXISTS "idx_bulk_undo_deadline" ON "bulk_undo_grants" USING btree ("undo_deadline");
479
479
  --> statement-breakpoint
480
- CREATE INDEX "idx_circuit_window" ON "circuit_breaker_states" USING btree ("window_start");
480
+ CREATE INDEX IF NOT EXISTS "idx_circuit_window" ON "circuit_breaker_states" USING btree ("window_start");
481
481
  --> statement-breakpoint
482
- CREATE INDEX "idx_gateway_metrics_minute" ON "gateway_metrics" USING btree ("minute_key");
482
+ CREATE INDEX IF NOT EXISTS "idx_gateway_metrics_minute" ON "gateway_metrics" USING btree ("minute_key");
483
483
  --> statement-breakpoint
484
- CREATE INDEX "idx_gpu_nodes_status" ON "gpu_nodes" USING btree ("status");
484
+ CREATE INDEX IF NOT EXISTS "idx_gpu_nodes_status" ON "gpu_nodes" USING btree ("status");
485
485
  --> statement-breakpoint
486
- CREATE INDEX "idx_gpu_nodes_region" ON "gpu_nodes" USING btree ("region");
486
+ CREATE INDEX IF NOT EXISTS "idx_gpu_nodes_region" ON "gpu_nodes" USING btree ("region");
487
487
  --> statement-breakpoint
488
- CREATE INDEX "idx_reg_tokens_user" ON "node_registration_tokens" USING btree ("user_id");
488
+ CREATE INDEX IF NOT EXISTS "idx_reg_tokens_user" ON "node_registration_tokens" USING btree ("user_id");
489
489
  --> statement-breakpoint
490
- CREATE INDEX "idx_reg_tokens_expires" ON "node_registration_tokens" USING btree ("expires_at");
490
+ CREATE INDEX IF NOT EXISTS "idx_reg_tokens_expires" ON "node_registration_tokens" USING btree ("expires_at");
491
491
  --> statement-breakpoint
492
- CREATE INDEX "idx_node_transitions_node" ON "node_transitions" USING btree ("node_id");
492
+ CREATE INDEX IF NOT EXISTS "idx_node_transitions_node" ON "node_transitions" USING btree ("node_id");
493
493
  --> statement-breakpoint
494
- CREATE INDEX "idx_node_transitions_created" ON "node_transitions" USING btree ("created_at");
494
+ CREATE INDEX IF NOT EXISTS "idx_node_transitions_created" ON "node_transitions" USING btree ("created_at");
495
495
  --> statement-breakpoint
496
- CREATE INDEX "idx_nodes_status" ON "nodes" USING btree ("status");
496
+ CREATE INDEX IF NOT EXISTS "idx_nodes_status" ON "nodes" USING btree ("status");
497
497
  --> statement-breakpoint
498
- CREATE INDEX "idx_nodes_droplet" ON "nodes" USING btree ("droplet_id");
498
+ CREATE INDEX IF NOT EXISTS "idx_nodes_droplet" ON "nodes" USING btree ("droplet_id");
499
499
  --> statement-breakpoint
500
- CREATE INDEX "idx_nodes_node_secret" ON "nodes" USING btree ("node_secret");
500
+ CREATE INDEX IF NOT EXISTS "idx_nodes_node_secret" ON "nodes" USING btree ("node_secret");
501
501
  --> statement-breakpoint
502
- CREATE INDEX "idx_oauth_states_expires" ON "oauth_states" USING btree ("expires_at");
502
+ CREATE INDEX IF NOT EXISTS "idx_oauth_states_expires" ON "oauth_states" USING btree ("expires_at");
503
503
  --> statement-breakpoint
504
- CREATE INDEX "idx_provisioned_phone_tenant" ON "provisioned_phone_numbers" USING btree ("tenant_id");
504
+ CREATE INDEX IF NOT EXISTS "idx_provisioned_phone_tenant" ON "provisioned_phone_numbers" USING btree ("tenant_id");
505
505
  --> statement-breakpoint
506
- CREATE INDEX "idx_provisioned_phone_last_billed" ON "provisioned_phone_numbers" USING btree ("last_billed_at");
506
+ CREATE INDEX IF NOT EXISTS "idx_provisioned_phone_last_billed" ON "provisioned_phone_numbers" USING btree ("last_billed_at");
507
507
  --> statement-breakpoint
508
- CREATE INDEX "idx_recovery_events_node" ON "recovery_events" USING btree ("node_id");
508
+ CREATE INDEX IF NOT EXISTS "idx_recovery_events_node" ON "recovery_events" USING btree ("node_id");
509
509
  --> statement-breakpoint
510
- CREATE INDEX "idx_recovery_events_status" ON "recovery_events" USING btree ("status");
510
+ CREATE INDEX IF NOT EXISTS "idx_recovery_events_status" ON "recovery_events" USING btree ("status");
511
511
  --> statement-breakpoint
512
- CREATE INDEX "idx_restore_log_tenant" ON "restore_log" USING btree ("tenant","restored_at");
512
+ CREATE INDEX IF NOT EXISTS "idx_restore_log_tenant" ON "restore_log" USING btree ("tenant","restored_at");
513
513
  --> statement-breakpoint
514
- CREATE INDEX "idx_restore_log_restored_by" ON "restore_log" USING btree ("restored_by");
514
+ CREATE INDEX IF NOT EXISTS "idx_restore_log_restored_by" ON "restore_log" USING btree ("restored_by");
515
515
  --> statement-breakpoint
516
- CREATE INDEX "idx_snapshots_instance" ON "snapshots" USING btree ("instance_id","created_at" desc);
516
+ CREATE INDEX IF NOT EXISTS "idx_snapshots_instance" ON "snapshots" USING btree ("instance_id","created_at" desc);
517
517
  --> statement-breakpoint
518
- CREATE INDEX "idx_snapshots_user" ON "snapshots" USING btree ("user_id");
518
+ CREATE INDEX IF NOT EXISTS "idx_snapshots_user" ON "snapshots" USING btree ("user_id");
519
519
  --> statement-breakpoint
520
- CREATE INDEX "idx_snapshots_tenant" ON "snapshots" USING btree ("tenant");
520
+ CREATE INDEX IF NOT EXISTS "idx_snapshots_tenant" ON "snapshots" USING btree ("tenant");
521
521
  --> statement-breakpoint
522
- CREATE INDEX "idx_snapshots_type" ON "snapshots" USING btree ("type");
522
+ CREATE INDEX IF NOT EXISTS "idx_snapshots_type" ON "snapshots" USING btree ("type");
523
523
  --> statement-breakpoint
524
- CREATE INDEX "idx_snapshots_expires" ON "snapshots" USING btree ("expires_at");
524
+ CREATE INDEX IF NOT EXISTS "idx_snapshots_expires" ON "snapshots" USING btree ("expires_at");
525
525
  --> statement-breakpoint
526
- CREATE INDEX "idx_tenant_status_status" ON "tenant_status" USING btree ("status");
526
+ CREATE INDEX IF NOT EXISTS "idx_tenant_status_status" ON "tenant_status" USING btree ("status");
527
527
  --> statement-breakpoint
528
- CREATE INDEX "idx_tenant_status_grace" ON "tenant_status" USING btree ("grace_deadline");
528
+ CREATE INDEX IF NOT EXISTS "idx_tenant_status_grace" ON "tenant_status" USING btree ("grace_deadline");
529
529
  --> statement-breakpoint
530
- CREATE INDEX "idx_tenant_status_delete" ON "tenant_status" USING btree ("data_delete_after");
530
+ CREATE INDEX IF NOT EXISTS "idx_tenant_status_delete" ON "tenant_status" USING btree ("data_delete_after");
531
531
  --> statement-breakpoint
532
- CREATE INDEX "idx_vps_sub_tenant" ON "vps_subscriptions" USING btree ("tenant_id");
532
+ CREATE INDEX IF NOT EXISTS "idx_vps_sub_tenant" ON "vps_subscriptions" USING btree ("tenant_id");
533
533
  --> statement-breakpoint
534
- CREATE INDEX "idx_vps_sub_stripe" ON "vps_subscriptions" USING btree ("stripe_subscription_id");
534
+ CREATE INDEX IF NOT EXISTS "idx_vps_sub_stripe" ON "vps_subscriptions" USING btree ("stripe_subscription_id");
535
535
  --> statement-breakpoint
536
- CREATE INDEX "idx_sig_penalties_blocked" ON "webhook_sig_penalties" USING btree ("blocked_until");
536
+ CREATE INDEX IF NOT EXISTS "idx_sig_penalties_blocked" ON "webhook_sig_penalties" USING btree ("blocked_until");
537
537
  --> statement-breakpoint
538
- CREATE INDEX "marketplace_plugins_enabled_idx" ON "marketplace_plugins" USING btree ("enabled");
538
+ CREATE INDEX IF NOT EXISTS "marketplace_plugins_enabled_idx" ON "marketplace_plugins" USING btree ("enabled");
539
539
  --> statement-breakpoint
540
- CREATE INDEX "onboarding_sessions_user_id_idx" ON "onboarding_sessions" USING btree ("user_id");
540
+ CREATE INDEX IF NOT EXISTS "onboarding_sessions_user_id_idx" ON "onboarding_sessions" USING btree ("user_id");
541
541
  --> statement-breakpoint
542
- CREATE INDEX "onboarding_sessions_anonymous_id_idx" ON "onboarding_sessions" USING btree ("anonymous_id");
542
+ CREATE INDEX IF NOT EXISTS "onboarding_sessions_anonymous_id_idx" ON "onboarding_sessions" USING btree ("anonymous_id");
543
543
  --> statement-breakpoint
544
- CREATE INDEX "setup_sessions_session_id_idx" ON "setup_sessions" USING btree ("session_id");
544
+ CREATE INDEX IF NOT EXISTS "setup_sessions_session_id_idx" ON "setup_sessions" USING btree ("session_id");
545
545
  --> statement-breakpoint
546
- CREATE INDEX "setup_sessions_plugin_id_idx" ON "setup_sessions" USING btree ("plugin_id");
546
+ CREATE INDEX IF NOT EXISTS "setup_sessions_plugin_id_idx" ON "setup_sessions" USING btree ("plugin_id");
547
547
  --> statement-breakpoint
548
- CREATE INDEX "plugin_configs_bot_id_idx" ON "plugin_configs" USING btree ("bot_id");
548
+ CREATE INDEX IF NOT EXISTS "plugin_configs_bot_id_idx" ON "plugin_configs" USING btree ("bot_id");
549
549
  --> statement-breakpoint
550
- CREATE INDEX "plugin_configs_setup_session_idx" ON "plugin_configs" USING btree ("setup_session_id");
550
+ CREATE INDEX IF NOT EXISTS "plugin_configs_setup_session_idx" ON "plugin_configs" USING btree ("setup_session_id");
551
551
  --> statement-breakpoint
552
552
  CREATE INDEX IF NOT EXISTS "adapter_rate_overrides_adapter_idx" ON "adapter_rate_overrides" ("adapter_id");
553
553
  --> statement-breakpoint
554
554
  CREATE INDEX IF NOT EXISTS "adapter_rate_overrides_status_idx" ON "adapter_rate_overrides" ("status");
555
555
  --> statement-breakpoint
556
- CREATE INDEX "idx_gpu_allocations_gpu_node_id" ON "gpu_allocations" USING btree ("gpu_node_id");
556
+ CREATE INDEX IF NOT EXISTS "idx_gpu_allocations_gpu_node_id" ON "gpu_allocations" USING btree ("gpu_node_id");
557
557
  --> statement-breakpoint
558
- CREATE INDEX "idx_gpu_allocations_tenant_id" ON "gpu_allocations" USING btree ("tenant_id");
558
+ CREATE INDEX IF NOT EXISTS "idx_gpu_allocations_tenant_id" ON "gpu_allocations" USING btree ("tenant_id");
559
559
  --> statement-breakpoint
560
560
  CREATE INDEX IF NOT EXISTS "page_contexts_updated_at_idx" ON "page_contexts" USING btree ("updated_at");
561
561
  --> statement-breakpoint
562
- CREATE INDEX "idx_provider_costs_capability" ON "provider_costs" USING btree ("capability");
562
+ CREATE INDEX IF NOT EXISTS "idx_provider_costs_capability" ON "provider_costs" USING btree ("capability");
563
563
  --> statement-breakpoint
564
- CREATE INDEX "idx_provider_costs_adapter" ON "provider_costs" USING btree ("adapter");
564
+ CREATE INDEX IF NOT EXISTS "idx_provider_costs_adapter" ON "provider_costs" USING btree ("adapter");
565
565
  --> statement-breakpoint
566
- CREATE INDEX "idx_provider_costs_active" ON "provider_costs" USING btree ("is_active");
566
+ CREATE INDEX IF NOT EXISTS "idx_provider_costs_active" ON "provider_costs" USING btree ("is_active");
567
567
  --> statement-breakpoint
568
- CREATE INDEX "idx_recovery_items_event" ON "recovery_items" USING btree ("recovery_event_id");
568
+ CREATE INDEX IF NOT EXISTS "idx_recovery_items_event" ON "recovery_items" USING btree ("recovery_event_id");
569
569
  --> statement-breakpoint
570
- CREATE INDEX "idx_recovery_items_tenant" ON "recovery_items" USING btree ("tenant");
570
+ CREATE INDEX IF NOT EXISTS "idx_recovery_items_tenant" ON "recovery_items" USING btree ("tenant");
571
571
  --> statement-breakpoint
572
- CREATE INDEX "idx_sell_rates_capability" ON "sell_rates" USING btree ("capability");
572
+ CREATE INDEX IF NOT EXISTS "idx_sell_rates_capability" ON "sell_rates" USING btree ("capability");
573
573
  --> statement-breakpoint
574
- CREATE INDEX "idx_sell_rates_active" ON "sell_rates" USING btree ("is_active");
574
+ CREATE INDEX IF NOT EXISTS "idx_sell_rates_active" ON "sell_rates" USING btree ("is_active");
575
575
  --> statement-breakpoint
576
- ALTER TABLE "marketplace_plugins" ADD COLUMN "previous_version" text;
576
+ ALTER TABLE "marketplace_plugins" ADD COLUMN IF NOT EXISTS "previous_version" text;
577
577
  --> statement-breakpoint
578
- ALTER TABLE "marketplace_plugins" ADD COLUMN "manifest" jsonb;
578
+ ALTER TABLE "marketplace_plugins" ADD COLUMN IF NOT EXISTS "manifest" jsonb;
579
579
  --> statement-breakpoint
580
- CREATE UNIQUE INDEX "idx_gateway_metrics_unique" ON "gateway_metrics" USING btree ("minute_key","capability");
580
+ CREATE UNIQUE INDEX IF NOT EXISTS "idx_gateway_metrics_unique" ON "gateway_metrics" USING btree ("minute_key","capability");
581
581
  --> statement-breakpoint
582
582
  INSERT INTO "onboarding_scripts" ("id", "content", "version", "updated_at", "updated_by")
583
583
  VALUES ('seed-v1', $onboarding$# WOPR Onboarding
@@ -1,4 +1,4 @@
1
- CREATE TABLE "gateway_service_keys" (
1
+ CREATE TABLE IF NOT EXISTS "gateway_service_keys" (
2
2
  "id" text PRIMARY KEY NOT NULL,
3
3
  "key_hash" text NOT NULL,
4
4
  "tenant_id" text NOT NULL,
@@ -7,8 +7,8 @@ CREATE TABLE "gateway_service_keys" (
7
7
  "revoked_at" bigint
8
8
  );
9
9
  --> statement-breakpoint
10
- CREATE UNIQUE INDEX "idx_gateway_service_keys_hash" ON "gateway_service_keys" USING btree ("key_hash");
10
+ CREATE UNIQUE INDEX IF NOT EXISTS "idx_gateway_service_keys_hash" ON "gateway_service_keys" USING btree ("key_hash");
11
11
  --> statement-breakpoint
12
- CREATE INDEX "idx_gateway_service_keys_tenant" ON "gateway_service_keys" USING btree ("tenant_id");
12
+ CREATE INDEX IF NOT EXISTS "idx_gateway_service_keys_tenant" ON "gateway_service_keys" USING btree ("tenant_id");
13
13
  --> statement-breakpoint
14
- CREATE INDEX "idx_gateway_service_keys_instance" ON "gateway_service_keys" USING btree ("instance_id");
14
+ CREATE INDEX IF NOT EXISTS "idx_gateway_service_keys_instance" ON "gateway_service_keys" USING btree ("instance_id");
@@ -9,7 +9,7 @@ DO $$ BEGIN
9
9
  CREATE TYPE "public"."entry_side" AS ENUM('debit','credit');
10
10
  EXCEPTION WHEN duplicate_object THEN NULL;
11
11
  END $$;--> statement-breakpoint
12
- CREATE TABLE "accounts" (
12
+ CREATE TABLE IF NOT EXISTS "accounts" (
13
13
  "id" text PRIMARY KEY NOT NULL,
14
14
  "code" text NOT NULL,
15
15
  "name" text NOT NULL,
@@ -18,7 +18,7 @@ CREATE TABLE "accounts" (
18
18
  "tenant_id" text,
19
19
  "created_at" text DEFAULT (now()) NOT NULL
20
20
  );--> statement-breakpoint
21
- CREATE TABLE "journal_entries" (
21
+ CREATE TABLE IF NOT EXISTS "journal_entries" (
22
22
  "id" text PRIMARY KEY NOT NULL,
23
23
  "posted_at" text DEFAULT (now()) NOT NULL,
24
24
  "entry_type" text NOT NULL,
@@ -28,29 +28,29 @@ CREATE TABLE "journal_entries" (
28
28
  "metadata" jsonb,
29
29
  "created_by" text
30
30
  );--> statement-breakpoint
31
- CREATE TABLE "journal_lines" (
31
+ CREATE TABLE IF NOT EXISTS "journal_lines" (
32
32
  "id" text PRIMARY KEY NOT NULL,
33
33
  "journal_entry_id" text NOT NULL REFERENCES "journal_entries"("id"),
34
34
  "account_id" text NOT NULL REFERENCES "accounts"("id"),
35
35
  "amount" bigint NOT NULL,
36
36
  "side" "entry_side" NOT NULL
37
37
  );--> statement-breakpoint
38
- CREATE TABLE "account_balances" (
38
+ CREATE TABLE IF NOT EXISTS "account_balances" (
39
39
  "account_id" text PRIMARY KEY NOT NULL REFERENCES "accounts"("id"),
40
40
  "balance" bigint DEFAULT 0 NOT NULL,
41
41
  "last_updated" text DEFAULT (now()) NOT NULL
42
42
  );--> statement-breakpoint
43
- CREATE UNIQUE INDEX "idx_accounts_code" ON "accounts" USING btree ("code");--> statement-breakpoint
44
- CREATE INDEX "idx_accounts_tenant" ON "accounts" USING btree ("tenant_id") WHERE "tenant_id" IS NOT NULL;--> statement-breakpoint
45
- CREATE INDEX "idx_accounts_type" ON "accounts" USING btree ("type");--> statement-breakpoint
46
- CREATE UNIQUE INDEX "idx_je_reference" ON "journal_entries" USING btree ("reference_id") WHERE "reference_id" IS NOT NULL;--> statement-breakpoint
47
- CREATE INDEX "idx_je_tenant" ON "journal_entries" USING btree ("tenant_id");--> statement-breakpoint
48
- CREATE INDEX "idx_je_type" ON "journal_entries" USING btree ("entry_type");--> statement-breakpoint
49
- CREATE INDEX "idx_je_posted" ON "journal_entries" USING btree ("posted_at");--> statement-breakpoint
50
- CREATE INDEX "idx_je_tenant_posted" ON "journal_entries" USING btree ("tenant_id","posted_at");--> statement-breakpoint
51
- CREATE INDEX "idx_jl_entry" ON "journal_lines" USING btree ("journal_entry_id");--> statement-breakpoint
52
- CREATE INDEX "idx_jl_account" ON "journal_lines" USING btree ("account_id");--> statement-breakpoint
53
- CREATE INDEX "idx_jl_account_side" ON "journal_lines" USING btree ("account_id","side");--> statement-breakpoint
43
+ CREATE UNIQUE INDEX IF NOT EXISTS "idx_accounts_code" ON "accounts" USING btree ("code");--> statement-breakpoint
44
+ CREATE INDEX IF NOT EXISTS "idx_accounts_tenant" ON "accounts" USING btree ("tenant_id") WHERE "tenant_id" IS NOT NULL;--> statement-breakpoint
45
+ CREATE INDEX IF NOT EXISTS "idx_accounts_type" ON "accounts" USING btree ("type");--> statement-breakpoint
46
+ CREATE UNIQUE INDEX IF NOT EXISTS "idx_je_reference" ON "journal_entries" USING btree ("reference_id") WHERE "reference_id" IS NOT NULL;--> statement-breakpoint
47
+ CREATE INDEX IF NOT EXISTS "idx_je_tenant" ON "journal_entries" USING btree ("tenant_id");--> statement-breakpoint
48
+ CREATE INDEX IF NOT EXISTS "idx_je_type" ON "journal_entries" USING btree ("entry_type");--> statement-breakpoint
49
+ CREATE INDEX IF NOT EXISTS "idx_je_posted" ON "journal_entries" USING btree ("posted_at");--> statement-breakpoint
50
+ CREATE INDEX IF NOT EXISTS "idx_je_tenant_posted" ON "journal_entries" USING btree ("tenant_id","posted_at");--> statement-breakpoint
51
+ CREATE INDEX IF NOT EXISTS "idx_jl_entry" ON "journal_lines" USING btree ("journal_entry_id");--> statement-breakpoint
52
+ CREATE INDEX IF NOT EXISTS "idx_jl_account" ON "journal_lines" USING btree ("account_id");--> statement-breakpoint
53
+ CREATE INDEX IF NOT EXISTS "idx_jl_account_side" ON "journal_lines" USING btree ("account_id","side");--> statement-breakpoint
54
54
 
55
55
  -- Seed system accounts
56
56
  INSERT INTO "accounts" ("id", "code", "name", "type", "normal_side") VALUES
@@ -1,7 +1,7 @@
1
- ALTER TABLE "crypto_charges" ADD COLUMN "chain" text;--> statement-breakpoint
2
- ALTER TABLE "crypto_charges" ADD COLUMN "token" text;--> statement-breakpoint
3
- ALTER TABLE "crypto_charges" ADD COLUMN "deposit_address" text;--> statement-breakpoint
4
- ALTER TABLE "crypto_charges" ADD COLUMN "derivation_index" integer;--> statement-breakpoint
5
- CREATE INDEX "idx_crypto_charges_deposit_address" ON "crypto_charges" USING btree ("deposit_address");--> statement-breakpoint
6
- CREATE UNIQUE INDEX "uq_crypto_charges_deposit_address" ON "crypto_charges" ("deposit_address") WHERE "deposit_address" IS NOT NULL;--> statement-breakpoint
7
- CREATE UNIQUE INDEX "uq_crypto_charges_derivation_index" ON "crypto_charges" ("derivation_index") WHERE "derivation_index" IS NOT NULL;
1
+ ALTER TABLE "crypto_charges" ADD COLUMN IF NOT EXISTS "chain" text;--> statement-breakpoint
2
+ ALTER TABLE "crypto_charges" ADD COLUMN IF NOT EXISTS "token" text;--> statement-breakpoint
3
+ ALTER TABLE "crypto_charges" ADD COLUMN IF NOT EXISTS "deposit_address" text;--> statement-breakpoint
4
+ ALTER TABLE "crypto_charges" ADD COLUMN IF NOT EXISTS "derivation_index" integer;--> statement-breakpoint
5
+ CREATE INDEX IF NOT EXISTS "idx_crypto_charges_deposit_address" ON "crypto_charges" USING btree ("deposit_address");--> statement-breakpoint
6
+ CREATE UNIQUE INDEX IF NOT EXISTS "uq_crypto_charges_deposit_address" ON "crypto_charges" ("deposit_address") WHERE "deposit_address" IS NOT NULL;--> statement-breakpoint
7
+ CREATE UNIQUE INDEX IF NOT EXISTS "uq_crypto_charges_derivation_index" ON "crypto_charges" ("derivation_index") WHERE "derivation_index" IS NOT NULL;
@@ -1,2 +1,2 @@
1
- ALTER TABLE "organization_invites" ADD COLUMN "accepted_at" bigint;--> statement-breakpoint
2
- ALTER TABLE "organization_invites" ADD COLUMN "revoked_at" bigint;
1
+ ALTER TABLE "organization_invites" ADD COLUMN IF NOT EXISTS "accepted_at" bigint;--> statement-breakpoint
2
+ ALTER TABLE "organization_invites" ADD COLUMN IF NOT EXISTS "revoked_at" bigint;
@@ -1,6 +1,6 @@
1
- ALTER TABLE "payment_methods" ADD COLUMN "oracle_address" text;
1
+ ALTER TABLE "payment_methods" ADD COLUMN IF NOT EXISTS "oracle_address" text;
2
2
  --> statement-breakpoint
3
- ALTER TABLE "payment_methods" ADD COLUMN "xpub" text;
3
+ ALTER TABLE "payment_methods" ADD COLUMN IF NOT EXISTS "xpub" text;
4
4
  --> statement-breakpoint
5
5
  UPDATE "payment_methods" SET "oracle_address" = '0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70' WHERE "id" = 'ETH:base';
6
6
  --> statement-breakpoint
@@ -11,4 +11,4 @@ CREATE TABLE IF NOT EXISTS "notification_templates" (
11
11
  CONSTRAINT "notification_templates_name_unique" UNIQUE("name")
12
12
  );
13
13
  --> statement-breakpoint
14
- ALTER TABLE "notification_preferences" ADD COLUMN "fleet_updates" boolean DEFAULT true NOT NULL;
14
+ ALTER TABLE "notification_preferences" ADD COLUMN IF NOT EXISTS "fleet_updates" boolean DEFAULT true NOT NULL;