From 18359139e198c5d9b48060b83e95f03051cbddf0 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Fri, 29 Apr 2022 11:02:03 +0300 Subject: [PATCH] fix: migration - add cursor descriptions - enable search extension on indexes --- migrations/002_cic_dw_tables.sql | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/migrations/002_cic_dw_tables.sql b/migrations/002_cic_dw_tables.sql index dc6d3ca..8e2952f 100644 --- a/migrations/002_cic_dw_tables.sql +++ b/migrations/002_cic_dw_tables.sql @@ -56,15 +56,16 @@ CREATE TABLE IF NOT EXISTS meta ( tags TEXT[] ); -CREATE INDEX IF NOT EXISTS tags ON meta USING gin(tags); -CREATE INDEX IF NOT EXISTS location_name_idx ON meta USING gin(location_name); -CREATE INDEX IF NOT EXISTS products_idx ON meta USING gin(location_name); +CREATE INDEX IF NOT EXISTS tags ON meta USING gin(tags gin_trgm_ops); +CREATE INDEX IF NOT EXISTS location_name_idx ON meta USING gin(location_name gin_trgm_ops); +CREATE INDEX IF NOT EXISTS products_idx ON meta USING gin(location_name gin_trgm_ops); CREATE INDEX IF NOT EXISTS meta_filter_idx ON meta(gender, preferred_language, age); -- cursors table (for internal syncing) CREATE TABLE IF NOT EXISTS cursors ( - id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - cursor_pos VARCHAR(64) NOT NULL + id INT PRIMARY KEY, + cursor_pos VARCHAR(64) NOT NULL, + cursor_description VARCHAR(100) ); -- bootstrap first users row @@ -72,9 +73,9 @@ INSERT INTO users (phone_number, blockchain_address, date_registered) SELECT phone_number, blockchain_address, created FROM cic_ussd.account WHERE id = 1; --- idx 1 = cic_ussd cursor -INSERT INTO cursors (cursor_pos) -SELECT blockchain_address FROM users ORDER BY id DESC LIMIT 1; +-- id 1 = cic_ussd cursor +INSERT INTO cursors (id, cursor_pos) +SELECT 1, blockchain_address FROM users ORDER BY id DESC LIMIT 1; -- bootstrap first tx row INSERT INTO transactions (tx_hash, block_number, tx_index, token_address, sender_address, recipient_address, tx_value, date_block, tx_type) @@ -84,6 +85,14 @@ INNER JOIN cic_cache.tag_tx_link ON tx.id = cic_cache.tag_tx_link.tx_id INNER JOIN cic_cache.tag ON cic_cache.tag_tx_link.tag_id = cic_cache.tag.id WHERE tx.success = true AND tx.id = 1; --- idx 2 = cic_cache cursor -INSERT INTO cursors (cursor_pos) -SELECT tx_hash FROM transactions ORDER BY id DESC LIMIT 1; +-- id 2 = cic_cache cursor +INSERT INTO cursors (id,cursor_pos) +SELECT 2, tx_hash FROM transactions ORDER BY id DESC LIMIT 1; + +-- id 3 = kitabu.erc20_token_index cursor +INSERT INTO cursors (cursor_pos) VALUES +(3, 0, 'kitabu.erc20_token_index contract entry idx'); + +-- cursor descriptions +UPDATE cursors SET cursor_description = 'cic_ussd.account.block_chain_address remote cursor' WHERE id = 1; +UPDATE cursors SET cursor_description = 'cic_cache.tx.tx_hash remote cursor' WHERE id = 2;