From df479dba6d579a572fc05fd6e9b4f0f8e8fedebb Mon Sep 17 00:00:00 2001 From: Olga Telezhnaya Date: Mon, 23 Aug 2021 16:20:05 +0300 Subject: [PATCH] wip: feat: add ft, nft aggregated tables --- .../down.sql | 2 + .../up.sql | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 migrations/2021-08-23-161500_aggregated_ft_nft_tables/down.sql create mode 100644 migrations/2021-08-23-161500_aggregated_ft_nft_tables/up.sql diff --git a/migrations/2021-08-23-161500_aggregated_ft_nft_tables/down.sql b/migrations/2021-08-23-161500_aggregated_ft_nft_tables/down.sql new file mode 100644 index 00000000..70d8b5b7 --- /dev/null +++ b/migrations/2021-08-23-161500_aggregated_ft_nft_tables/down.sql @@ -0,0 +1,2 @@ +DROP TABLE aggregated__fungible_tokens; +DROP TABLE aggregated__non_fungible_tokens; diff --git a/migrations/2021-08-23-161500_aggregated_ft_nft_tables/up.sql b/migrations/2021-08-23-161500_aggregated_ft_nft_tables/up.sql new file mode 100644 index 00000000..f172b5ba --- /dev/null +++ b/migrations/2021-08-23-161500_aggregated_ft_nft_tables/up.sql @@ -0,0 +1,62 @@ +CREATE TABLE aggregated__fungible_tokens +( + id bigserial NOT NULL, + included_in_transaction_hash text NOT NULL, + included_in_transaction_timestamp numeric(20, 0) NOT NULL, + transaction_status execution_outcome_status NOT NULL, + issued_contract_id text NOT NULL, + called_method text NOT NULL, + predecessor_account_id text NOT NULL, + receiver_account_id text NOT NULL, + amount numeric(45, 0) NOT NULL, + args jsonb NOT NULL +); + +ALTER TABLE ONLY aggregated__fungible_tokens + ADD CONSTRAINT aggregated__fungible_tokens_pkey PRIMARY KEY (id); + +CREATE INDEX aggregated__fungible_tokens_timestamp_idx ON aggregated__fungible_tokens USING btree (included_in_transaction_timestamp); + +ALTER TABLE ONLY aggregated__fungible_tokens + ADD CONSTRAINT aggregated__fungible_tokens_fk FOREIGN KEY (included_in_transaction_hash) REFERENCES transactions (transaction_hash) ON DELETE CASCADE; + +ALTER TABLE ONLY aggregated__fungible_tokens + ADD CONSTRAINT aggregated__ft_issued_contract_id_fk FOREIGN KEY (issued_contract_id) REFERENCES accounts (account_id) ON DELETE CASCADE; + +ALTER TABLE ONLY aggregated__fungible_tokens + ADD CONSTRAINT aggregated__ft_predecessor_account_id_fk FOREIGN KEY (predecessor_account_id) REFERENCES accounts (account_id) ON DELETE CASCADE; + +ALTER TABLE ONLY aggregated__fungible_tokens + ADD CONSTRAINT aggregated__ft_receiver_account_id_fk FOREIGN KEY (receiver_account_id) REFERENCES accounts (account_id) ON DELETE CASCADE; + +CREATE TABLE aggregated__non_fungible_tokens +( + id bigserial NOT NULL, + included_in_transaction_hash text NOT NULL, + included_in_transaction_timestamp numeric(20, 0) NOT NULL, + transaction_status execution_outcome_status NOT NULL, + issued_contract_id text NOT NULL, + called_method text NOT NULL, + non_fungible_token_id text NOT NULL, + predecessor_account_id text NOT NULL, + receiver_account_id text NOT NULL, + amount numeric(45, 0) NOT NULL, + args jsonb NOT NULL +); + +ALTER TABLE ONLY aggregated__non_fungible_tokens + ADD CONSTRAINT aggregated__non_fungible_tokens_pkey PRIMARY KEY (id); + +CREATE INDEX aggregated__non_fungible_tokens_timestamp_idx ON aggregated__non_fungible_tokens USING btree (included_in_transaction_timestamp); + +ALTER TABLE ONLY aggregated__non_fungible_tokens + ADD CONSTRAINT aggregated__non_fungible_tokens_fk FOREIGN KEY (included_in_transaction_hash) REFERENCES transactions (transaction_hash) ON DELETE CASCADE; + +ALTER TABLE ONLY aggregated__non_fungible_tokens + ADD CONSTRAINT aggregated__nft_issued_contract_id_fk FOREIGN KEY (issued_contract_id) REFERENCES accounts (account_id) ON DELETE CASCADE; + +ALTER TABLE ONLY aggregated__non_fungible_tokens + ADD CONSTRAINT aggregated__nft_predecessor_account_id_fk FOREIGN KEY (predecessor_account_id) REFERENCES accounts (account_id) ON DELETE CASCADE; + +ALTER TABLE ONLY aggregated__non_fungible_tokens + ADD CONSTRAINT aggregated__nft_receiver_account_id_fk FOREIGN KEY (receiver_account_id) REFERENCES accounts (account_id) ON DELETE CASCADE;