@accounter/server
Version:
Accounter GraphQL server
886 lines (818 loc) • 117 kB
JavaScript
export default {
name: '2024-01-29T13-15-23.initial.sql',
run: ({ sql }) => sql `
-- create accounter schema
CREATE SCHEMA IF NOT EXISTS accounter_schema;
-- create types
create type accounter_schema.currency as enum ('ILS', 'USD', 'EUR', 'GBP', 'USDC', 'GRT', 'ETH');
create type accounter_schema.document_type as enum ('INVOICE', 'RECEIPT', 'INVOICE_RECEIPT', 'PROFORMA', 'UNPROCESSED', 'CREDIT_INVOICE');
create type accounter_schema.tags_enum as enum ('business', 'Business Trip', 'conversion', 'creditcard', 'financial', 'investments', 'mistake', 'salary', 'transportation');
create type accounter_schema.business_trip_transaction_type as enum ('FLIGHT', 'ACCOMMODATION', 'TRAVEL_AND_SUBSISTENCE', 'OTHER');
-- create tables
create table accounter_schema.exchange_rates
(
exchange_date date,
usd numeric(4, 3),
eur numeric(5, 4),
gbp numeric(5, 4)
);
create unique index exchange_rates_exchange_date_uindex
on accounter_schema.exchange_rates (exchange_date);
create table accounter_schema.isracard_creditcard_transactions
(
specific_date varchar(30),
card_index integer not null,
deals_inbound varchar(3),
supplier_id integer,
supplier_name varchar(15),
deal_sum_type varchar(1),
payment_sum_sign varchar(1),
purchase_date varchar(5),
full_purchase_date text,
more_info varchar(30),
horaat_keva varchar(1),
voucher_number integer,
voucher_number_ratz integer,
solek varchar(1),
purchase_date_outbound varchar(5),
full_purchase_date_outbound text,
currency_id varchar(4),
current_payment_currency varchar(3),
city varchar(10),
supplier_name_outbound varchar(15),
full_supplier_name_outbound varchar(20),
payment_date varchar(5),
full_payment_date text,
is_show_deals_outbound varchar(1),
adendum varchar(30),
voucher_number_ratz_outbound integer,
is_show_link_for_supplier_details varchar(3),
deal_sum varchar(8),
payment_sum numeric(8, 2),
full_supplier_name_heb varchar(20),
deal_sum_outbound numeric(9, 2),
payment_sum_outbound numeric(8, 2),
is_horaat_keva varchar(5) not null,
stage varchar(30),
return_code varchar(30),
message varchar(30),
return_message varchar(30),
display_properties varchar(30),
table_page_num bit not null,
is_error varchar(5) not null,
is_captcha varchar(5) not null,
is_button varchar(5) not null,
site_name varchar(30),
client_ip_address varchar(30),
card integer not null,
id uuid default gen_random_uuid() not null
constraint isracard_creditcard_transactions_pk
primary key,
charging_date text,
kod_matbea_mekori text
);
create unique index isracard_creditcard_transactions_id_uindex
on accounter_schema.isracard_creditcard_transactions (id);
create table accounter_schema.poalim_eur_account_transactions
(
metadata_attributes_original_event_key json,
metadata_attributes_contra_branch_number json,
metadata_attributes_contra_account_number json,
metadata_attributes_contra_bank_number json,
metadata_attributes_contra_account_field_name_lable json,
metadata_attributes_data_group_code json,
metadata_attributes_currency_rate json,
metadata_attributes_contra_currency_code json,
metadata_attributes_rate_fixing_code json,
executing_date date not null,
formatted_executing_date varchar(24) not null,
value_date date not null,
formatted_value_date varchar(24) not null,
original_system_id integer not null,
activity_description varchar(11) not null,
event_amount numeric(8, 2) not null,
current_balance numeric(9, 2) not null,
reference_catenated_number integer not null,
reference_number integer not null,
currency_rate numeric(9, 7) not null,
event_details varchar(18),
rate_fixing_code integer not null,
contra_currency_code integer not null,
event_activity_type_code integer not null,
transaction_type varchar(7) not null,
rate_fixing_short_description varchar(9) not null,
currency_long_description text not null,
activity_type_code integer not null,
event_number integer not null,
validity_date date not null,
comments varchar(30),
comment_existence_switch bit not null,
account_name varchar(30),
contra_bank_number integer not null,
contra_branch_number integer not null,
contra_account_number integer not null,
original_event_key bit not null,
contra_account_field_name_lable varchar(30),
data_group_code bit not null,
rate_fixing_description varchar(34),
url_address_niar varchar(30),
currency_swift_code varchar(3) not null,
url_address varchar(30),
bank_number integer not null,
branch_number integer not null,
account_number integer not null,
id uuid default gen_random_uuid() not null
constraint poalim_eur_account_transactions_pk
primary key
);
create unique index poalim_eur_account_transactions_id_uindex
on accounter_schema.poalim_eur_account_transactions (id);
create table accounter_schema.poalim_ils_account_transactions
(
event_date date not null,
formatted_event_date varchar(24) not null,
serial_number integer not null,
activity_type_code integer not null,
activity_description varchar(14) not null,
text_code integer not null,
reference_number bigint not null,
reference_catenated_number integer not null,
value_date date not null,
formatted_value_date varchar(24) not null,
event_amount numeric(9, 2) not null,
event_activity_type_code integer not null,
current_balance numeric(9, 2) not null,
internal_link_code integer not null,
original_event_create_date integer not null,
formatted_original_event_create_date varchar(30),
transaction_type varchar(7) not null,
data_group_code integer not null,
beneficiary_details_data varchar(30),
expanded_event_date bigint not null,
executing_branch_number integer not null,
event_id integer not null,
details text,
pfm_details varchar(30),
different_date_indication varchar(1) not null,
rejected_data_event_pertaining_indication varchar(1),
table_number integer not null,
record_number integer not null,
contra_bank_number integer not null,
contra_branch_number integer not null,
contra_account_number integer not null,
contra_account_type_code integer not null,
marketing_offer_context bit not null,
comment_existence_switch bit not null,
english_action_desc varchar(14),
field_desc_display_switch bit not null,
url_address_niar varchar(30),
offer_activity_context varchar(33),
comment varchar(30),
beneficiary_details_data_party_name varchar(24),
beneficiary_details_data_message_headline varchar(5),
beneficiary_details_data_party_headline varchar(6),
beneficiary_details_data_message_detail varchar(34),
beneficiary_details_data_table_number integer,
beneficiary_details_data_record_number integer,
activity_description_include_value_date varchar(30),
bank_number integer not null,
branch_number integer not null,
account_number integer not null,
id uuid default gen_random_uuid() not null
constraint poalim_ils_account_transactions_pk
primary key
);
comment on column accounter_schema.poalim_ils_account_transactions.serial_number is 'Serial number is how we order transactions in the same day, if they have the same amount.
Lower number is earlier in the day.
So you can''t have multiple rows with the same date, amount and same serial number.
This is also referenced in the end of the expanded_event_date row';
comment on column accounter_schema.poalim_ils_account_transactions.comment_existence_switch is 'Can change and get the same value on existing transaction again if the user added a comment';
comment on column accounter_schema.poalim_ils_account_transactions.comment is 'Can change and get the same value on existing transaction again if the user added a comment';
create unique index poalim_ils_account_transactions_id_uindex
on accounter_schema.poalim_ils_account_transactions (id);
create index poalim_ils_account_transactions_reference_number_index
on accounter_schema.poalim_ils_account_transactions (reference_number);
create index poalim_ils_account_transactions_event_date_index
on accounter_schema.poalim_ils_account_transactions (event_date);
create table accounter_schema.poalim_usd_account_transactions
(
metadata_attributes_original_event_key json,
metadata_attributes_contra_branch_number json,
metadata_attributes_contra_account_number json,
metadata_attributes_contra_bank_number json,
metadata_attributes_contra_account_field_name_lable json,
metadata_attributes_data_group_code json,
metadata_attributes_currency_rate json,
metadata_attributes_contra_currency_code json,
metadata_attributes_rate_fixing_code json,
executing_date date not null,
formatted_executing_date varchar(24) not null,
value_date date not null,
formatted_value_date varchar(24) not null,
original_system_id integer not null,
activity_description varchar(11) not null,
event_amount numeric(10, 2) not null,
current_balance numeric(10, 2) not null,
reference_catenated_number integer not null,
reference_number integer not null,
currency_rate numeric(9, 7) not null,
event_details varchar(14),
rate_fixing_code integer not null,
contra_currency_code integer not null,
event_activity_type_code integer not null,
transaction_type varchar(7) not null,
rate_fixing_short_description varchar(9) not null,
currency_long_description text not null,
activity_type_code integer not null,
event_number integer not null,
validity_date date not null,
comments varchar(30),
comment_existence_switch bit not null,
account_name varchar(30),
contra_bank_number integer not null,
contra_branch_number integer not null,
contra_account_number integer not null,
original_event_key bit not null,
contra_account_field_name_lable varchar(30),
data_group_code bit not null,
rate_fixing_description varchar(34),
url_address_niar varchar(30),
currency_swift_code varchar(3) not null,
url_address varchar(30),
bank_number integer not null,
branch_number integer not null,
account_number integer not null,
id uuid default gen_random_uuid() not null
constraint poalim_usd_account_transactions_pk
primary key
);
create unique index poalim_usd_account_transactions_id_uindex
on accounter_schema.poalim_usd_account_transactions (id);
create table accounter_schema.financial_accounts
(
account_number text not null,
private_business text default 'business'::text not null,
owner uuid,
hashavshevet_account_ils text,
hashavshevet_account_usd text,
hashavshevet_account_eur text,
bank_number integer,
branch_number integer,
extended_bank_number integer,
party_preferred_indication integer,
party_account_involvement_code integer,
account_deal_date integer,
account_update_date integer,
meteg_doar_net integer,
kod_harshaat_peilut integer,
account_closing_reason_code integer,
account_agreement_opening_date integer,
service_authorization_desc text,
branch_type_code integer,
mymail_entitlement_switch integer,
hashavshevet_account_gbp text,
id uuid default gen_random_uuid() not null
constraint financial_accounts_pk
primary key,
type text not null
);
comment on column accounter_schema.financial_accounts.meteg_doar_net is 'Getting mail only online or physical
0 - Also physical
1 - Only online';
create unique index financial_accounts_id_uindex
on accounter_schema.financial_accounts (id);
create table accounter_schema.poalim_deposits_account_transactions
(
data_0_short_product_name varchar(5) not null
constraint data_0_short_product_name_enum
check ((data_0_short_product_name)::text = 'פריים'::text),
data_0_principal_amount numeric(8, 2) not null,
data_0_revalued_total_amount numeric(8, 2) not null,
data_0_end_exit_date date not null,
data_0_payment_date date not null,
data_0_stated_annual_interest_rate bit not null,
data_0_hebrew_purpose_description varchar(10) not null
constraint data_0_hebrew_purpose_description_enum
check ((data_0_hebrew_purpose_description)::text = 'לא רלוונטי'::text),
data_0_objective_amount bit not null,
data_0_objective_date bit not null,
data_0_agreement_opening_date date not null,
data_0_event_withdrawal_amount bit not null,
data_0_start_exit_date date not null,
data_0_period_until_next_event integer not null,
data_0_renewal_description varchar(12) not null
constraint data_0_renewal_description_enum
check ((data_0_renewal_description)::text = ANY
((ARRAY ['פיקדון מתחדש'::character varying, 'יפרע לעו"ש'::character varying])::text[])),
data_0_requested_renewal_number bit not null,
data_0_interest_base_description varchar(5) not null
constraint data_0_interest_base_description_enum
check ((data_0_interest_base_description)::text = 'פריים'::text),
data_0_interest_type_description varchar(5) not null
constraint data_0_interest_type_description_enum
check ((data_0_interest_type_description)::text = 'משתנה'::text),
data_0_spread_percent numeric(5, 2) not null,
data_0_variable_interest_description varchar(22) not null,
data_0_adjusted_interest numeric(4, 2) not null,
data_0_interest_calculating_method_description varchar(6) not null
constraint data_0_interest_calculating_method_description_enum
check ((data_0_interest_calculating_method_description)::text = 'קו ישר'::text),
data_0_interest_crediting_method_description varchar(12) not null
constraint data_0_interest_crediting_method_description_enum
check ((data_0_interest_crediting_method_description)::text = 'לקרן הפיקדון'::text),
data_0_interest_payment_description varchar(4) not null
constraint data_0_interest_payment_description_enum
check ((data_0_interest_payment_description)::text = 'תחנה'::text),
data_0_nominal_interest numeric(4, 2) not null,
data_0_deposit_serial_id integer not null,
data_0_linkage_base_description varchar(30),
data_0_renewal_counter integer not null,
data_0_product_free_text varchar(30) not null,
data_0_party_text_id bigint not null,
data_0_actual_index_rate bit not null,
data_0_interest_type_code integer not null,
data_0_product_number integer not null,
data_0_product_purpose_code bit not null,
data_0_detailed_account_type_code integer not null,
data_0_formatted_end_exit_date varchar(24) not null,
data_0_formatted_payment_date varchar(24) not null,
data_0_formatted_objective_date varchar(30),
data_0_formatted_agreement_opening_date varchar(24) not null,
data_0_formatted_start_exit_date varchar(24) not null,
data_0_lien_description varchar(11)
constraint data_0_lien_description_enum
check ((data_0_lien_description)::text = ANY
((ARRAY ['משועבד'::character varying, 'מבטיח אשראי'::character varying])::text[])),
data_0_withdrawal_enabling_indication bit not null,
data_0_renewal_enabling_indication bit not null,
data_0_standing_order_enabling_indication bit not null,
data_0_addition_enabling_indication bit not null,
data_0_time_unit_description varchar(4) not null
constraint data_0_time_unit_description_enum
check ((data_0_time_unit_description)::text = 'ימים'::text),
data_0_formatted_revalued_total_amount varchar(30),
data_0_warning_existance_indication bit not null,
data_0_renewal_date_explanation varchar(18) not null
constraint data_0_renewal_date_explanation_enum
check ((data_0_renewal_date_explanation)::text = ANY
((ARRAY ['תחנה קרובה'::character varying, 'ייפרע לעו"ש בתאריך'::character varying])::text[])),
source varchar(22) not null
constraint source_enum
check ((source)::text = 'israeliCurrencyDeposit'::text),
validity_date date not null,
validity_time integer not null,
israeli_currency_deposit_principal_balance_amount numeric(8, 2) not null,
deposits_revalued_amount numeric(8, 2) not null,
formatted_validity_time varchar(5) not null,
formatted_date varchar(24) not null,
amount numeric(8, 2) not null,
revaluated_amount numeric(8, 2) not null,
account_number integer not null,
branch_number integer not null,
bank_number integer not null
);
create table accounter_schema.poalim_gbp_account_transactions
(
metadata_attributes_original_event_key json,
metadata_attributes_contra_branch_number json,
metadata_attributes_contra_account_number json,
metadata_attributes_contra_bank_number json,
metadata_attributes_contra_account_field_name_lable json,
metadata_attributes_data_group_code json,
metadata_attributes_currency_rate json,
metadata_attributes_contra_currency_code json,
metadata_attributes_rate_fixing_code json,
executing_date date not null,
formatted_executing_date varchar(24) not null,
value_date date not null,
formatted_value_date varchar(24) not null,
original_system_id integer not null,
activity_description varchar(11) not null,
event_amount numeric(8, 2) not null,
current_balance numeric(9, 2) not null,
reference_catenated_number integer not null,
reference_number integer not null,
currency_rate numeric(9, 7) not null,
event_details varchar(18),
rate_fixing_code integer not null,
contra_currency_code integer not null,
event_activity_type_code integer not null,
transaction_type varchar(7) not null,
rate_fixing_short_description varchar(9) not null,
currency_long_description text not null,
activity_type_code integer not null,
event_number integer not null,
validity_date date not null,
comments varchar(30),
comment_existence_switch bit not null,
account_name varchar(30),
contra_bank_number integer not null,
contra_branch_number integer not null,
contra_account_number integer not null,
original_event_key bit not null,
contra_account_field_name_lable varchar(30),
data_group_code bit not null,
rate_fixing_description varchar(34),
url_address_niar varchar(30),
currency_swift_code varchar(3) not null,
url_address varchar(30),
bank_number integer not null,
branch_number integer not null,
account_number integer not null,
id uuid default gen_random_uuid() not null
constraint poalim_gbp_account_transactions_pk
primary key
);
create unique index poalim_gbp_account_transactions_id_uindex
on accounter_schema.poalim_gbp_account_transactions (id);
create table accounter_schema.sort_codes
(
key integer not null
constraint hash_sort_codes_pk
primary key,
name text
);
create table accounter_schema.businesses
(
name text not null,
id uuid default gen_random_uuid() not null
constraint businesses_pk
primary key,
vat_number text,
tax_siduri_number_2021 text,
password text,
username_vat_website text,
website_login_screenshot text,
nikuim text,
pinkas_social_security_2021 text,
hebrew_name text,
tax_pinkas_number_2020 text,
address text,
address_hebrew text,
wizcloud_token text,
wizcloud_company_id text,
advance_tax_rate real,
email text,
website text,
phone_number text,
bank_account_bank_number integer,
bank_account_branch_number integer,
bank_account_account_number integer,
"bank_account_IBAN" text,
tax_nikuim_pinkas_number text,
bank_account_swift text,
vat_report_cadence integer,
contract text,
country text default 'Israel'::text not null,
pinkas_social_security_2022 text,
tax_siduri_number_2022 text,
registration_date date,
no_invoices_required boolean default false not null,
suggestion_data jsonb,
can_settle_with_receipt boolean default false not null,
sort_code integer
constraint businesses_hash_sort_codes_key_fk
references accounter_schema.sort_codes
);
create unique index businesses_id_uindex
on accounter_schema.businesses (id);
create unique index businesses_tax_note_number_uindex
on accounter_schema.businesses (tax_siduri_number_2021);
create unique index businesses_name_uindex
on accounter_schema.businesses (name);
create table accounter_schema.employees
(
first_name text,
last_name text,
pension_fund_id uuid,
pension_member_id text,
national_id text,
birth_date text,
pension_policy_number text,
training_fund_policy_number text,
training_fund_start_date text,
employer uuid,
gender text,
family_status text,
role_status text,
phone_number text,
address text,
israel_resident boolean,
kibutz_member boolean,
kupat_holim text,
start_work_date text,
email text,
bank_number integer,
account_number integer,
branch_number integer,
business_id uuid not null
constraint employees_pk
primary key
constraint employees_businesses_id_fk
references accounter_schema.businesses
);
create unique index employees_business_id_uindex
on accounter_schema.employees (business_id);
create table accounter_schema.pension_funds
(
name text not null,
otsar_id text,
id uuid not null
constraint pension_funds_pk
primary key
constraint pension_funds_businesses_id_fk
references accounter_schema.businesses,
type text,
management_fees numeric(9, 2),
links text[],
bank_account_bank_number integer,
bank_account_branch_number integer,
bank_account_account_number integer,
bank_account_name text,
email text,
managing_company_name text,
managing_company_id text,
emails text[]
);
create unique index pension_funds_id_uindex
on accounter_schema.pension_funds (id);
create unique index hash_sort_codes_key_uindex
on accounter_schema.sort_codes (key);
create table accounter_schema.etherscan_transactions
(
tx_id text not null,
wallet_address text not null,
contract_address text not null,
from_address text not null,
to_address text not null,
currency text not null,
transaction_hash text,
amount numeric not null,
value_date date not null,
raw_data jsonb not null,
event_date timestamp not null,
gas_fee numeric,
id uuid default gen_random_uuid() not null,
primary key (tx_id, currency)
);
create unique index etherscan_transactions_id_uindex
on accounter_schema.etherscan_transactions (id);
create table accounter_schema.etana_account_transactions
(
transaction_id text not null
primary key,
account_id text not null,
time date not null,
currency text not null,
amount numeric not null,
description text not null,
fee numeric,
fee_tx_id text,
metadata text,
action_type text not null,
raw_data jsonb not null
);
create table accounter_schema.poalim_swift_account_transactions
(
start_date text,
formatted_start_date text,
swift_status_code text,
swift_status_desc text,
amount text,
currency_code_catenated_key text,
currency_long_description text,
charge_party_name text,
reference_number text,
transfer_catenated_id text,
data_origin_code text,
swift_isn_serial_number text,
swift_bank_code text,
order_customer_name text,
beneficiary_english_street_name text,
beneficiary_english_city_name text,
beneficiary_english_country_name text,
swift_senders_reference_20 text,
swift_bank_operation_code_23b text,
swift_value_date_currency_amount_32a text,
swift_currency_instructed_amount_33b text,
swift_ordering_customer_50k_1 text,
swift_ordering_customer_50k_2 text,
swift_ordering_customer_50k_3 text,
swift_ordering_customer_50k_4 text,
swift_ordering_customer_50k_5 text,
swift_ordering_institution_52a text,
swift_senders_correspondent_53a text,
swift_beneficiary_customer_59_1 text,
swift_beneficiary_customer_59_2 text,
swift_beneficiary_customer_59_3 text,
swift_beneficiary_customer_59_4 text,
swift_beneficiary_customer_59_5 text,
swift_remittance_information_70_1 text,
swift_remittance_information_70_2 text,
swift_details_of_charges_71a text,
account_number integer,
branch_number integer,
bank_number integer,
swift_senders_charges_71f text,
swift_ordering_institution_52d_1 text,
swift_ordering_institution_52d_2 text,
swift_ordering_institution_52d_3 text,
swift_receivers_correspondent_54a text,
id uuid default gen_random_uuid() not null
constraint poalim_swift_account_transactions_pk
primary key
);
create table accounter_schema.transactions_raw_list
(
id uuid default gen_random_uuid() not null
constraint transactions_raw_list_pk
primary key,
creditcard_id uuid
constraint transactions_raw_list_isracard_creditcard_transactions_id_fk
references accounter_schema.isracard_creditcard_transactions,
poalim_ils_id uuid
constraint transactions_raw_list_poalim_ils_account_transactions_id_fk
references accounter_schema.poalim_ils_account_transactions,
poalim_eur_id uuid
constraint transactions_raw_list_poalim_eur_account_transactions_id_fk
references accounter_schema.poalim_eur_account_transactions,
poalim_gbp_id uuid
constraint transactions_raw_list_poalim_gbp_account_transactions_id_fk
references accounter_schema.poalim_gbp_account_transactions,
poalim_usd_id uuid
constraint transactions_raw_list_poalim_usd_account_transactions_id_fk
references accounter_schema.poalim_usd_account_transactions,
kraken_id text,
etana_id text,
etherscan_id uuid,
poalim_swift_id uuid
constraint transactions_raw_list_poalim_swift_account_transactions_id_fk
references accounter_schema.poalim_swift_account_transactions,
constraint transactions_raw_list_check
check (((((((((((creditcard_id IS NOT NULL))::integer + ((poalim_ils_id IS NOT NULL))::integer) +
((poalim_eur_id IS NOT NULL))::integer) + ((poalim_gbp_id IS NOT NULL))::integer) +
((poalim_usd_id IS NOT NULL))::integer) + ((poalim_swift_id IS NOT NULL))::integer) +
((kraken_id IS NOT NULL))::integer) + ((etana_id IS NOT NULL))::integer) +
((etherscan_id IS NOT NULL))::integer) = 1)
);
create unique index transactions_raw_list_id_uindex
on accounter_schema.transactions_raw_list (id);
create unique index transactions_raw_list_creditcard_id_uindex
on accounter_schema.transactions_raw_list (creditcard_id)
where (creditcard_id IS NOT NULL);
create unique index transactions_raw_list_poalim_eur_id_uindex
on accounter_schema.transactions_raw_list (poalim_eur_id)
where (poalim_eur_id IS NOT NULL);
create unique index transactions_raw_list_poalim_gbp_id_uindex
on accounter_schema.transactions_raw_list (poalim_gbp_id)
where (poalim_gbp_id IS NOT NULL);
create unique index transactions_raw_list_poalim_ils_id_uindex
on accounter_schema.transactions_raw_list (poalim_ils_id)
where (poalim_ils_id IS NOT NULL);
create unique index transactions_raw_list_poalim_usd_id_uindex
on accounter_schema.transactions_raw_list (poalim_usd_id)
where (poalim_usd_id IS NOT NULL);
create unique index poalim_swift_account_transactions_id_uindex
on accounter_schema.poalim_swift_account_transactions (id);
create table accounter_schema.kraken_trades
(
trade_id text not null
primary key,
account_nickname text not null,
pair text not null,
value_date timestamp not null,
order_type text not null,
price numeric not null,
cost numeric not null,
fee numeric not null,
vol numeric not null,
margin numeric not null,
raw_data jsonb not null
);
create table accounter_schema.kraken_ledger_records
(
ledger_id text not null
primary key,
account_nickname text not null,
action_type text not null,
currency text not null,
amount numeric not null,
balance numeric not null,
fee numeric not null,
value_date timestamp not null,
trade_ref_id text,
raw_data jsonb not null
);
create table accounter_schema.crypto_currencies
(
symbol text not null
constraint crypto_currencies_pk
primary key,
name text not null,
coingecko_id text,
coinmarketcap_id integer
);
create unique index crypto_currencies_symbol_uindex
on accounter_schema.crypto_currencies (symbol);
create table accounter_schema.crypto_exchange_rates
(
date timestamp not null,
coin_symbol text not null
constraint crypto_exchange_rates_crypto_currencies_symbol_fk
references accounter_schema.crypto_currencies,
value numeric not null,
against accounter_schema.currency default 'USD'::accounter_schema.currency not null,
sample_date timestamp not null,
constraint crypto_exchange_rates_pk_2
primary key (date, coin_symbol, against),
constraint crypto_exchange_rates_pk
unique (date, coin_symbol)
);
create table accounter_schema.business_trips
(
id uuid default gen_random_uuid() not null,
name text not null,
from_date date,
to_date date,
destination text,
trip_purpose text
);
create unique index business_trips_id_uindex
on accounter_schema.business_trips (id);
create unique index business_trips_name_uindex
on accounter_schema.business_trips (name);
create table accounter_schema.business_trips_attendees
(
attendee_business_id uuid not null
constraint business_trips_attendees_businesses_id_fk
references accounter_schema.businesses,
business_trip_id uuid not null
constraint business_trips_attendees_business_trips_id_fk
references accounter_schema.business_trips (id),
constraint business_trips_attendees_pk
primary key (business_trip_id, attendee_business_id)
);
create table accounter_schema.business_trips_transactions_tns
(
id uuid not null
constraint business_trips_transactions_tns_pk
primary key,
expense_type text
);
create unique index business_trips_transactions_tns_id_uindex
on accounter_schema.business_trips_transactions_tns (id);
create table accounter_schema.financial_entities
(
id uuid default gen_random_uuid() not null
constraint financial_entities_pk
primary key,
type text,
owner_id uuid
constraint financial_entities_businesses_id_fk
references accounter_schema.businesses,
name text not null,
sort_code integer
constraint financial_entities_hash_sort_codes_key_fk
references accounter_schema.sort_codes,
created_at timestamp default CURRENT_TIMESTAMP not null,
updated_at timestamp default CURRENT_TIMESTAMP not null
);
alter table accounter_schema.businesses
add constraint businesses_financial_entities_id_fk
foreign key (id) references accounter_schema.financial_entities;
create table accounter_schema.tax_categories
(
id uuid default gen_random_uuid() not null
constraint tax_categories_pk
primary key
constraint tax_categories_financial_entities_id_fk
references accounter_schema.financial_entities,
name text not null,
hashavshevet_name text,
sort_code integer not null
constraint tax_categories_hash_sort_codes_key_fk
references accounter_schema.sort_codes
);
create table accounter_schema.charges
(
id uuid default gen_random_uuid() not null
constraint charges_pk
primary key,
owner_id uuid not null
constraint charges_businesses_id_fk
references accounter_schema.businesses,
is_conversion boolean default false not null,
is_property boolean default false not null,
accountant_reviewed boolean default false not null,
user_description text,
created_at timestamp default CURRENT_TIMESTAMP not null,
updated_at timestamp default CURRENT_TIMESTAMP not null,
tax_category_id uuid
constraint charges_tax_categories_id_fk
references accounter_schema.tax_categories
);
create table accounter_schema.salaries
(
direct_payment_amount numeric(9, 2) not null,
employee text,
employe