Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrew7234/consolidate migrations #728

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

Andrew7234
Copy link
Collaborator

@Andrew7234 Andrew7234 commented Jul 18, 2024

Consolidates our rather long list of migrations from ~32 -> 5. Although this PR is intended to be deployed on a fresh database, operators can redeploy with this version and then manually update their existing deployments by going into the db and running update schema_migrations set version = 5. This will allow future migrations (which will now start at 06_... to properly apply to the database.

Functionally, this PR is mostly a no-op, with two exceptions:

  • chain.blocks.metadata was removed because it was not being used. It was likely an artifact from years ago.
  • There was a missing permission for the new history.staking_events table; it has been granted properly as of this PR.

Validation:
Comparison of the dumped database schema (using pg_dump -s) for main branch / feature branch:

> diff main.sql new.sql

Explanation: chain.blocks.metadata was removed; gas_limit, size_limit, and epoch were reordered.
354a355,357
>     gas_limit public.uint_numeric DEFAULT 0 NOT NULL,
>     size_limit public.uint_numeric DEFAULT 0 NOT NULL,
>     epoch public.uint63 DEFAULT 0 NOT NULL,
358,361d360
<     metadata jsonb,
<     gas_limit public.uint_numeric DEFAULT 0 NOT NULL,
<     epoch public.uint63 DEFAULT 0 NOT NULL,
<     size_limit public.uint_numeric DEFAULT 0 NOT NULL,

Explanation: reordering of columns
638a638,639
>     title text,
>     description text,
649,651c650
<     invalid_votes public.uint_numeric DEFAULT 0 NOT NULL,
<     title text,
<     description text
---
>     invalid_votes public.uint_numeric DEFAULT 0 NOT NULL
806a806,808
>     fee_symbol text DEFAULT ''::text NOT NULL,
>     fee_proxy_module text,
>     fee_proxy_id bytea,
813a816
>     amount_symbol text,
821a825,830
>     oasis_encrypted_format public.call_format,
>     oasis_encrypted_public_key bytea,
>     oasis_encrypted_data_nonce bytea,
>     oasis_encrypted_data_data bytea,
>     oasis_encrypted_result_nonce bytea,
>     oasis_encrypted_result_data bytea,
829,838d837
<     amount_symbol text,
<     fee_symbol text DEFAULT ''::text NOT NULL,
<     fee_proxy_module text,
<     fee_proxy_id bytea,
<     oasis_encrypted_format public.call_format,
<     oasis_encrypted_public_key bytea,
<     oasis_encrypted_data_nonce bytea,
<     oasis_encrypted_data_data bytea,
<     oasis_encrypted_result_nonce bytea,
<     oasis_encrypted_result_data bytea,

Explanation: chain.transactions.body column was reordered.
889a889
>     body jsonb,
892,893c892
<     message text,
<     body jsonb
---
>     message text

Explanation: A previous migration (`20_consensus_debonding_delegations...`) created a new `chain.debonding_delegations_new` table which was populated and then renamed to `chain.debonding_delegations` to replace the old table of the same name. The rename did not apply to the constraints, which kept the `_new` suffix in their names. After this PR, the constraints now reflect the table name since the rename migration no longer occurs.
1162c1161
< -- Name: debonding_delegations debonding_delegations_new_pkey; Type: CONSTRAINT; Schema: chain; Owner: rwuser
---
> -- Name: debonding_delegations debonding_delegations_pkey; Type: CONSTRAINT; Schema: chain; Owner: rwuser
1166c1165
<     ADD CONSTRAINT debonding_delegations_new_pkey PRIMARY KEY (delegatee, delegator, debond_end);
---
>     ADD CONSTRAINT debonding_delegations_pkey PRIMARY KEY (delegatee, delegator, debond_end);
1769c1768
< -- Name: debonding_delegations debonding_delegations_new_delegatee_fkey; Type: FK CONSTRAINT; Schema: chain; Owner: rwuser
---
> -- Name: debonding_delegations debonding_delegations_delegatee_fkey; Type: FK CONSTRAINT; Schema: chain; Owner: rwuser
1773c1772
<     ADD CONSTRAINT debonding_delegations_new_delegatee_fkey FOREIGN KEY (delegatee) REFERENCES chain.accounts(address) DEFERRABLE INITIALLY DEFERRED;
---
>     ADD CONSTRAINT debonding_delegations_delegatee_fkey FOREIGN KEY (delegatee) REFERENCES chain.accounts(address) DEFERRABLE INITIALLY DEFERRED;
1777c1776
< -- Name: debonding_delegations debonding_delegations_new_delegator_fkey; Type: FK CONSTRAINT; Schema: chain; Owner: rwuser
---
> -- Name: debonding_delegations debonding_delegations_delegator_fkey; Type: FK CONSTRAINT; Schema: chain; Owner: rwuser
1781c1780
<     ADD CONSTRAINT debonding_delegations_new_delegator_fkey FOREIGN KEY (delegator) REFERENCES chain.accounts(address) DEFERRABLE INITIALLY DEFERRED;
---
>     ADD CONSTRAINT debonding_delegations_delegator_fkey FOREIGN KEY (delegator) REFERENCES chain.accounts(address) DEFERRABLE INITIALLY DEFERRED;

Explanation: This wasn't granted properly before; fixed in this PR
2197a2197,2203
> -- Name: TABLE escrow_events; Type: ACL; Schema: history; Owner: rwuser
> GRANT SELECT ON TABLE history.escrow_events TO PUBLIC;
>
>
> --

@Andrew7234 Andrew7234 requested review from pro-wh and ptrus as code owners July 18, 2024 20:31
CREATE INDEX ix_transactions_tx_hash ON chain.transactions (tx_hash);
--`method` is a possible external API parameter; `block` lets us efficiently retrieve the most recent N txs with a given method.
-- CREATE INDEX ix_transactions_method_block ON chain.transactions (method, block); -- added in 18_consensus_tx_idxs.up.sql
CREATE INDEX ix_transactions_method_height ON chain.transactions (method, block);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have named this index ix_transactions_method_block (as it was here in the comment).

@Andrew7234 Andrew7234 force-pushed the andrew7234/consolidate-migrations branch from 9b592ff to b3ccd5f Compare September 30, 2024 20:34
update ordering of chain.blocks insert

consolidate additional migrations

add changelog

more migrations
@Andrew7234 Andrew7234 force-pushed the andrew7234/consolidate-migrations branch from b3ccd5f to c2d4152 Compare September 30, 2024 20:35
@Andrew7234 Andrew7234 merged commit 834a96f into main Oct 1, 2024
16 checks passed
@Andrew7234 Andrew7234 deleted the andrew7234/consolidate-migrations branch October 1, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants