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

feat: cache / expire uAgent almanac resolutions #198

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add resolutions migration
  • Loading branch information
bryanchriswhite committed Dec 22, 2022
commit 6dbb344f7d975b3ae3c1d97e98dbd9c8a4cd3183
98 changes: 98 additions & 0 deletions migrations/committed/000010.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
--! Previous: sha1:914d20d8e81f79b1e98e114302e6e48534463c27
--! Hash: sha1:12fcbbff828973e1619ec9fee35008f99e747cf2

CREATE SCHEMA IF NOT EXISTS app;
SET SCHEMA 'app';

ALTER TABLE IF EXISTS ONLY app.almanac_resolutions DROP CONSTRAINT IF EXISTS almanac_resolutions_record_id_fkey;
ALTER TABLE IF EXISTS ONLY app.almanac_resolutions DROP CONSTRAINT IF EXISTS almanac_resolutions_contract_id_fkey;
ALTER TABLE IF EXISTS ONLY app.almanac_resolutions DROP CONSTRAINT IF EXISTS almanac_resolutions_agent_id_fkey;
DROP INDEX IF EXISTS app.almanac_resolutions_record_id;
DROP INDEX IF EXISTS app.almanac_resolutions_contract_id;
DROP INDEX IF EXISTS app.almanac_resolutions_agent_id;
ALTER TABLE IF EXISTS ONLY app.almanac_resolutions DROP CONSTRAINT IF EXISTS almanac_resolutions_pkey;
DROP TABLE IF EXISTS app.almanac_resolutions;
SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: almanac_resolutions; Type: TABLE; Schema: app; Owner: subquery
--

CREATE TABLE app.almanac_resolutions (
id text NOT NULL,
agent_id text NOT NULL,
contract_id text NOT NULL,
record_id text NOT NULL
);


ALTER TABLE app.almanac_resolutions OWNER TO subquery;

--
-- Name: almanac_resolutions almanac_resolutions_pkey; Type: CONSTRAINT; Schema: app; Owner: subquery
--

ALTER TABLE ONLY app.almanac_resolutions
ADD CONSTRAINT almanac_resolutions_pkey PRIMARY KEY (id);


--
-- Name: almanac_resolutions_agent_id; Type: INDEX; Schema: app; Owner: subquery
--

CREATE INDEX almanac_resolutions_agent_id ON app.almanac_resolutions USING hash (agent_id);


--
-- Name: almanac_resolutions_contract_id; Type: INDEX; Schema: app; Owner: subquery
--

CREATE INDEX almanac_resolutions_contract_id ON app.almanac_resolutions USING hash (contract_id);


--
-- Name: almanac_resolutions_record_id; Type: INDEX; Schema: app; Owner: subquery
--

CREATE INDEX almanac_resolutions_record_id ON app.almanac_resolutions USING hash (record_id);


--
-- Name: almanac_resolutions almanac_resolutions_agent_id_fkey; Type: FK CONSTRAINT; Schema: app; Owner: subquery
--

ALTER TABLE ONLY app.almanac_resolutions
ADD CONSTRAINT almanac_resolutions_agent_id_fkey FOREIGN KEY (agent_id) REFERENCES app.agents(id) ON UPDATE CASCADE;


--
-- Name: almanac_resolutions almanac_resolutions_contract_id_fkey; Type: FK CONSTRAINT; Schema: app; Owner: subquery
--

ALTER TABLE ONLY app.almanac_resolutions
ADD CONSTRAINT almanac_resolutions_contract_id_fkey FOREIGN KEY (contract_id) REFERENCES app.contracts(id) ON UPDATE CASCADE;


--
-- Name: almanac_resolutions almanac_resolutions_record_id_fkey; Type: FK CONSTRAINT; Schema: app; Owner: subquery
--

ALTER TABLE ONLY app.almanac_resolutions
ADD CONSTRAINT almanac_resolutions_record_id_fkey FOREIGN KEY (record_id) REFERENCES app.almanac_records(id) ON UPDATE CASCADE;


--
-- PostgreSQL database dump complete
--


INSERT INTO app.almanac_resolutions (id, agent_id, contract_id, record_id)
SELECT reg.id, reg.agent_id, reg.contract_id, reg.record_id
FROM app.almanac_registrations reg
WHERE reg.expiry_height > (
SELECT b.height FROM app.blocks b
ORDER BY b.height
LIMIT 1
);