diff --git a/app/models/tx_display_info.rb b/app/models/tx_display_info.rb deleted file mode 100644 index aca50509d..000000000 --- a/app/models/tx_display_info.rb +++ /dev/null @@ -1,14 +0,0 @@ -class TxDisplayInfo < ApplicationRecord -end - -# == Schema Information -# -# Table name: tx_display_infos -# -# ckb_transaction_id :bigint not null, primary key -# inputs :jsonb -# outputs :jsonb -# created_at :datetime not null -# updated_at :datetime not null -# income :jsonb -# diff --git a/db/migrate/20240408065818_drop_unused_tables.rb b/db/migrate/20240408065818_drop_unused_tables.rb new file mode 100644 index 000000000..6694b10ee --- /dev/null +++ b/db/migrate/20240408065818_drop_unused_tables.rb @@ -0,0 +1,8 @@ +class DropUnusedTables < ActiveRecord::Migration[7.0] + def change + drop_table :pool_transaction_entries, if_exists: true + drop_table :old_ckb_transactions, if_exists: true + drop_table :temp_view, if_exists: true + drop_table :tx_display_infos, if_exists: true + end +end diff --git a/db/migrate/20240408075718_rebind_cell_inputs_id_sequence.rb b/db/migrate/20240408075718_rebind_cell_inputs_id_sequence.rb new file mode 100644 index 000000000..97eca5f31 --- /dev/null +++ b/db/migrate/20240408075718_rebind_cell_inputs_id_sequence.rb @@ -0,0 +1,7 @@ +class RebindCellInputsIdSequence < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + ALTER SEQUENCE cell_inputs_id_seq OWNED BY cell_inputs.id; + SQL + end +end diff --git a/db/migrate/20240408082159_drop_cell_inputs_old_tables.rb b/db/migrate/20240408082159_drop_cell_inputs_old_tables.rb new file mode 100644 index 000000000..7e6bff848 --- /dev/null +++ b/db/migrate/20240408082159_drop_cell_inputs_old_tables.rb @@ -0,0 +1,5 @@ +class DropCellInputsOldTables < ActiveRecord::Migration[7.0] + def change + drop_table :cell_inputs_old, if_exists: true + end +end diff --git a/db/structure.sql b/db/structure.sql index f5256d4c6..9cf0765f1 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -980,17 +980,17 @@ ALTER SEQUENCE public.cell_dependencies_id_seq OWNED BY public.cell_dependencies -- --- Name: cell_inputs_old; Type: TABLE; Schema: public; Owner: - +-- Name: cell_inputs; Type: TABLE; Schema: public; Owner: - -- -CREATE TABLE public.cell_inputs_old ( +CREATE TABLE public.cell_inputs ( id bigint NOT NULL, ckb_transaction_id bigint, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, previous_cell_output_id bigint, from_cell_base boolean DEFAULT false, - block_id numeric(30,0), + block_id bigint, since numeric(30,0) DEFAULT 0.0, cell_type integer DEFAULT 0, index integer, @@ -1015,27 +1015,7 @@ CREATE SEQUENCE public.cell_inputs_id_seq -- Name: cell_inputs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - -- -ALTER SEQUENCE public.cell_inputs_id_seq OWNED BY public.cell_inputs_old.id; - - --- --- Name: cell_inputs; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.cell_inputs ( - id bigint DEFAULT nextval('public.cell_inputs_id_seq'::regclass) NOT NULL, - ckb_transaction_id bigint, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, - previous_cell_output_id bigint, - from_cell_base boolean DEFAULT false, - block_id bigint, - since numeric(30,0) DEFAULT 0.0, - cell_type integer DEFAULT 0, - index integer, - previous_tx_hash bytea, - previous_index integer -); +ALTER SEQUENCE public.cell_inputs_id_seq OWNED BY public.cell_inputs.id; -- @@ -1795,64 +1775,6 @@ CREATE SEQUENCE public.nrc_factory_cells_id_seq ALTER SEQUENCE public.nrc_factory_cells_id_seq OWNED BY public.nrc_factory_cells.id; --- --- Name: old_ckb_transactions; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.old_ckb_transactions ( - id bigint NOT NULL, - tx_hash bytea, - block_id bigint, - block_number numeric(30,0), - block_timestamp numeric(30,0), - transaction_fee numeric(30,0), - version integer, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, - is_cellbase boolean DEFAULT false, - header_deps bytea, - cell_deps jsonb, - witnesses jsonb, - live_cell_changes integer, - capacity_involved numeric(30,0), - contained_address_ids bigint[] DEFAULT '{}'::bigint[], - tags character varying[] DEFAULT '{}'::character varying[], - contained_udt_ids bigint[] DEFAULT '{}'::bigint[], - dao_address_ids bigint[] DEFAULT '{}'::bigint[], - udt_address_ids bigint[] DEFAULT '{}'::bigint[], - bytes integer DEFAULT 0, - cycles integer, - confirmation_time integer, - tx_status integer DEFAULT 2 NOT NULL -); - - --- --- Name: COLUMN old_ckb_transactions.confirmation_time; Type: COMMENT; Schema: public; Owner: - --- - -COMMENT ON COLUMN public.old_ckb_transactions.confirmation_time IS 'it cost how many seconds to confirm this transaction'; - - --- --- Name: old_ckb_transactions_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.old_ckb_transactions_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: old_ckb_transactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.old_ckb_transactions_id_seq OWNED BY public.old_ckb_transactions.id; - - -- -- Name: omiga_inscription_infos; Type: TABLE; Schema: public; Owner: - -- @@ -1897,54 +1819,6 @@ CREATE SEQUENCE public.omiga_inscription_infos_id_seq ALTER SEQUENCE public.omiga_inscription_infos_id_seq OWNED BY public.omiga_inscription_infos.id; --- --- Name: pool_transaction_entries; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.pool_transaction_entries ( - id bigint NOT NULL, - cell_deps jsonb, - tx_hash bytea, - header_deps jsonb, - inputs jsonb, - outputs jsonb, - outputs_data jsonb, - version integer, - witnesses jsonb, - transaction_fee numeric(30,0), - block_number numeric(30,0), - block_timestamp numeric(30,0), - cycles numeric(30,0), - tx_size numeric(30,0), - display_inputs jsonb, - display_outputs jsonb, - tx_status integer DEFAULT 0, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL, - detailed_message text, - bytes integer DEFAULT 0 -); - - --- --- Name: pool_transaction_entries_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.pool_transaction_entries_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pool_transaction_entries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.pool_transaction_entries_id_seq OWNED BY public.pool_transaction_entries.id; - - -- -- Name: portfolios; Type: TABLE; Schema: public; Owner: - -- @@ -2376,20 +2250,6 @@ CREATE SEQUENCE public.transaction_propagation_delays_id_seq ALTER SEQUENCE public.transaction_propagation_delays_id_seq OWNED BY public.transaction_propagation_delays.id; --- --- Name: tx_display_infos; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.tx_display_infos ( - ckb_transaction_id bigint NOT NULL, - inputs jsonb, - outputs jsonb, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL, - income jsonb -); - - -- -- Name: type_scripts; Type: TABLE; Schema: public; Owner: - -- @@ -2814,10 +2674,10 @@ ALTER TABLE ONLY public.cell_dependencies ALTER COLUMN id SET DEFAULT nextval('p -- --- Name: cell_inputs_old id; Type: DEFAULT; Schema: public; Owner: - +-- Name: cell_inputs id; Type: DEFAULT; Schema: public; Owner: - -- -ALTER TABLE ONLY public.cell_inputs_old ALTER COLUMN id SET DEFAULT nextval('public.cell_inputs_id_seq'::regclass); +ALTER TABLE ONLY public.cell_inputs ALTER COLUMN id SET DEFAULT nextval('public.cell_inputs_id_seq'::regclass); -- @@ -2925,13 +2785,6 @@ ALTER TABLE ONLY public.mining_infos ALTER COLUMN id SET DEFAULT nextval('public ALTER TABLE ONLY public.nrc_factory_cells ALTER COLUMN id SET DEFAULT nextval('public.nrc_factory_cells_id_seq'::regclass); --- --- Name: old_ckb_transactions id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.old_ckb_transactions ALTER COLUMN id SET DEFAULT nextval('public.old_ckb_transactions_id_seq'::regclass); - - -- -- Name: omiga_inscription_infos id; Type: DEFAULT; Schema: public; Owner: - -- @@ -2939,13 +2792,6 @@ ALTER TABLE ONLY public.old_ckb_transactions ALTER COLUMN id SET DEFAULT nextval ALTER TABLE ONLY public.omiga_inscription_infos ALTER COLUMN id SET DEFAULT nextval('public.omiga_inscription_infos_id_seq'::regclass); --- --- Name: pool_transaction_entries id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pool_transaction_entries ALTER COLUMN id SET DEFAULT nextval('public.pool_transaction_entries_id_seq'::regclass); - - -- -- Name: portfolios id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3215,14 +3061,6 @@ ALTER TABLE ONLY public.cell_dependencies ADD CONSTRAINT cell_dependencies_pkey PRIMARY KEY (id); --- --- Name: cell_inputs_old cell_inputs_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.cell_inputs_old - ADD CONSTRAINT cell_inputs_pkey PRIMARY KEY (id); - - -- -- Name: cell_inputs cell_inputs_pkey_new; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3423,14 +3261,6 @@ ALTER TABLE ONLY public.nrc_factory_cells ADD CONSTRAINT nrc_factory_cells_pkey PRIMARY KEY (id); --- --- Name: old_ckb_transactions old_ckb_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.old_ckb_transactions - ADD CONSTRAINT old_ckb_transactions_pkey PRIMARY KEY (id); - - -- -- Name: omiga_inscription_infos omiga_inscription_infos_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3439,14 +3269,6 @@ ALTER TABLE ONLY public.omiga_inscription_infos ADD CONSTRAINT omiga_inscription_infos_pkey PRIMARY KEY (id); --- --- Name: pool_transaction_entries pool_transaction_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pool_transaction_entries - ADD CONSTRAINT pool_transaction_entries_pkey PRIMARY KEY (id); - - -- -- Name: portfolios portfolios_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3551,14 +3373,6 @@ ALTER TABLE ONLY public.transaction_propagation_delays ADD CONSTRAINT transaction_propagation_delays_pkey PRIMARY KEY (id); --- --- Name: tx_display_infos tx_display_infos_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.tx_display_infos - ADD CONSTRAINT tx_display_infos_pkey PRIMARY KEY (ckb_transaction_id); - - -- -- Name: type_scripts type_scripts_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -3615,14 +3429,6 @@ ALTER TABLE ONLY public.token_collections ADD CONSTRAINT unique_sn UNIQUE (sn); --- --- Name: pool_transaction_entries unique_tx_hash; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.pool_transaction_entries - ADD CONSTRAINT unique_tx_hash UNIQUE (tx_hash); - - -- -- Name: udts unique_type_hash; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4067,20 +3873,6 @@ CREATE INDEX index_cell_dependencies_on_contract_id ON public.cell_dependencies CREATE INDEX index_cell_dependencies_on_script_id ON public.cell_dependencies USING btree (script_id); --- --- Name: index_cell_inputs_on_block_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_cell_inputs_on_block_id ON public.cell_inputs_old USING btree (block_id); - - --- --- Name: index_cell_inputs_on_ckb_transaction_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_cell_inputs_on_ckb_transaction_id ON public.cell_inputs_old USING btree (ckb_transaction_id); - - -- -- Name: index_cell_inputs_on_ckb_transaction_id_and_index; Type: INDEX; Schema: public; Owner: - -- @@ -4088,20 +3880,6 @@ CREATE INDEX index_cell_inputs_on_ckb_transaction_id ON public.cell_inputs_old U CREATE UNIQUE INDEX index_cell_inputs_on_ckb_transaction_id_and_index ON public.cell_inputs USING btree (ckb_transaction_id, index); --- --- Name: index_cell_inputs_on_previous_cell_output_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_cell_inputs_on_previous_cell_output_id ON public.cell_inputs_old USING btree (previous_cell_output_id); - - --- --- Name: index_cell_inputs_on_previous_tx_hash_and_previous_index; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_cell_inputs_on_previous_tx_hash_and_previous_index ON public.cell_inputs_old USING btree (previous_tx_hash, previous_index); - - -- -- Name: index_cell_outputs_on_address_id_and_status; Type: INDEX; Schema: public; Owner: - -- @@ -4375,69 +4153,6 @@ CREATE INDEX index_mining_infos_on_block_number ON public.mining_infos USING btr CREATE UNIQUE INDEX index_nrc_factory_cells_on_code_hash_and_hash_type_and_args ON public.nrc_factory_cells USING btree (code_hash, hash_type, args); --- --- Name: index_old_ckb_transactions_on_block_id_and_block_timestamp; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_block_id_and_block_timestamp ON public.old_ckb_transactions USING btree (block_id, block_timestamp); - - --- --- Name: index_old_ckb_transactions_on_block_timestamp_and_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_block_timestamp_and_id ON public.old_ckb_transactions USING btree (block_timestamp DESC NULLS LAST, id DESC); - - --- --- Name: index_old_ckb_transactions_on_contained_address_ids_and_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_contained_address_ids_and_id ON public.old_ckb_transactions USING gin (contained_address_ids, id); - - --- --- Name: index_old_ckb_transactions_on_contained_udt_ids; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_contained_udt_ids ON public.old_ckb_transactions USING gin (contained_udt_ids); - - --- --- Name: index_old_ckb_transactions_on_dao_address_ids; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_dao_address_ids ON public.old_ckb_transactions USING gin (dao_address_ids); - - --- --- Name: index_old_ckb_transactions_on_is_cellbase; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_is_cellbase ON public.old_ckb_transactions USING btree (is_cellbase); - - --- --- Name: index_old_ckb_transactions_on_tags; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_tags ON public.old_ckb_transactions USING gin (tags); - - --- --- Name: index_old_ckb_transactions_on_tx_hash_and_block_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_old_ckb_transactions_on_tx_hash_and_block_id ON public.old_ckb_transactions USING btree (tx_hash, block_id); - - --- --- Name: index_old_ckb_transactions_on_udt_address_ids; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_old_ckb_transactions_on_udt_address_ids ON public.old_ckb_transactions USING gin (udt_address_ids); - - -- -- Name: index_omiga_inscription_infos_on_udt_hash; Type: INDEX; Schema: public; Owner: - -- @@ -4445,27 +4160,6 @@ CREATE INDEX index_old_ckb_transactions_on_udt_address_ids ON public.old_ckb_tra CREATE UNIQUE INDEX index_omiga_inscription_infos_on_udt_hash ON public.omiga_inscription_infos USING btree (udt_hash); --- --- Name: index_pool_transaction_entries_on_id_and_tx_status; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pool_transaction_entries_on_id_and_tx_status ON public.pool_transaction_entries USING btree (id, tx_status); - - --- --- Name: index_pool_transaction_entries_on_tx_hash; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pool_transaction_entries_on_tx_hash ON public.pool_transaction_entries USING hash (tx_hash); - - --- --- Name: index_pool_transaction_entries_on_tx_status; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pool_transaction_entries_on_tx_status ON public.pool_transaction_entries USING btree (tx_status); - - -- -- Name: index_portfolios_on_user_id_and_address_id; Type: INDEX; Schema: public; Owner: - -- @@ -4949,13 +4643,6 @@ ALTER INDEX public.ckb_tx_uni_tx_hash ATTACH PARTITION public.ckb_transactions_r CREATE TRIGGER after_delete_update_ckb_transactions_count AFTER DELETE ON public.ckb_transactions FOR EACH ROW EXECUTE FUNCTION public.decrease_ckb_transactions_count(); --- --- Name: old_ckb_transactions after_delete_update_ckb_transactions_count; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER after_delete_update_ckb_transactions_count AFTER DELETE ON public.old_ckb_transactions FOR EACH ROW EXECUTE FUNCTION public.decrease_ckb_transactions_count(); - - -- -- Name: ckb_transactions after_insert_update_ckb_transactions_count; Type: TRIGGER; Schema: public; Owner: - -- @@ -4963,13 +4650,6 @@ CREATE TRIGGER after_delete_update_ckb_transactions_count AFTER DELETE ON public CREATE TRIGGER after_insert_update_ckb_transactions_count AFTER INSERT ON public.ckb_transactions FOR EACH ROW EXECUTE FUNCTION public.increase_ckb_transactions_count(); --- --- Name: old_ckb_transactions after_insert_update_ckb_transactions_count; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER after_insert_update_ckb_transactions_count AFTER INSERT ON public.old_ckb_transactions FOR EACH ROW EXECUTE FUNCTION public.increase_ckb_transactions_count(); - - -- -- Name: ckb_transactions after_update_ckb_transactions_count; Type: TRIGGER; Schema: public; Owner: - -- @@ -4977,20 +4657,6 @@ CREATE TRIGGER after_insert_update_ckb_transactions_count AFTER INSERT ON public CREATE TRIGGER after_update_ckb_transactions_count AFTER UPDATE ON public.ckb_transactions FOR EACH ROW EXECUTE FUNCTION public.update_ckb_transactions_count(); --- --- Name: pool_transaction_entries insert_ckb_transactions; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER insert_ckb_transactions AFTER INSERT ON public.pool_transaction_entries FOR EACH ROW EXECUTE FUNCTION public.insert_into_ckb_transactions(); - - --- --- Name: old_ckb_transactions sync_to_account_book; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER sync_to_account_book AFTER INSERT OR UPDATE ON public.old_ckb_transactions FOR EACH ROW EXECUTE FUNCTION public.synx_tx_to_account_book(); - - -- -- Name: block_transactions fk_rails_a0eeb26f19; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -5305,6 +4971,9 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240315015432'), ('20240330023445'), ('20240407100517'), -('20240408024145'); +('20240408024145'), +('20240408065818'), +('20240408075718'), +('20240408082159');