@voyant-travel/finance 0.125.0 → 0.126.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.
@@ -0,0 +1,938 @@
1
+ DO $$ BEGIN
2
+ CREATE TYPE "public"."ap_service_type" AS ENUM('transport', 'flight', 'accommodation', 'guide', 'meal', 'experience', 'insurance', 'other');
3
+ EXCEPTION WHEN duplicate_object THEN null;
4
+ END $$;--> statement-breakpoint
5
+ DO $$ BEGIN
6
+ CREATE TYPE "public"."capture_mode" AS ENUM('automatic', 'manual');
7
+ EXCEPTION WHEN duplicate_object THEN null;
8
+ END $$;--> statement-breakpoint
9
+ DO $$ BEGIN
10
+ CREATE TYPE "public"."commission_model" AS ENUM('percentage', 'fixed', 'markup', 'net');
11
+ EXCEPTION WHEN duplicate_object THEN null;
12
+ END $$;--> statement-breakpoint
13
+ DO $$ BEGIN
14
+ CREATE TYPE "public"."commission_recipient_type" AS ENUM('channel', 'affiliate', 'agency', 'agent', 'internal', 'supplier', 'other');
15
+ EXCEPTION WHEN duplicate_object THEN null;
16
+ END $$;--> statement-breakpoint
17
+ DO $$ BEGIN
18
+ CREATE TYPE "public"."commission_status" AS ENUM('pending', 'accrued', 'payable', 'paid', 'void');
19
+ EXCEPTION WHEN duplicate_object THEN null;
20
+ END $$;--> statement-breakpoint
21
+ DO $$ BEGIN
22
+ CREATE TYPE "public"."cost_allocation_split_method" AS ENUM('manual', 'per_pax', 'equal', 'weighted');
23
+ EXCEPTION WHEN duplicate_object THEN null;
24
+ END $$;--> statement-breakpoint
25
+ DO $$ BEGIN
26
+ CREATE TYPE "public"."cost_allocation_target_type" AS ENUM('departure', 'product', 'booking', 'traveler', 'unattributed');
27
+ EXCEPTION WHEN duplicate_object THEN null;
28
+ END $$;--> statement-breakpoint
29
+ DO $$ BEGIN
30
+ CREATE TYPE "public"."credit_note_status" AS ENUM('draft', 'issued', 'applied');
31
+ EXCEPTION WHEN duplicate_object THEN null;
32
+ END $$;--> statement-breakpoint
33
+ DO $$ BEGIN
34
+ CREATE TYPE "public"."guarantee_status" AS ENUM('pending', 'active', 'released', 'failed', 'cancelled', 'expired');
35
+ EXCEPTION WHEN duplicate_object THEN null;
36
+ END $$;--> statement-breakpoint
37
+ DO $$ BEGIN
38
+ CREATE TYPE "public"."guarantee_type" AS ENUM('deposit', 'credit_card', 'preauth', 'card_on_file', 'bank_transfer', 'voucher', 'agency_letter', 'other');
39
+ EXCEPTION WHEN duplicate_object THEN null;
40
+ END $$;--> statement-breakpoint
41
+ DO $$ BEGIN
42
+ CREATE TYPE "public"."invoice_number_reset_strategy" AS ENUM('never', 'annual', 'monthly');
43
+ EXCEPTION WHEN duplicate_object THEN null;
44
+ END $$;--> statement-breakpoint
45
+ DO $$ BEGIN
46
+ CREATE TYPE "public"."invoice_number_series_scope" AS ENUM('invoice', 'proforma', 'credit_note');
47
+ EXCEPTION WHEN duplicate_object THEN null;
48
+ END $$;--> statement-breakpoint
49
+ DO $$ BEGIN
50
+ CREATE TYPE "public"."invoice_rendition_format" AS ENUM('html', 'pdf', 'xml', 'json');
51
+ EXCEPTION WHEN duplicate_object THEN null;
52
+ END $$;--> statement-breakpoint
53
+ DO $$ BEGIN
54
+ CREATE TYPE "public"."invoice_rendition_status" AS ENUM('pending', 'ready', 'failed', 'stale');
55
+ EXCEPTION WHEN duplicate_object THEN null;
56
+ END $$;--> statement-breakpoint
57
+ DO $$ BEGIN
58
+ CREATE TYPE "public"."invoice_status" AS ENUM('draft', 'pending_external_allocation', 'issued', 'partially_paid', 'paid', 'overdue', 'void');
59
+ EXCEPTION WHEN duplicate_object THEN null;
60
+ END $$;--> statement-breakpoint
61
+ DO $$ BEGIN
62
+ CREATE TYPE "public"."invoice_template_body_format" AS ENUM('html', 'markdown', 'lexical_json');
63
+ EXCEPTION WHEN duplicate_object THEN null;
64
+ END $$;--> statement-breakpoint
65
+ DO $$ BEGIN
66
+ CREATE TYPE "public"."invoice_type" AS ENUM('invoice', 'proforma', 'credit_note');
67
+ EXCEPTION WHEN duplicate_object THEN null;
68
+ END $$;--> statement-breakpoint
69
+ DO $$ BEGIN
70
+ CREATE TYPE "public"."payment_authorization_status" AS ENUM('pending', 'authorized', 'partially_captured', 'captured', 'voided', 'failed', 'expired');
71
+ EXCEPTION WHEN duplicate_object THEN null;
72
+ END $$;--> statement-breakpoint
73
+ DO $$ BEGIN
74
+ CREATE TYPE "public"."payment_capture_status" AS ENUM('pending', 'completed', 'failed', 'refunded', 'voided');
75
+ EXCEPTION WHEN duplicate_object THEN null;
76
+ END $$;--> statement-breakpoint
77
+ DO $$ BEGIN
78
+ CREATE TYPE "public"."payment_instrument_owner_type" AS ENUM('client', 'supplier', 'channel', 'agency', 'internal', 'other');
79
+ EXCEPTION WHEN duplicate_object THEN null;
80
+ END $$;--> statement-breakpoint
81
+ DO $$ BEGIN
82
+ CREATE TYPE "public"."payment_instrument_status" AS ENUM('active', 'inactive', 'expired', 'revoked', 'failed_verification');
83
+ EXCEPTION WHEN duplicate_object THEN null;
84
+ END $$;--> statement-breakpoint
85
+ DO $$ BEGIN
86
+ CREATE TYPE "public"."payment_instrument_type" AS ENUM('credit_card', 'debit_card', 'bank_account', 'wallet', 'voucher', 'direct_bill', 'cash', 'other');
87
+ EXCEPTION WHEN duplicate_object THEN null;
88
+ END $$;--> statement-breakpoint
89
+ DO $$ BEGIN
90
+ CREATE TYPE "public"."payment_method" AS ENUM('bank_transfer', 'credit_card', 'debit_card', 'cash', 'cheque', 'wallet', 'direct_bill', 'voucher', 'other');
91
+ EXCEPTION WHEN duplicate_object THEN null;
92
+ END $$;--> statement-breakpoint
93
+ DO $$ BEGIN
94
+ CREATE TYPE "public"."payment_schedule_status" AS ENUM('pending', 'due', 'paid', 'waived', 'cancelled', 'expired');
95
+ EXCEPTION WHEN duplicate_object THEN null;
96
+ END $$;--> statement-breakpoint
97
+ DO $$ BEGIN
98
+ CREATE TYPE "public"."payment_schedule_type" AS ENUM('deposit', 'installment', 'balance', 'hold', 'other');
99
+ EXCEPTION WHEN duplicate_object THEN null;
100
+ END $$;--> statement-breakpoint
101
+ DO $$ BEGIN
102
+ CREATE TYPE "public"."payment_session_status" AS ENUM('pending', 'requires_redirect', 'processing', 'authorized', 'paid', 'failed', 'cancelled', 'expired');
103
+ EXCEPTION WHEN duplicate_object THEN null;
104
+ END $$;--> statement-breakpoint
105
+ DO $$ BEGIN
106
+ CREATE TYPE "public"."payment_session_target_type" AS ENUM('booking', 'order', 'invoice', 'booking_payment_schedule', 'booking_guarantee', 'flight_order', 'other');
107
+ EXCEPTION WHEN duplicate_object THEN null;
108
+ END $$;--> statement-breakpoint
109
+ DO $$ BEGIN
110
+ CREATE TYPE "public"."payment_status" AS ENUM('pending', 'completed', 'failed', 'refunded');
111
+ EXCEPTION WHEN duplicate_object THEN null;
112
+ END $$;--> statement-breakpoint
113
+ DO $$ BEGIN
114
+ CREATE TYPE "public"."supplier_invoice_status" AS ENUM('draft', 'received', 'approved', 'partially_paid', 'paid', 'disputed', 'void');
115
+ EXCEPTION WHEN duplicate_object THEN null;
116
+ END $$;--> statement-breakpoint
117
+ DO $$ BEGIN
118
+ CREATE TYPE "public"."tax_regime_code" AS ENUM('standard', 'reduced', 'exempt', 'reverse_charge', 'margin_scheme_art311', 'zero_rated', 'out_of_scope', 'other');
119
+ EXCEPTION WHEN duplicate_object THEN null;
120
+ END $$;--> statement-breakpoint
121
+ DO $$ BEGIN
122
+ CREATE TYPE "public"."tax_scope" AS ENUM('included', 'excluded', 'withheld');
123
+ EXCEPTION WHEN duplicate_object THEN null;
124
+ END $$;--> statement-breakpoint
125
+ DO $$ BEGIN
126
+ CREATE TYPE "public"."voucher_source_type" AS ENUM('refund', 'cancellation_credit', 'gift', 'manual', 'promo');
127
+ EXCEPTION WHEN duplicate_object THEN null;
128
+ END $$;--> statement-breakpoint
129
+ DO $$ BEGIN
130
+ CREATE TYPE "public"."voucher_status" AS ENUM('active', 'redeemed', 'expired', 'void');
131
+ EXCEPTION WHEN duplicate_object THEN null;
132
+ END $$;--> statement-breakpoint
133
+ DO $$ BEGIN
134
+ CREATE TYPE "public"."tax_class_applies_to" AS ENUM('base', 'addon', 'accommodation', 'all');
135
+ EXCEPTION WHEN duplicate_object THEN null;
136
+ END $$;--> statement-breakpoint
137
+ DO $$ BEGIN
138
+ CREATE TYPE "public"."tax_policy_side" AS ENUM('sell', 'buy');
139
+ EXCEPTION WHEN duplicate_object THEN null;
140
+ END $$;--> statement-breakpoint
141
+ CREATE TABLE "booking_guarantees" (
142
+ "id" text PRIMARY KEY NOT NULL,
143
+ "booking_id" text NOT NULL,
144
+ "booking_payment_schedule_id" text,
145
+ "booking_item_id" text,
146
+ "guarantee_type" "guarantee_type" NOT NULL,
147
+ "status" "guarantee_status" DEFAULT 'pending' NOT NULL,
148
+ "payment_instrument_id" text,
149
+ "payment_authorization_id" text,
150
+ "currency" text,
151
+ "amount_cents" integer,
152
+ "provider" text,
153
+ "reference_number" text,
154
+ "guaranteed_at" timestamp with time zone,
155
+ "expires_at" timestamp with time zone,
156
+ "released_at" timestamp with time zone,
157
+ "notes" text,
158
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
159
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
160
+ CONSTRAINT "ck_booking_guarantees_currency_amount" CHECK (("booking_guarantees"."currency" IS NULL) = ("booking_guarantees"."amount_cents" IS NULL))
161
+ );
162
+ --> statement-breakpoint
163
+ CREATE TABLE "booking_item_commissions" (
164
+ "id" text PRIMARY KEY NOT NULL,
165
+ "booking_item_id" text NOT NULL,
166
+ "channel_id" text,
167
+ "recipient_type" "commission_recipient_type" NOT NULL,
168
+ "commission_model" "commission_model" DEFAULT 'percentage' NOT NULL,
169
+ "currency" text,
170
+ "amount_cents" integer,
171
+ "rate_basis_points" integer,
172
+ "status" "commission_status" DEFAULT 'pending' NOT NULL,
173
+ "payable_at" date,
174
+ "paid_at" date,
175
+ "notes" text,
176
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
177
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
178
+ CONSTRAINT "ck_booking_item_commissions_currency_amount" CHECK (("booking_item_commissions"."currency" IS NULL) = ("booking_item_commissions"."amount_cents" IS NULL))
179
+ );
180
+ --> statement-breakpoint
181
+ CREATE TABLE "booking_item_tax_lines" (
182
+ "id" text PRIMARY KEY NOT NULL,
183
+ "booking_item_id" text NOT NULL,
184
+ "code" text,
185
+ "name" text NOT NULL,
186
+ "jurisdiction" text,
187
+ "scope" "tax_scope" DEFAULT 'excluded' NOT NULL,
188
+ "currency" text NOT NULL,
189
+ "amount_cents" integer NOT NULL,
190
+ "rate_basis_points" integer,
191
+ "included_in_price" boolean DEFAULT false NOT NULL,
192
+ "remittance_party" text,
193
+ "sort_order" integer DEFAULT 0 NOT NULL,
194
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
195
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
196
+ );
197
+ --> statement-breakpoint
198
+ CREATE TABLE "booking_payment_schedules" (
199
+ "id" text PRIMARY KEY NOT NULL,
200
+ "booking_id" text NOT NULL,
201
+ "booking_item_id" text,
202
+ "schedule_type" "payment_schedule_type" DEFAULT 'balance' NOT NULL,
203
+ "status" "payment_schedule_status" DEFAULT 'pending' NOT NULL,
204
+ "due_date" date NOT NULL,
205
+ "currency" text NOT NULL,
206
+ "amount_cents" integer NOT NULL,
207
+ "notes" text,
208
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
209
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
210
+ );
211
+ --> statement-breakpoint
212
+ CREATE TABLE "finance_notes" (
213
+ "id" text PRIMARY KEY NOT NULL,
214
+ "invoice_id" text NOT NULL,
215
+ "author_id" text NOT NULL,
216
+ "content" text NOT NULL,
217
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
218
+ );
219
+ --> statement-breakpoint
220
+ CREATE TABLE "invoice_attachments" (
221
+ "id" text PRIMARY KEY NOT NULL,
222
+ "invoice_id" text NOT NULL,
223
+ "kind" text DEFAULT 'supporting_document' NOT NULL,
224
+ "name" text NOT NULL,
225
+ "mime_type" text,
226
+ "file_size" integer,
227
+ "storage_key" text,
228
+ "checksum" text,
229
+ "metadata" jsonb,
230
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
231
+ );
232
+ --> statement-breakpoint
233
+ CREATE TABLE "invoice_external_refs" (
234
+ "id" text PRIMARY KEY NOT NULL,
235
+ "invoice_id" text NOT NULL,
236
+ "provider" text NOT NULL,
237
+ "external_id" text,
238
+ "external_number" text,
239
+ "external_url" text,
240
+ "status" text,
241
+ "metadata" jsonb,
242
+ "synced_at" timestamp with time zone,
243
+ "sync_error" text,
244
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
245
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
246
+ );
247
+ --> statement-breakpoint
248
+ CREATE TABLE "invoice_number_series" (
249
+ "id" text PRIMARY KEY NOT NULL,
250
+ "code" text NOT NULL,
251
+ "name" text NOT NULL,
252
+ "prefix" text DEFAULT '' NOT NULL,
253
+ "separator" text DEFAULT '' NOT NULL,
254
+ "pad_length" integer DEFAULT 4 NOT NULL,
255
+ "current_sequence" integer DEFAULT 0 NOT NULL,
256
+ "reset_strategy" "invoice_number_reset_strategy" DEFAULT 'never' NOT NULL,
257
+ "reset_at" timestamp with time zone,
258
+ "scope" "invoice_number_series_scope" DEFAULT 'invoice' NOT NULL,
259
+ "is_default" boolean DEFAULT false NOT NULL,
260
+ "external_provider" text,
261
+ "external_config_key" text,
262
+ "active" boolean DEFAULT true NOT NULL,
263
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
264
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
265
+ CONSTRAINT "invoice_number_series_code_unique" UNIQUE("code")
266
+ );
267
+ --> statement-breakpoint
268
+ CREATE TABLE "invoice_renditions" (
269
+ "id" text PRIMARY KEY NOT NULL,
270
+ "invoice_id" text NOT NULL,
271
+ "template_id" text,
272
+ "format" "invoice_rendition_format" DEFAULT 'pdf' NOT NULL,
273
+ "status" "invoice_rendition_status" DEFAULT 'pending' NOT NULL,
274
+ "storage_key" text,
275
+ "file_size" integer,
276
+ "checksum" text,
277
+ "language" text,
278
+ "error_message" text,
279
+ "generated_at" timestamp with time zone,
280
+ "metadata" jsonb,
281
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
282
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
283
+ );
284
+ --> statement-breakpoint
285
+ CREATE TABLE "invoice_templates" (
286
+ "id" text PRIMARY KEY NOT NULL,
287
+ "name" text NOT NULL,
288
+ "slug" text NOT NULL,
289
+ "language" text DEFAULT 'en' NOT NULL,
290
+ "jurisdiction" text,
291
+ "body_format" "invoice_template_body_format" DEFAULT 'html' NOT NULL,
292
+ "body" text NOT NULL,
293
+ "css_styles" text,
294
+ "is_default" boolean DEFAULT false NOT NULL,
295
+ "active" boolean DEFAULT true NOT NULL,
296
+ "metadata" jsonb,
297
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
298
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
299
+ CONSTRAINT "invoice_templates_slug_unique" UNIQUE("slug")
300
+ );
301
+ --> statement-breakpoint
302
+ CREATE TABLE "payment_instruments" (
303
+ "id" text PRIMARY KEY NOT NULL,
304
+ "owner_type" "payment_instrument_owner_type" DEFAULT 'client' NOT NULL,
305
+ "person_id" text,
306
+ "organization_id" text,
307
+ "supplier_id" text,
308
+ "channel_id" text,
309
+ "instrument_type" "payment_instrument_type" NOT NULL,
310
+ "status" "payment_instrument_status" DEFAULT 'active' NOT NULL,
311
+ "label" text NOT NULL,
312
+ "provider" text,
313
+ "brand" text,
314
+ "last4" text,
315
+ "holder_name" text,
316
+ "expiry_month" integer,
317
+ "expiry_year" integer,
318
+ "external_token" text,
319
+ "external_customer_id" text,
320
+ "billing_email" text,
321
+ "billing_address" text,
322
+ "direct_bill_reference" text,
323
+ "notes" text,
324
+ "metadata" jsonb,
325
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
326
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
327
+ );
328
+ --> statement-breakpoint
329
+ CREATE TABLE "payment_authorizations" (
330
+ "id" text PRIMARY KEY NOT NULL,
331
+ "booking_id" text,
332
+ "order_id" text,
333
+ "invoice_id" text,
334
+ "booking_guarantee_id" text,
335
+ "payment_instrument_id" text,
336
+ "status" "payment_authorization_status" DEFAULT 'pending' NOT NULL,
337
+ "capture_mode" "capture_mode" DEFAULT 'manual' NOT NULL,
338
+ "currency" text NOT NULL,
339
+ "amount_cents" integer NOT NULL,
340
+ "provider" text,
341
+ "external_authorization_id" text,
342
+ "approval_code" text,
343
+ "authorized_at" timestamp with time zone,
344
+ "expires_at" timestamp with time zone,
345
+ "voided_at" timestamp with time zone,
346
+ "notes" text,
347
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
348
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
349
+ );
350
+ --> statement-breakpoint
351
+ CREATE TABLE "payment_captures" (
352
+ "id" text PRIMARY KEY NOT NULL,
353
+ "payment_authorization_id" text,
354
+ "invoice_id" text,
355
+ "status" "payment_capture_status" DEFAULT 'pending' NOT NULL,
356
+ "currency" text NOT NULL,
357
+ "amount_cents" integer NOT NULL,
358
+ "provider" text,
359
+ "external_capture_id" text,
360
+ "captured_at" timestamp with time zone,
361
+ "settled_at" timestamp with time zone,
362
+ "notes" text,
363
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
364
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
365
+ );
366
+ --> statement-breakpoint
367
+ CREATE TABLE "payment_sessions" (
368
+ "id" text PRIMARY KEY NOT NULL,
369
+ "target_type" "payment_session_target_type" DEFAULT 'other' NOT NULL,
370
+ "target_id" text,
371
+ "booking_id" text,
372
+ "order_id" text,
373
+ "invoice_id" text,
374
+ "booking_payment_schedule_id" text,
375
+ "booking_guarantee_id" text,
376
+ "payment_instrument_id" text,
377
+ "payment_authorization_id" text,
378
+ "payment_capture_id" text,
379
+ "payment_id" text,
380
+ "status" "payment_session_status" DEFAULT 'pending' NOT NULL,
381
+ "provider" text,
382
+ "provider_session_id" text,
383
+ "provider_payment_id" text,
384
+ "external_reference" text,
385
+ "idempotency_key" text,
386
+ "client_reference" text,
387
+ "currency" text NOT NULL,
388
+ "amount_cents" integer NOT NULL,
389
+ "payment_method" "payment_method",
390
+ "payer_person_id" text,
391
+ "payer_organization_id" text,
392
+ "payer_email" text,
393
+ "payer_name" text,
394
+ "redirect_url" text,
395
+ "return_url" text,
396
+ "cancel_url" text,
397
+ "callback_url" text,
398
+ "expires_at" timestamp with time zone,
399
+ "completed_at" timestamp with time zone,
400
+ "failed_at" timestamp with time zone,
401
+ "cancelled_at" timestamp with time zone,
402
+ "expired_at" timestamp with time zone,
403
+ "failure_code" text,
404
+ "failure_message" text,
405
+ "notes" text,
406
+ "provider_payload" jsonb,
407
+ "metadata" jsonb,
408
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
409
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
410
+ );
411
+ --> statement-breakpoint
412
+ CREATE TABLE "credit_note_line_items" (
413
+ "id" text PRIMARY KEY NOT NULL,
414
+ "credit_note_id" text NOT NULL,
415
+ "description" text NOT NULL,
416
+ "quantity" integer DEFAULT 1 NOT NULL,
417
+ "unit_price_cents" integer NOT NULL,
418
+ "total_cents" integer NOT NULL,
419
+ "sort_order" integer DEFAULT 0 NOT NULL,
420
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
421
+ );
422
+ --> statement-breakpoint
423
+ CREATE TABLE "credit_notes" (
424
+ "id" text PRIMARY KEY NOT NULL,
425
+ "credit_note_number" text NOT NULL,
426
+ "invoice_id" text NOT NULL,
427
+ "status" "credit_note_status" DEFAULT 'draft' NOT NULL,
428
+ "amount_cents" integer NOT NULL,
429
+ "currency" text NOT NULL,
430
+ "base_currency" text,
431
+ "base_amount_cents" integer,
432
+ "fx_rate_set_id" text,
433
+ "reason" text NOT NULL,
434
+ "notes" text,
435
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
436
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
437
+ CONSTRAINT "credit_notes_credit_note_number_unique" UNIQUE("credit_note_number")
438
+ );
439
+ --> statement-breakpoint
440
+ CREATE TABLE "invoice_line_items" (
441
+ "id" text PRIMARY KEY NOT NULL,
442
+ "invoice_id" text NOT NULL,
443
+ "booking_item_id" text,
444
+ "booking_payment_schedule_id" text,
445
+ "description" text NOT NULL,
446
+ "quantity" integer DEFAULT 1 NOT NULL,
447
+ "unit_price_cents" integer NOT NULL,
448
+ "total_cents" integer NOT NULL,
449
+ "tax_rate" integer,
450
+ "sort_order" integer DEFAULT 0 NOT NULL,
451
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
452
+ );
453
+ --> statement-breakpoint
454
+ CREATE TABLE "invoices" (
455
+ "id" text PRIMARY KEY NOT NULL,
456
+ "invoice_number" text NOT NULL,
457
+ "invoice_type" "invoice_type" DEFAULT 'invoice' NOT NULL,
458
+ "converted_from_invoice_id" text,
459
+ "series_id" text,
460
+ "sequence" integer,
461
+ "template_id" text,
462
+ "tax_regime_id" text,
463
+ "language" text,
464
+ "booking_id" text NOT NULL,
465
+ "person_id" text,
466
+ "organization_id" text,
467
+ "status" "invoice_status" DEFAULT 'draft' NOT NULL,
468
+ "currency" text NOT NULL,
469
+ "base_currency" text,
470
+ "fx_rate_set_id" text,
471
+ "subtotal_cents" integer DEFAULT 0 NOT NULL,
472
+ "base_subtotal_cents" integer,
473
+ "tax_cents" integer DEFAULT 0 NOT NULL,
474
+ "base_tax_cents" integer,
475
+ "total_cents" integer DEFAULT 0 NOT NULL,
476
+ "base_total_cents" integer,
477
+ "paid_cents" integer DEFAULT 0 NOT NULL,
478
+ "base_paid_cents" integer,
479
+ "balance_due_cents" integer DEFAULT 0 NOT NULL,
480
+ "base_balance_due_cents" integer,
481
+ "commission_percent" integer,
482
+ "commission_amount_cents" integer,
483
+ "issue_date" date NOT NULL,
484
+ "due_date" date NOT NULL,
485
+ "notes" text,
486
+ "voided_at" timestamp with time zone,
487
+ "void_reason" text,
488
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
489
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
490
+ CONSTRAINT "ck_invoices_base_currency_amounts" CHECK ((
491
+ "invoices"."base_subtotal_cents" IS NULL
492
+ AND "invoices"."base_tax_cents" IS NULL
493
+ AND "invoices"."base_total_cents" IS NULL
494
+ AND "invoices"."base_paid_cents" IS NULL
495
+ AND "invoices"."base_balance_due_cents" IS NULL
496
+ ) OR "invoices"."base_currency" IS NOT NULL)
497
+ );
498
+ --> statement-breakpoint
499
+ CREATE TABLE "payments" (
500
+ "id" text PRIMARY KEY NOT NULL,
501
+ "invoice_id" text NOT NULL,
502
+ "amount_cents" integer NOT NULL,
503
+ "currency" text NOT NULL,
504
+ "base_currency" text,
505
+ "base_amount_cents" integer,
506
+ "fx_rate_set_id" text,
507
+ "payment_method" "payment_method" NOT NULL,
508
+ "payment_instrument_id" text,
509
+ "payment_authorization_id" text,
510
+ "payment_capture_id" text,
511
+ "status" "payment_status" DEFAULT 'pending' NOT NULL,
512
+ "reference_number" text,
513
+ "payment_date" date NOT NULL,
514
+ "notes" text,
515
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
516
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
517
+ CONSTRAINT "ck_payments_base_currency_amount" CHECK (("payments"."base_currency" IS NULL) = ("payments"."base_amount_cents" IS NULL))
518
+ );
519
+ --> statement-breakpoint
520
+ CREATE TABLE "cost_categories" (
521
+ "id" text PRIMARY KEY NOT NULL,
522
+ "name" text NOT NULL,
523
+ "sort_order" integer DEFAULT 0 NOT NULL,
524
+ "archived_at" timestamp with time zone,
525
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
526
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
527
+ );
528
+ --> statement-breakpoint
529
+ CREATE TABLE "supplier_cost_allocations" (
530
+ "id" text PRIMARY KEY NOT NULL,
531
+ "supplier_invoice_id" text NOT NULL,
532
+ "supplier_invoice_line_id" text,
533
+ "target_type" "cost_allocation_target_type" NOT NULL,
534
+ "departure_id" text,
535
+ "product_id" text,
536
+ "booking_id" text,
537
+ "booking_item_id" text,
538
+ "traveler_id" text,
539
+ "amount_cents" integer NOT NULL,
540
+ "base_amount_cents" integer,
541
+ "split_method" "cost_allocation_split_method" DEFAULT 'manual' NOT NULL,
542
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
543
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
544
+ CONSTRAINT "ck_supplier_cost_allocations_one_target" CHECK ((
545
+ ("supplier_cost_allocations"."target_type" = 'departure' AND "supplier_cost_allocations"."departure_id" IS NOT NULL AND "supplier_cost_allocations"."product_id" IS NULL AND "supplier_cost_allocations"."booking_id" IS NULL AND "supplier_cost_allocations"."booking_item_id" IS NULL AND "supplier_cost_allocations"."traveler_id" IS NULL)
546
+ OR ("supplier_cost_allocations"."target_type" = 'product' AND "supplier_cost_allocations"."product_id" IS NOT NULL AND "supplier_cost_allocations"."departure_id" IS NULL AND "supplier_cost_allocations"."booking_id" IS NULL AND "supplier_cost_allocations"."booking_item_id" IS NULL AND "supplier_cost_allocations"."traveler_id" IS NULL)
547
+ OR ("supplier_cost_allocations"."target_type" = 'booking' AND "supplier_cost_allocations"."booking_id" IS NOT NULL AND "supplier_cost_allocations"."departure_id" IS NULL AND "supplier_cost_allocations"."product_id" IS NULL AND "supplier_cost_allocations"."traveler_id" IS NULL)
548
+ OR ("supplier_cost_allocations"."target_type" = 'traveler' AND "supplier_cost_allocations"."traveler_id" IS NOT NULL AND "supplier_cost_allocations"."departure_id" IS NULL AND "supplier_cost_allocations"."product_id" IS NULL)
549
+ OR ("supplier_cost_allocations"."target_type" = 'unattributed' AND "supplier_cost_allocations"."departure_id" IS NULL AND "supplier_cost_allocations"."product_id" IS NULL AND "supplier_cost_allocations"."booking_id" IS NULL AND "supplier_cost_allocations"."booking_item_id" IS NULL AND "supplier_cost_allocations"."traveler_id" IS NULL)
550
+ ))
551
+ );
552
+ --> statement-breakpoint
553
+ CREATE TABLE "supplier_invoice_attachments" (
554
+ "id" text PRIMARY KEY NOT NULL,
555
+ "supplier_invoice_id" text NOT NULL,
556
+ "kind" text DEFAULT 'supporting_document' NOT NULL,
557
+ "name" text NOT NULL,
558
+ "mime_type" text,
559
+ "file_size" integer,
560
+ "storage_key" text,
561
+ "checksum" text,
562
+ "metadata" jsonb,
563
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
564
+ );
565
+ --> statement-breakpoint
566
+ CREATE TABLE "supplier_invoice_lines" (
567
+ "id" text PRIMARY KEY NOT NULL,
568
+ "supplier_invoice_id" text NOT NULL,
569
+ "description" text NOT NULL,
570
+ "service_type" "ap_service_type" DEFAULT 'other' NOT NULL,
571
+ "cost_category_id" text,
572
+ "supplier_service_id" text,
573
+ "quantity" integer DEFAULT 1 NOT NULL,
574
+ "unit_amount_cents" integer NOT NULL,
575
+ "tax_rate_bps" integer,
576
+ "tax_amount_cents" integer DEFAULT 0 NOT NULL,
577
+ "total_amount_cents" integer NOT NULL,
578
+ "sort_order" integer DEFAULT 0 NOT NULL,
579
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
580
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
581
+ );
582
+ --> statement-breakpoint
583
+ CREATE TABLE "supplier_invoices" (
584
+ "id" text PRIMARY KEY NOT NULL,
585
+ "supplier_id" text NOT NULL,
586
+ "supplier_invoice_no" text NOT NULL,
587
+ "internal_ref" text,
588
+ "status" "supplier_invoice_status" DEFAULT 'draft' NOT NULL,
589
+ "currency" text NOT NULL,
590
+ "base_currency" text,
591
+ "fx_rate_set_id" text,
592
+ "subtotal_cents" integer DEFAULT 0 NOT NULL,
593
+ "tax_cents" integer DEFAULT 0 NOT NULL,
594
+ "total_cents" integer DEFAULT 0 NOT NULL,
595
+ "base_subtotal_cents" integer,
596
+ "base_tax_cents" integer,
597
+ "base_total_cents" integer,
598
+ "paid_cents" integer DEFAULT 0 NOT NULL,
599
+ "balance_due_cents" integer DEFAULT 0 NOT NULL,
600
+ "tax_regime_id" text,
601
+ "issue_date" date NOT NULL,
602
+ "due_date" date,
603
+ "received_at" timestamp with time zone,
604
+ "approved_at" timestamp with time zone,
605
+ "approved_by" text,
606
+ "storage_key" text,
607
+ "extraction_id" text,
608
+ "notes" text,
609
+ "voided_at" timestamp with time zone,
610
+ "void_reason" text,
611
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
612
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
613
+ "deleted_at" timestamp with time zone,
614
+ CONSTRAINT "ck_supplier_invoices_base_currency" CHECK ("supplier_invoices"."base_currency" IS NOT NULL OR "supplier_invoices"."fx_rate_set_id" IS NULL)
615
+ );
616
+ --> statement-breakpoint
617
+ CREATE TABLE "supplier_payments" (
618
+ "id" text PRIMARY KEY NOT NULL,
619
+ "booking_id" text,
620
+ "supplier_id" text,
621
+ "booking_supplier_status_id" text,
622
+ "supplier_invoice_id" text,
623
+ "amount_cents" integer NOT NULL,
624
+ "currency" text NOT NULL,
625
+ "base_currency" text,
626
+ "base_amount_cents" integer,
627
+ "fx_rate_set_id" text,
628
+ "payment_method" "payment_method" NOT NULL,
629
+ "payment_instrument_id" text,
630
+ "status" "payment_status" DEFAULT 'pending' NOT NULL,
631
+ "reference_number" text,
632
+ "payment_date" date NOT NULL,
633
+ "notes" text,
634
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
635
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
636
+ CONSTRAINT "ck_supplier_payments_target" CHECK ("supplier_payments"."booking_id" IS NOT NULL OR "supplier_payments"."supplier_invoice_id" IS NOT NULL)
637
+ );
638
+ --> statement-breakpoint
639
+ CREATE TABLE "tax_classes" (
640
+ "id" text PRIMARY KEY NOT NULL,
641
+ "code" text NOT NULL,
642
+ "label" text NOT NULL,
643
+ "description" text,
644
+ "default_regime_id" text,
645
+ "lines" jsonb,
646
+ "active" boolean DEFAULT true NOT NULL,
647
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
648
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
649
+ );
650
+ --> statement-breakpoint
651
+ CREATE TABLE "tax_policy_profiles" (
652
+ "id" text PRIMARY KEY NOT NULL,
653
+ "code" text NOT NULL,
654
+ "name" text NOT NULL,
655
+ "jurisdiction" text,
656
+ "description" text,
657
+ "active" boolean DEFAULT true NOT NULL,
658
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
659
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
660
+ );
661
+ --> statement-breakpoint
662
+ CREATE TABLE "tax_policy_rules" (
663
+ "id" text PRIMARY KEY NOT NULL,
664
+ "profile_id" text NOT NULL,
665
+ "side" "tax_policy_side" DEFAULT 'sell' NOT NULL,
666
+ "priority" integer DEFAULT 100 NOT NULL,
667
+ "name" text NOT NULL,
668
+ "applies_to" "tax_class_applies_to" DEFAULT 'all' NOT NULL,
669
+ "condition" jsonb,
670
+ "tax_regime_id" text NOT NULL,
671
+ "active" boolean DEFAULT true NOT NULL,
672
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
673
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
674
+ );
675
+ --> statement-breakpoint
676
+ CREATE TABLE "tax_regimes" (
677
+ "id" text PRIMARY KEY NOT NULL,
678
+ "code" "tax_regime_code" NOT NULL,
679
+ "name" text NOT NULL,
680
+ "jurisdiction" text,
681
+ "rate_percent" integer,
682
+ "description" text,
683
+ "legal_reference" text,
684
+ "active" boolean DEFAULT true NOT NULL,
685
+ "metadata" jsonb,
686
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
687
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
688
+ );
689
+ --> statement-breakpoint
690
+ CREATE TABLE "voucher_redemptions" (
691
+ "id" text PRIMARY KEY NOT NULL,
692
+ "voucher_id" text NOT NULL,
693
+ "booking_id" text NOT NULL,
694
+ "payment_id" text,
695
+ "amount_cents" integer NOT NULL,
696
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
697
+ "created_by_user_id" text
698
+ );
699
+ --> statement-breakpoint
700
+ CREATE TABLE "vouchers" (
701
+ "id" text PRIMARY KEY NOT NULL,
702
+ "code" text NOT NULL,
703
+ "series_code" text,
704
+ "status" "voucher_status" DEFAULT 'active' NOT NULL,
705
+ "currency" text NOT NULL,
706
+ "initial_amount_cents" integer NOT NULL,
707
+ "remaining_amount_cents" integer NOT NULL,
708
+ "issued_to_person_id" text,
709
+ "issued_to_organization_id" text,
710
+ "source_type" "voucher_source_type" NOT NULL,
711
+ "source_booking_id" text,
712
+ "source_payment_id" text,
713
+ "valid_from" timestamp with time zone,
714
+ "expires_at" timestamp with time zone,
715
+ "notes" text,
716
+ "issued_by_user_id" text,
717
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
718
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
719
+ );
720
+ --> statement-breakpoint
721
+ ALTER TABLE "booking_guarantees" ADD CONSTRAINT "booking_guarantees_booking_payment_schedule_id_booking_payment_schedules_id_fk" FOREIGN KEY ("booking_payment_schedule_id") REFERENCES "public"."booking_payment_schedules"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
722
+ ALTER TABLE "booking_guarantees" ADD CONSTRAINT "booking_guarantees_payment_instrument_id_payment_instruments_id_fk" FOREIGN KEY ("payment_instrument_id") REFERENCES "public"."payment_instruments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
723
+ ALTER TABLE "booking_guarantees" ADD CONSTRAINT "booking_guarantees_payment_authorization_id_payment_authorizations_id_fk" FOREIGN KEY ("payment_authorization_id") REFERENCES "public"."payment_authorizations"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
724
+ ALTER TABLE "finance_notes" ADD CONSTRAINT "finance_notes_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
725
+ ALTER TABLE "invoice_attachments" ADD CONSTRAINT "invoice_attachments_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
726
+ ALTER TABLE "invoice_external_refs" ADD CONSTRAINT "invoice_external_refs_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
727
+ ALTER TABLE "invoice_renditions" ADD CONSTRAINT "invoice_renditions_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
728
+ ALTER TABLE "invoice_renditions" ADD CONSTRAINT "invoice_renditions_template_id_invoice_templates_id_fk" FOREIGN KEY ("template_id") REFERENCES "public"."invoice_templates"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
729
+ ALTER TABLE "payment_authorizations" ADD CONSTRAINT "payment_authorizations_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
730
+ ALTER TABLE "payment_authorizations" ADD CONSTRAINT "payment_authorizations_payment_instrument_id_payment_instruments_id_fk" FOREIGN KEY ("payment_instrument_id") REFERENCES "public"."payment_instruments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
731
+ ALTER TABLE "payment_captures" ADD CONSTRAINT "payment_captures_payment_authorization_id_payment_authorizations_id_fk" FOREIGN KEY ("payment_authorization_id") REFERENCES "public"."payment_authorizations"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
732
+ ALTER TABLE "payment_captures" ADD CONSTRAINT "payment_captures_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
733
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
734
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_booking_payment_schedule_id_booking_payment_schedules_id_fk" FOREIGN KEY ("booking_payment_schedule_id") REFERENCES "public"."booking_payment_schedules"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
735
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_booking_guarantee_id_booking_guarantees_id_fk" FOREIGN KEY ("booking_guarantee_id") REFERENCES "public"."booking_guarantees"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
736
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_payment_instrument_id_payment_instruments_id_fk" FOREIGN KEY ("payment_instrument_id") REFERENCES "public"."payment_instruments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
737
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_payment_authorization_id_payment_authorizations_id_fk" FOREIGN KEY ("payment_authorization_id") REFERENCES "public"."payment_authorizations"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
738
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_payment_capture_id_payment_captures_id_fk" FOREIGN KEY ("payment_capture_id") REFERENCES "public"."payment_captures"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
739
+ ALTER TABLE "payment_sessions" ADD CONSTRAINT "payment_sessions_payment_id_payments_id_fk" FOREIGN KEY ("payment_id") REFERENCES "public"."payments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
740
+ ALTER TABLE "credit_note_line_items" ADD CONSTRAINT "credit_note_line_items_credit_note_id_credit_notes_id_fk" FOREIGN KEY ("credit_note_id") REFERENCES "public"."credit_notes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
741
+ ALTER TABLE "credit_notes" ADD CONSTRAINT "credit_notes_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
742
+ ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
743
+ ALTER TABLE "invoice_line_items" ADD CONSTRAINT "invoice_line_items_booking_payment_schedule_id_booking_payment_schedules_id_fk" FOREIGN KEY ("booking_payment_schedule_id") REFERENCES "public"."booking_payment_schedules"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
744
+ ALTER TABLE "payments" ADD CONSTRAINT "payments_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
745
+ ALTER TABLE "payments" ADD CONSTRAINT "payments_payment_instrument_id_payment_instruments_id_fk" FOREIGN KEY ("payment_instrument_id") REFERENCES "public"."payment_instruments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
746
+ ALTER TABLE "payments" ADD CONSTRAINT "payments_payment_authorization_id_payment_authorizations_id_fk" FOREIGN KEY ("payment_authorization_id") REFERENCES "public"."payment_authorizations"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
747
+ ALTER TABLE "payments" ADD CONSTRAINT "payments_payment_capture_id_payment_captures_id_fk" FOREIGN KEY ("payment_capture_id") REFERENCES "public"."payment_captures"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
748
+ ALTER TABLE "supplier_cost_allocations" ADD CONSTRAINT "supplier_cost_allocations_supplier_invoice_id_supplier_invoices_id_fk" FOREIGN KEY ("supplier_invoice_id") REFERENCES "public"."supplier_invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
749
+ ALTER TABLE "supplier_cost_allocations" ADD CONSTRAINT "supplier_cost_allocations_supplier_invoice_line_id_supplier_invoice_lines_id_fk" FOREIGN KEY ("supplier_invoice_line_id") REFERENCES "public"."supplier_invoice_lines"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
750
+ ALTER TABLE "supplier_invoice_attachments" ADD CONSTRAINT "supplier_invoice_attachments_supplier_invoice_id_supplier_invoices_id_fk" FOREIGN KEY ("supplier_invoice_id") REFERENCES "public"."supplier_invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
751
+ ALTER TABLE "supplier_invoice_lines" ADD CONSTRAINT "supplier_invoice_lines_supplier_invoice_id_supplier_invoices_id_fk" FOREIGN KEY ("supplier_invoice_id") REFERENCES "public"."supplier_invoices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
752
+ ALTER TABLE "supplier_invoice_lines" ADD CONSTRAINT "supplier_invoice_lines_cost_category_id_cost_categories_id_fk" FOREIGN KEY ("cost_category_id") REFERENCES "public"."cost_categories"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
753
+ ALTER TABLE "supplier_payments" ADD CONSTRAINT "supplier_payments_supplier_invoice_id_supplier_invoices_id_fk" FOREIGN KEY ("supplier_invoice_id") REFERENCES "public"."supplier_invoices"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
754
+ ALTER TABLE "supplier_payments" ADD CONSTRAINT "supplier_payments_payment_instrument_id_payment_instruments_id_fk" FOREIGN KEY ("payment_instrument_id") REFERENCES "public"."payment_instruments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
755
+ ALTER TABLE "voucher_redemptions" ADD CONSTRAINT "voucher_redemptions_voucher_id_vouchers_id_fk" FOREIGN KEY ("voucher_id") REFERENCES "public"."vouchers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
756
+ CREATE INDEX "idx_booking_guarantees_booking" ON "booking_guarantees" USING btree ("booking_id");--> statement-breakpoint
757
+ CREATE INDEX "idx_booking_guarantees_booking_created" ON "booking_guarantees" USING btree ("booking_id","created_at");--> statement-breakpoint
758
+ CREATE INDEX "idx_booking_guarantees_schedule" ON "booking_guarantees" USING btree ("booking_payment_schedule_id");--> statement-breakpoint
759
+ CREATE INDEX "idx_booking_guarantees_item" ON "booking_guarantees" USING btree ("booking_item_id");--> statement-breakpoint
760
+ CREATE INDEX "idx_booking_guarantees_instrument" ON "booking_guarantees" USING btree ("payment_instrument_id");--> statement-breakpoint
761
+ CREATE INDEX "idx_booking_guarantees_authorization" ON "booking_guarantees" USING btree ("payment_authorization_id");--> statement-breakpoint
762
+ CREATE INDEX "idx_booking_guarantees_status" ON "booking_guarantees" USING btree ("status");--> statement-breakpoint
763
+ CREATE INDEX "idx_booking_item_commissions_item" ON "booking_item_commissions" USING btree ("booking_item_id");--> statement-breakpoint
764
+ CREATE INDEX "idx_booking_item_commissions_item_created" ON "booking_item_commissions" USING btree ("booking_item_id","created_at");--> statement-breakpoint
765
+ CREATE INDEX "idx_booking_item_commissions_channel" ON "booking_item_commissions" USING btree ("channel_id");--> statement-breakpoint
766
+ CREATE INDEX "idx_booking_item_commissions_status" ON "booking_item_commissions" USING btree ("status");--> statement-breakpoint
767
+ CREATE INDEX "idx_booking_item_tax_lines_item" ON "booking_item_tax_lines" USING btree ("booking_item_id");--> statement-breakpoint
768
+ CREATE INDEX "idx_booking_item_tax_lines_item_sort_created" ON "booking_item_tax_lines" USING btree ("booking_item_id","sort_order","created_at");--> statement-breakpoint
769
+ CREATE INDEX "idx_booking_item_tax_lines_scope" ON "booking_item_tax_lines" USING btree ("scope");--> statement-breakpoint
770
+ CREATE INDEX "idx_booking_payment_schedules_booking" ON "booking_payment_schedules" USING btree ("booking_id");--> statement-breakpoint
771
+ CREATE INDEX "idx_booking_payment_schedules_booking_due_created" ON "booking_payment_schedules" USING btree ("booking_id","due_date","created_at");--> statement-breakpoint
772
+ CREATE INDEX "idx_booking_payment_schedules_item" ON "booking_payment_schedules" USING btree ("booking_item_id");--> statement-breakpoint
773
+ CREATE INDEX "idx_booking_payment_schedules_status" ON "booking_payment_schedules" USING btree ("status");--> statement-breakpoint
774
+ CREATE INDEX "idx_booking_payment_schedules_due_date" ON "booking_payment_schedules" USING btree ("due_date");--> statement-breakpoint
775
+ CREATE INDEX "idx_finance_notes_invoice" ON "finance_notes" USING btree ("invoice_id");--> statement-breakpoint
776
+ CREATE INDEX "idx_finance_notes_invoice_created" ON "finance_notes" USING btree ("invoice_id","created_at");--> statement-breakpoint
777
+ CREATE INDEX "idx_invoice_attachments_invoice" ON "invoice_attachments" USING btree ("invoice_id");--> statement-breakpoint
778
+ CREATE INDEX "idx_invoice_attachments_invoice_created" ON "invoice_attachments" USING btree ("invoice_id","created_at");--> statement-breakpoint
779
+ CREATE INDEX "idx_invoice_external_refs_invoice" ON "invoice_external_refs" USING btree ("invoice_id");--> statement-breakpoint
780
+ CREATE INDEX "idx_invoice_external_refs_invoice_created" ON "invoice_external_refs" USING btree ("invoice_id","created_at");--> statement-breakpoint
781
+ CREATE INDEX "idx_invoice_external_refs_provider" ON "invoice_external_refs" USING btree ("provider");--> statement-breakpoint
782
+ CREATE UNIQUE INDEX "uq_invoice_external_refs_invoice_provider" ON "invoice_external_refs" USING btree ("invoice_id","provider");--> statement-breakpoint
783
+ CREATE INDEX "idx_invoice_number_series_scope" ON "invoice_number_series" USING btree ("scope");--> statement-breakpoint
784
+ CREATE INDEX "idx_invoice_number_series_active" ON "invoice_number_series" USING btree ("active");--> statement-breakpoint
785
+ CREATE INDEX "idx_invoice_number_series_scope_default" ON "invoice_number_series" USING btree ("scope","is_default");--> statement-breakpoint
786
+ CREATE INDEX "idx_invoice_number_series_external_provider" ON "invoice_number_series" USING btree ("external_provider");--> statement-breakpoint
787
+ CREATE INDEX "idx_invoice_number_series_scope_updated" ON "invoice_number_series" USING btree ("scope","updated_at");--> statement-breakpoint
788
+ CREATE INDEX "idx_invoice_number_series_active_updated" ON "invoice_number_series" USING btree ("active","updated_at");--> statement-breakpoint
789
+ CREATE UNIQUE INDEX "uidx_invoice_number_series_default_scope_active" ON "invoice_number_series" USING btree ("scope") WHERE "invoice_number_series"."active" = true AND "invoice_number_series"."is_default" = true;--> statement-breakpoint
790
+ CREATE INDEX "idx_invoice_renditions_invoice" ON "invoice_renditions" USING btree ("invoice_id");--> statement-breakpoint
791
+ CREATE INDEX "idx_invoice_renditions_invoice_created" ON "invoice_renditions" USING btree ("invoice_id","created_at");--> statement-breakpoint
792
+ CREATE INDEX "idx_invoice_renditions_template" ON "invoice_renditions" USING btree ("template_id");--> statement-breakpoint
793
+ CREATE INDEX "idx_invoice_renditions_status" ON "invoice_renditions" USING btree ("status");--> statement-breakpoint
794
+ CREATE INDEX "idx_invoice_renditions_format" ON "invoice_renditions" USING btree ("format");--> statement-breakpoint
795
+ CREATE INDEX "idx_invoice_templates_language" ON "invoice_templates" USING btree ("language");--> statement-breakpoint
796
+ CREATE INDEX "idx_invoice_templates_language_updated" ON "invoice_templates" USING btree ("language","updated_at");--> statement-breakpoint
797
+ CREATE INDEX "idx_invoice_templates_jurisdiction" ON "invoice_templates" USING btree ("jurisdiction");--> statement-breakpoint
798
+ CREATE INDEX "idx_invoice_templates_jurisdiction_updated" ON "invoice_templates" USING btree ("jurisdiction","updated_at");--> statement-breakpoint
799
+ CREATE INDEX "idx_invoice_templates_default" ON "invoice_templates" USING btree ("is_default");--> statement-breakpoint
800
+ CREATE INDEX "idx_invoice_templates_default_updated" ON "invoice_templates" USING btree ("is_default","updated_at");--> statement-breakpoint
801
+ CREATE INDEX "idx_invoice_templates_active" ON "invoice_templates" USING btree ("active");--> statement-breakpoint
802
+ CREATE INDEX "idx_invoice_templates_active_updated" ON "invoice_templates" USING btree ("active","updated_at");--> statement-breakpoint
803
+ CREATE INDEX "idx_payment_instruments_owner_type" ON "payment_instruments" USING btree ("owner_type");--> statement-breakpoint
804
+ CREATE INDEX "idx_payment_instruments_owner_type_updated" ON "payment_instruments" USING btree ("owner_type","updated_at");--> statement-breakpoint
805
+ CREATE INDEX "idx_payment_instruments_person" ON "payment_instruments" USING btree ("person_id");--> statement-breakpoint
806
+ CREATE INDEX "idx_payment_instruments_person_updated" ON "payment_instruments" USING btree ("person_id","updated_at");--> statement-breakpoint
807
+ CREATE INDEX "idx_payment_instruments_organization" ON "payment_instruments" USING btree ("organization_id");--> statement-breakpoint
808
+ CREATE INDEX "idx_payment_instruments_organization_updated" ON "payment_instruments" USING btree ("organization_id","updated_at");--> statement-breakpoint
809
+ CREATE INDEX "idx_payment_instruments_supplier" ON "payment_instruments" USING btree ("supplier_id");--> statement-breakpoint
810
+ CREATE INDEX "idx_payment_instruments_supplier_updated" ON "payment_instruments" USING btree ("supplier_id","updated_at");--> statement-breakpoint
811
+ CREATE INDEX "idx_payment_instruments_channel" ON "payment_instruments" USING btree ("channel_id");--> statement-breakpoint
812
+ CREATE INDEX "idx_payment_instruments_channel_updated" ON "payment_instruments" USING btree ("channel_id","updated_at");--> statement-breakpoint
813
+ CREATE INDEX "idx_payment_instruments_status" ON "payment_instruments" USING btree ("status");--> statement-breakpoint
814
+ CREATE INDEX "idx_payment_instruments_status_updated" ON "payment_instruments" USING btree ("status","updated_at");--> statement-breakpoint
815
+ CREATE INDEX "idx_payment_instruments_type" ON "payment_instruments" USING btree ("instrument_type");--> statement-breakpoint
816
+ CREATE INDEX "idx_payment_instruments_type_updated" ON "payment_instruments" USING btree ("instrument_type","updated_at");--> statement-breakpoint
817
+ CREATE INDEX "idx_payment_authorizations_booking" ON "payment_authorizations" USING btree ("booking_id");--> statement-breakpoint
818
+ CREATE INDEX "idx_payment_authorizations_booking_created" ON "payment_authorizations" USING btree ("booking_id","created_at");--> statement-breakpoint
819
+ CREATE INDEX "idx_payment_authorizations_order" ON "payment_authorizations" USING btree ("order_id");--> statement-breakpoint
820
+ CREATE INDEX "idx_payment_authorizations_order_created" ON "payment_authorizations" USING btree ("order_id","created_at");--> statement-breakpoint
821
+ CREATE INDEX "idx_payment_authorizations_invoice" ON "payment_authorizations" USING btree ("invoice_id");--> statement-breakpoint
822
+ CREATE INDEX "idx_payment_authorizations_invoice_created" ON "payment_authorizations" USING btree ("invoice_id","created_at");--> statement-breakpoint
823
+ CREATE INDEX "idx_payment_authorizations_guarantee" ON "payment_authorizations" USING btree ("booking_guarantee_id");--> statement-breakpoint
824
+ CREATE INDEX "idx_payment_authorizations_guarantee_created" ON "payment_authorizations" USING btree ("booking_guarantee_id","created_at");--> statement-breakpoint
825
+ CREATE INDEX "idx_payment_authorizations_instrument" ON "payment_authorizations" USING btree ("payment_instrument_id");--> statement-breakpoint
826
+ CREATE INDEX "idx_payment_authorizations_instrument_created" ON "payment_authorizations" USING btree ("payment_instrument_id","created_at");--> statement-breakpoint
827
+ CREATE INDEX "idx_payment_authorizations_status" ON "payment_authorizations" USING btree ("status");--> statement-breakpoint
828
+ CREATE INDEX "idx_payment_authorizations_status_created" ON "payment_authorizations" USING btree ("status","created_at");--> statement-breakpoint
829
+ CREATE INDEX "idx_payment_captures_authorization" ON "payment_captures" USING btree ("payment_authorization_id");--> statement-breakpoint
830
+ CREATE INDEX "idx_payment_captures_authorization_created" ON "payment_captures" USING btree ("payment_authorization_id","created_at");--> statement-breakpoint
831
+ CREATE INDEX "idx_payment_captures_invoice" ON "payment_captures" USING btree ("invoice_id");--> statement-breakpoint
832
+ CREATE INDEX "idx_payment_captures_invoice_created" ON "payment_captures" USING btree ("invoice_id","created_at");--> statement-breakpoint
833
+ CREATE INDEX "idx_payment_captures_status" ON "payment_captures" USING btree ("status");--> statement-breakpoint
834
+ CREATE INDEX "idx_payment_captures_status_created" ON "payment_captures" USING btree ("status","created_at");--> statement-breakpoint
835
+ CREATE INDEX "idx_payment_sessions_target" ON "payment_sessions" USING btree ("target_type","target_id");--> statement-breakpoint
836
+ CREATE INDEX "idx_payment_sessions_target_created" ON "payment_sessions" USING btree ("target_type","created_at");--> statement-breakpoint
837
+ CREATE INDEX "idx_payment_sessions_booking" ON "payment_sessions" USING btree ("booking_id");--> statement-breakpoint
838
+ CREATE INDEX "idx_payment_sessions_booking_created" ON "payment_sessions" USING btree ("booking_id","created_at");--> statement-breakpoint
839
+ CREATE INDEX "idx_payment_sessions_order" ON "payment_sessions" USING btree ("order_id");--> statement-breakpoint
840
+ CREATE INDEX "idx_payment_sessions_order_created" ON "payment_sessions" USING btree ("order_id","created_at");--> statement-breakpoint
841
+ CREATE INDEX "idx_payment_sessions_invoice" ON "payment_sessions" USING btree ("invoice_id");--> statement-breakpoint
842
+ CREATE INDEX "idx_payment_sessions_invoice_created" ON "payment_sessions" USING btree ("invoice_id","created_at");--> statement-breakpoint
843
+ CREATE INDEX "idx_payment_sessions_schedule" ON "payment_sessions" USING btree ("booking_payment_schedule_id");--> statement-breakpoint
844
+ CREATE INDEX "idx_payment_sessions_schedule_created" ON "payment_sessions" USING btree ("booking_payment_schedule_id","created_at");--> statement-breakpoint
845
+ CREATE INDEX "idx_payment_sessions_guarantee" ON "payment_sessions" USING btree ("booking_guarantee_id");--> statement-breakpoint
846
+ CREATE INDEX "idx_payment_sessions_guarantee_created" ON "payment_sessions" USING btree ("booking_guarantee_id","created_at");--> statement-breakpoint
847
+ CREATE INDEX "idx_payment_sessions_status" ON "payment_sessions" USING btree ("status");--> statement-breakpoint
848
+ CREATE INDEX "idx_payment_sessions_status_created" ON "payment_sessions" USING btree ("status","created_at");--> statement-breakpoint
849
+ CREATE INDEX "idx_payment_sessions_provider" ON "payment_sessions" USING btree ("provider");--> statement-breakpoint
850
+ CREATE INDEX "idx_payment_sessions_provider_created" ON "payment_sessions" USING btree ("provider","created_at");--> statement-breakpoint
851
+ CREATE INDEX "idx_payment_sessions_provider_session" ON "payment_sessions" USING btree ("provider_session_id");--> statement-breakpoint
852
+ CREATE INDEX "idx_payment_sessions_expires_at" ON "payment_sessions" USING btree ("expires_at");--> statement-breakpoint
853
+ CREATE UNIQUE INDEX "uidx_payment_sessions_idempotency" ON "payment_sessions" USING btree ("idempotency_key");--> statement-breakpoint
854
+ CREATE UNIQUE INDEX "uidx_payment_sessions_provider_session" ON "payment_sessions" USING btree ("provider","provider_session_id");--> statement-breakpoint
855
+ CREATE INDEX "idx_credit_note_line_items_credit_note" ON "credit_note_line_items" USING btree ("credit_note_id");--> statement-breakpoint
856
+ CREATE INDEX "idx_credit_note_line_items_credit_note_sort" ON "credit_note_line_items" USING btree ("credit_note_id","sort_order");--> statement-breakpoint
857
+ CREATE INDEX "idx_credit_notes_invoice" ON "credit_notes" USING btree ("invoice_id");--> statement-breakpoint
858
+ CREATE INDEX "idx_credit_notes_invoice_created" ON "credit_notes" USING btree ("invoice_id","created_at");--> statement-breakpoint
859
+ CREATE INDEX "idx_credit_notes_fx_rate_set" ON "credit_notes" USING btree ("fx_rate_set_id");--> statement-breakpoint
860
+ CREATE INDEX "idx_credit_notes_number" ON "credit_notes" USING btree ("credit_note_number");--> statement-breakpoint
861
+ CREATE INDEX "idx_invoice_line_items_invoice" ON "invoice_line_items" USING btree ("invoice_id");--> statement-breakpoint
862
+ CREATE INDEX "idx_invoice_line_items_invoice_sort" ON "invoice_line_items" USING btree ("invoice_id","sort_order");--> statement-breakpoint
863
+ CREATE INDEX "idx_invoice_line_items_booking_item" ON "invoice_line_items" USING btree ("booking_item_id");--> statement-breakpoint
864
+ CREATE INDEX "idx_invoice_line_items_payment_schedule" ON "invoice_line_items" USING btree ("booking_payment_schedule_id");--> statement-breakpoint
865
+ CREATE INDEX "idx_invoices_booking" ON "invoices" USING btree ("booking_id");--> statement-breakpoint
866
+ CREATE INDEX "idx_invoices_booking_created" ON "invoices" USING btree ("booking_id","created_at");--> statement-breakpoint
867
+ CREATE INDEX "idx_invoices_person" ON "invoices" USING btree ("person_id");--> statement-breakpoint
868
+ CREATE INDEX "idx_invoices_organization" ON "invoices" USING btree ("organization_id");--> statement-breakpoint
869
+ CREATE INDEX "idx_invoices_status" ON "invoices" USING btree ("status");--> statement-breakpoint
870
+ CREATE INDEX "idx_invoices_status_created" ON "invoices" USING btree ("status","created_at");--> statement-breakpoint
871
+ CREATE INDEX "idx_invoices_outstanding_due" ON "invoices" USING btree ("status","balance_due_cents","due_date");--> statement-breakpoint
872
+ CREATE INDEX "idx_invoices_created" ON "invoices" USING btree ("created_at");--> statement-breakpoint
873
+ CREATE INDEX "idx_invoices_fx_rate_set" ON "invoices" USING btree ("fx_rate_set_id");--> statement-breakpoint
874
+ CREATE INDEX "idx_invoices_number" ON "invoices" USING btree ("invoice_number");--> statement-breakpoint
875
+ CREATE UNIQUE INDEX "invoices_invoice_number_type_active_idx" ON "invoices" USING btree ("invoice_number","invoice_type") WHERE "invoices"."status" <> 'void';--> statement-breakpoint
876
+ CREATE INDEX "idx_invoices_due_date" ON "invoices" USING btree ("due_date");--> statement-breakpoint
877
+ CREATE INDEX "idx_invoices_converted_from" ON "invoices" USING btree ("converted_from_invoice_id");--> statement-breakpoint
878
+ CREATE INDEX "idx_payments_invoice" ON "payments" USING btree ("invoice_id");--> statement-breakpoint
879
+ CREATE INDEX "idx_payments_invoice_date" ON "payments" USING btree ("invoice_id","payment_date");--> statement-breakpoint
880
+ CREATE INDEX "idx_payments_fx_rate_set" ON "payments" USING btree ("fx_rate_set_id");--> statement-breakpoint
881
+ CREATE INDEX "idx_payments_instrument" ON "payments" USING btree ("payment_instrument_id");--> statement-breakpoint
882
+ CREATE INDEX "idx_payments_authorization" ON "payments" USING btree ("payment_authorization_id");--> statement-breakpoint
883
+ CREATE INDEX "idx_payments_capture" ON "payments" USING btree ("payment_capture_id");--> statement-breakpoint
884
+ CREATE INDEX "idx_payments_status" ON "payments" USING btree ("status");--> statement-breakpoint
885
+ CREATE INDEX "idx_payments_date" ON "payments" USING btree ("payment_date");--> statement-breakpoint
886
+ CREATE INDEX "idx_cost_categories_sort" ON "cost_categories" USING btree ("sort_order");--> statement-breakpoint
887
+ CREATE INDEX "idx_supplier_cost_allocations_invoice" ON "supplier_cost_allocations" USING btree ("supplier_invoice_id");--> statement-breakpoint
888
+ CREATE INDEX "idx_supplier_cost_allocations_line" ON "supplier_cost_allocations" USING btree ("supplier_invoice_line_id");--> statement-breakpoint
889
+ CREATE INDEX "idx_supplier_cost_allocations_departure" ON "supplier_cost_allocations" USING btree ("departure_id");--> statement-breakpoint
890
+ CREATE INDEX "idx_supplier_cost_allocations_product" ON "supplier_cost_allocations" USING btree ("product_id");--> statement-breakpoint
891
+ CREATE INDEX "idx_supplier_cost_allocations_booking" ON "supplier_cost_allocations" USING btree ("booking_id");--> statement-breakpoint
892
+ CREATE INDEX "idx_supplier_invoice_attachments_invoice" ON "supplier_invoice_attachments" USING btree ("supplier_invoice_id");--> statement-breakpoint
893
+ CREATE INDEX "idx_supplier_invoice_attachments_invoice_created" ON "supplier_invoice_attachments" USING btree ("supplier_invoice_id","created_at");--> statement-breakpoint
894
+ CREATE INDEX "idx_supplier_invoice_lines_invoice" ON "supplier_invoice_lines" USING btree ("supplier_invoice_id");--> statement-breakpoint
895
+ CREATE INDEX "idx_supplier_invoice_lines_invoice_sort" ON "supplier_invoice_lines" USING btree ("supplier_invoice_id","sort_order");--> statement-breakpoint
896
+ CREATE INDEX "idx_supplier_invoice_lines_service_type" ON "supplier_invoice_lines" USING btree ("service_type");--> statement-breakpoint
897
+ CREATE INDEX "idx_supplier_invoices_supplier" ON "supplier_invoices" USING btree ("supplier_id") WHERE "supplier_invoices"."deleted_at" IS NULL;--> statement-breakpoint
898
+ CREATE INDEX "idx_supplier_invoices_supplier_created" ON "supplier_invoices" USING btree ("supplier_id","created_at") WHERE "supplier_invoices"."deleted_at" IS NULL;--> statement-breakpoint
899
+ CREATE INDEX "idx_supplier_invoices_status" ON "supplier_invoices" USING btree ("status") WHERE "supplier_invoices"."deleted_at" IS NULL;--> statement-breakpoint
900
+ CREATE INDEX "idx_supplier_invoices_status_created" ON "supplier_invoices" USING btree ("status","created_at") WHERE "supplier_invoices"."deleted_at" IS NULL;--> statement-breakpoint
901
+ CREATE INDEX "idx_supplier_invoices_due_date" ON "supplier_invoices" USING btree ("due_date") WHERE "supplier_invoices"."deleted_at" IS NULL;--> statement-breakpoint
902
+ CREATE INDEX "idx_supplier_invoices_fx_rate_set" ON "supplier_invoices" USING btree ("fx_rate_set_id");--> statement-breakpoint
903
+ CREATE UNIQUE INDEX "supplier_invoices_supplier_number_active_idx" ON "supplier_invoices" USING btree ("supplier_id","supplier_invoice_no") WHERE "supplier_invoices"."status" <> 'void' AND "supplier_invoices"."deleted_at" IS NULL;--> statement-breakpoint
904
+ CREATE INDEX "idx_supplier_payments_booking" ON "supplier_payments" USING btree ("booking_id");--> statement-breakpoint
905
+ CREATE INDEX "idx_supplier_payments_booking_created" ON "supplier_payments" USING btree ("booking_id","created_at");--> statement-breakpoint
906
+ CREATE INDEX "idx_supplier_payments_supplier" ON "supplier_payments" USING btree ("supplier_id");--> statement-breakpoint
907
+ CREATE INDEX "idx_supplier_payments_supplier_created" ON "supplier_payments" USING btree ("supplier_id","created_at");--> statement-breakpoint
908
+ CREATE INDEX "idx_supplier_payments_fx_rate_set" ON "supplier_payments" USING btree ("fx_rate_set_id");--> statement-breakpoint
909
+ CREATE INDEX "idx_supplier_payments_instrument" ON "supplier_payments" USING btree ("payment_instrument_id");--> statement-breakpoint
910
+ CREATE INDEX "idx_supplier_payments_status" ON "supplier_payments" USING btree ("status");--> statement-breakpoint
911
+ CREATE INDEX "idx_supplier_payments_status_created" ON "supplier_payments" USING btree ("status","created_at");--> statement-breakpoint
912
+ CREATE INDEX "idx_supplier_payments_date" ON "supplier_payments" USING btree ("payment_date");--> statement-breakpoint
913
+ CREATE INDEX "idx_supplier_payments_supplier_invoice" ON "supplier_payments" USING btree ("supplier_invoice_id");--> statement-breakpoint
914
+ CREATE INDEX "idx_tax_classes_code" ON "tax_classes" USING btree ("code");--> statement-breakpoint
915
+ CREATE INDEX "idx_tax_classes_active" ON "tax_classes" USING btree ("active");--> statement-breakpoint
916
+ CREATE INDEX "idx_tax_policy_profiles_code" ON "tax_policy_profiles" USING btree ("code");--> statement-breakpoint
917
+ CREATE INDEX "idx_tax_policy_profiles_active" ON "tax_policy_profiles" USING btree ("active");--> statement-breakpoint
918
+ CREATE INDEX "idx_tax_policy_rules_profile" ON "tax_policy_rules" USING btree ("profile_id");--> statement-breakpoint
919
+ CREATE INDEX "idx_tax_policy_rules_profile_side_priority" ON "tax_policy_rules" USING btree ("profile_id","side","priority");--> statement-breakpoint
920
+ CREATE INDEX "idx_tax_policy_rules_active" ON "tax_policy_rules" USING btree ("active");--> statement-breakpoint
921
+ CREATE INDEX "idx_tax_regimes_code" ON "tax_regimes" USING btree ("code");--> statement-breakpoint
922
+ CREATE INDEX "idx_tax_regimes_code_updated" ON "tax_regimes" USING btree ("code","updated_at");--> statement-breakpoint
923
+ CREATE INDEX "idx_tax_regimes_jurisdiction" ON "tax_regimes" USING btree ("jurisdiction");--> statement-breakpoint
924
+ CREATE INDEX "idx_tax_regimes_jurisdiction_updated" ON "tax_regimes" USING btree ("jurisdiction","updated_at");--> statement-breakpoint
925
+ CREATE INDEX "idx_tax_regimes_active" ON "tax_regimes" USING btree ("active");--> statement-breakpoint
926
+ CREATE INDEX "idx_tax_regimes_active_updated" ON "tax_regimes" USING btree ("active","updated_at");--> statement-breakpoint
927
+ CREATE INDEX "idx_voucher_redemptions_voucher" ON "voucher_redemptions" USING btree ("voucher_id");--> statement-breakpoint
928
+ CREATE INDEX "idx_voucher_redemptions_booking" ON "voucher_redemptions" USING btree ("booking_id");--> statement-breakpoint
929
+ CREATE INDEX "idx_voucher_redemptions_voucher_created" ON "voucher_redemptions" USING btree ("voucher_id","created_at");--> statement-breakpoint
930
+ CREATE UNIQUE INDEX "uidx_vouchers_code" ON "vouchers" USING btree ("code");--> statement-breakpoint
931
+ CREATE INDEX "idx_vouchers_series" ON "vouchers" USING btree ("series_code");--> statement-breakpoint
932
+ CREATE INDEX "idx_vouchers_status" ON "vouchers" USING btree ("status");--> statement-breakpoint
933
+ CREATE INDEX "idx_vouchers_person" ON "vouchers" USING btree ("issued_to_person_id");--> statement-breakpoint
934
+ CREATE INDEX "idx_vouchers_organization" ON "vouchers" USING btree ("issued_to_organization_id");--> statement-breakpoint
935
+ CREATE INDEX "idx_vouchers_source_booking" ON "vouchers" USING btree ("source_booking_id");--> statement-breakpoint
936
+ CREATE INDEX "idx_vouchers_valid_from" ON "vouchers" USING btree ("valid_from");--> statement-breakpoint
937
+ CREATE INDEX "idx_vouchers_expires_at" ON "vouchers" USING btree ("expires_at");--> statement-breakpoint
938
+ CREATE INDEX "idx_vouchers_remaining" ON "vouchers" USING btree ("remaining_amount_cents");
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1781947491635,
9
+ "tag": "0000_finance_baseline",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyant-travel/finance",
3
- "version": "0.125.0",
3
+ "version": "0.126.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -91,21 +91,24 @@
91
91
  "fflate": "^0.8.2",
