· 4 years ago · Apr 02, 2021, 08:32 AM
1ALTER TABLE IF EXISTS invoice_pricing RENAME TO invoice_pricing_old;
2
3create table currency_exchange
4(
5 id text not null primary key ,
6 base_currency varchar(3) not null,
7 target_currency varchar(3) not null,
8 conversion_rate numeric(19, 2) not null,
9 obtained_at timestamp not null,
10 is_estimated boolean not null
11);
12
13create table invoice_pricing
14(
15 id text not null primary key,
16 invoice_id text not null,
17 currency_exchange_id text null,
18 transferred_amount numeric(19, 2) not null,
19 transferred_currency varchar(3) not null,
20 international_fee_amount numeric(19, 2) null,
21 international_fee_currency varchar(3) null,
22 created_at timestamp not null,
23 updated_at timestamp not null,
24
25 constraint invoice_pricing_currency_exchange_id_fk
26 foreign key (currency_exchange_id) references currency_exchange (id),
27
28 constraint invoice_pricing_invoice_id_fk
29 foreign key (invoice_id) references invoice_meta (id)
30);
31
32create index invoice_pricing_invoice_id_idx on invoice_pricing (invoice_id);