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

Additional cleanup to support tokens UI #313

Merged
merged 8 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ CREATE TABLE tokenaccount (
balance VARCHAR(65)
);

CREATE UNIQUE INDEX tokenaccount_pool ON tokenaccount(pool_protocol_id,token_index,identity);
CREATE UNIQUE INDEX tokenaccount_pool ON tokenaccount(identity,pool_protocol_id,token_index);

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BEGIN;
DROP INDEX tokenbalance_pool;
DROP INDEX tokentransfer_pool;

ALTER TABLE tokenbalance ADD COLUMN pool_protocol_id VARCHAR(1024);
ALTER TABLE tokentransfer ADD COLUMN pool_protocol_id VARCHAR(1024);

UPDATE tokenbalance SET pool_protocol_id = pool.protocol_id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokenbalance.pool_id = pool.id;

UPDATE tokentransfer SET pool_protocol_id = pool.protocol_id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokentransfer.pool_id = pool.id;

ALTER TABLE tokenbalance DROP COLUMN pool_id;
ALTER TABLE tokentransfer DROP COLUMN pool_id;

ALTER TABLE tokenbalance ALTER COLUMN pool_protocol_id SET NOT NULL;
ALTER TABLE tokentransfer ALTER COLUMN pool_protocol_id SET NOT NULL;

CREATE UNIQUE INDEX tokenaccount_pool ON tokenbalance(key,pool_protocol_id,token_index);
CREATE INDEX tokentransfer_pool ON tokentransfer(pool_protocol_id,token_index);
COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BEGIN;
DROP INDEX tokenaccount_pool;
DROP INDEX tokentransfer_pool;

ALTER TABLE tokenbalance ADD COLUMN pool_id UUID;
ALTER TABLE tokentransfer ADD COLUMN pool_id UUID;

UPDATE tokenbalance SET pool_id = pool.id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokenbalance.pool_protocol_id = pool.protocol_id;

UPDATE tokentransfer SET pool_id = pool.id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokentransfer.pool_protocol_id = pool.protocol_id;

ALTER TABLE tokenbalance DROP COLUMN pool_protocol_id;
ALTER TABLE tokentransfer DROP COLUMN pool_protocol_id;

ALTER TABLE tokenbalance ALTER COLUMN pool_id SET NOT NULL;
ALTER TABLE tokentransfer ALTER COLUMN pool_id SET NOT NULL;

CREATE UNIQUE INDEX tokenbalance_pool ON tokenbalance(key,pool_id,token_index);
CREATE INDEX tokentransfer_pool ON tokentransfer(pool_id,token_index);
COMMIT;
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ CREATE TABLE tokenaccount (
balance VARCHAR(65)
);

CREATE UNIQUE INDEX tokenaccount_pool ON tokenaccount(pool_protocol_id,token_index,identity);
CREATE UNIQUE INDEX tokenaccount_pool ON tokenaccount(identity,pool_protocol_id,token_index);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
DROP INDEX tokenbalance_pool;
DROP INDEX tokentransfer_pool;

ALTER TABLE tokenbalance ADD COLUMN pool_protocol_id VARCHAR(1024);
ALTER TABLE tokentransfer ADD COLUMN pool_protocol_id VARCHAR(1024);

UPDATE tokenbalance SET pool_protocol_id = pool.protocol_id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokenbalance.pool_id = pool.id;

UPDATE tokentransfer SET pool_protocol_id = pool.protocol_id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokentransfer.pool_id = pool.id;

ALTER TABLE tokenbalance DROP COLUMN pool_id;
ALTER TABLE tokentransfer DROP COLUMN pool_id;

CREATE UNIQUE INDEX tokenaccount_pool ON tokenbalance(key,pool_protocol_id,token_index);
CREATE INDEX tokentransfer_pool ON tokentransfer(pool_protocol_id,token_index);
19 changes: 19 additions & 0 deletions db/migrations/sqlite/000043_replace_token_poolprotocolid.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
DROP INDEX tokenaccount_pool;
DROP INDEX tokentransfer_pool;

ALTER TABLE tokenbalance ADD COLUMN pool_id UUID;
ALTER TABLE tokentransfer ADD COLUMN pool_id UUID;

UPDATE tokenbalance SET pool_id = pool.id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokenbalance.pool_protocol_id = pool.protocol_id;

UPDATE tokentransfer SET pool_id = pool.id
FROM (SELECT protocol_id, id FROM tokenpool) AS pool
WHERE tokentransfer.pool_protocol_id = pool.protocol_id;

ALTER TABLE tokenbalance DROP COLUMN pool_protocol_id;
ALTER TABLE tokentransfer DROP COLUMN pool_protocol_id;

CREATE UNIQUE INDEX tokenbalance_pool ON tokenbalance(key,pool_id,token_index);
CREATE INDEX tokentransfer_pool ON tokentransfer(pool_id,token_index);
Loading