92
92
  "hono": "^4.12.10",
93
93
  "zod": "^4.3.6",
94
- "@voyant-travel/action-ledger": "^0.105.1",
95
- "@voyant-travel/bookings": "^0.125.0",
94
+ "@voyant-travel/action-ledger": "^0.105.3",
95
+ "@voyant-travel/bookings": "^0.126.0",
96
96
  "@voyant-travel/core": "^0.110.0",
97
- "@voyant-travel/db": "^0.108.3",
97
+ "@voyant-travel/db": "^0.108.4",
98
98
  "@voyant-travel/finance-contracts": "^0.104.6",
99
99
  "@voyant-travel/hono": "^0.112.2",
100
100
  "@voyant-travel/storage": "^0.105.0",
101
101
  "@voyant-travel/utils": "^0.105.2"
102
102
  },
103
103
  "devDependencies": {
104
+ "drizzle-kit": "^0.31.10",
104
105
  "typescript": "^6.0.2",
105
106
  "@voyant-travel/voyant-typescript-config": "^0.1.0"
106
107
  },
107
108
  "files": [
108
- "dist"
109
+ "dist",
110
+ "migrations/*.sql",
111
+ "migrations/meta/_journal.json"
109
112
  ],
110
113
  "publishConfig": {
111
114
  "access": "public"
@@ -127,7 +130,8 @@
127
130
  "test": "vitest run",
128
131
  "build": "tsc -p tsconfig.json",
129
132
  "clean": "rm -rf dist tsconfig.tsbuildinfo",
130
- "migrate:vouchers": "node --experimental-strip-types --experimental-transform-types scripts/migrate-vouchers.ts"
133
+ "migrate:vouchers": "node --experimental-strip-types --experimental-transform-types scripts/migrate-vouchers.ts",
134
+ "db:generate": "drizzle-kit generate --config=drizzle.migrations.config.ts --name=finance_baseline && node ../../scripts/d2/guard-create-type.mjs ./migrations && node ../../scripts/d2/ensure-extensions.mjs ./migrations"
131
135
  },
132
136
  "main": "./dist/index.js",
133
137
  "types": "./dist/index.d.ts"