From b9f06d16adec10f87c4096816143487448078fbd Mon Sep 17 00:00:00 2001 From: santi1234567 <45318759+santi1234567@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:45:19 -0300 Subject: [PATCH] change t_withdrawals to order by index --- ...00008_modify_order_by_withdrawals.down.sql | 20 +++++++++++++++++++ .../000008_modify_order_by_withdrawals.up.sql | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 pkg/db/migrations/000008_modify_order_by_withdrawals.down.sql create mode 100644 pkg/db/migrations/000008_modify_order_by_withdrawals.up.sql diff --git a/pkg/db/migrations/000008_modify_order_by_withdrawals.down.sql b/pkg/db/migrations/000008_modify_order_by_withdrawals.down.sql new file mode 100644 index 00000000..5189cbd9 --- /dev/null +++ b/pkg/db/migrations/000008_modify_order_by_withdrawals.down.sql @@ -0,0 +1,20 @@ +-- Create new table with desired order by +CREATE TABLE new_t_withdrawals( + f_slot UInt64, + f_index UInt64, + f_val_idx UInt64, + f_address TEXT, + f_amount UInt64) + ENGINE = ReplacingMergeTree() + ORDER BY (f_slot); + +-- Populate new table +INSERT INTO new_t_withdrawals +SELECT * FROM t_withdrawals; + +-- Rename tables +RENAME TABLE t_withdrawals TO t_withdrawals_old; +RENAME TABLE new_t_withdrawals TO t_withdrawals; + +-- Drop temporary table +DROP TABLE t_withdrawals_old; \ No newline at end of file diff --git a/pkg/db/migrations/000008_modify_order_by_withdrawals.up.sql b/pkg/db/migrations/000008_modify_order_by_withdrawals.up.sql new file mode 100644 index 00000000..88130898 --- /dev/null +++ b/pkg/db/migrations/000008_modify_order_by_withdrawals.up.sql @@ -0,0 +1,20 @@ +-- Create new table with desired order by +CREATE TABLE new_t_withdrawals( + f_slot UInt64, + f_index UInt64, + f_val_idx UInt64, + f_address TEXT, + f_amount UInt64) + ENGINE = ReplacingMergeTree() + ORDER BY (f_index); + +-- Populate new table +INSERT INTO new_t_withdrawals +SELECT * FROM t_withdrawals; + +-- Rename tables +RENAME TABLE t_withdrawals TO t_withdrawals_old; +RENAME TABLE new_t_withdrawals TO t_withdrawals; + +-- Drop temporary table +DROP TABLE t_withdrawals_old; \ No newline at end of file