From 802cfe71802708a2101aaa6de2fcdbccf5f459e1 Mon Sep 17 00:00:00 2001 From: i-norden Date: Fri, 17 Feb 2023 14:26:21 -0600 Subject: [PATCH] consolidate version migrations; reorder --- ...ersion_table.sql => 00014_create_db_version_table.sql} | 3 +++ ...h_meta_schema.sql => 00015_create_eth_meta_schema.sql} | 0 ...table.sql => 00016_create_watched_addresses_table.sql} | 0 ...ed_functions.sql => 00017_create_stored_functions.sql} | 0 ...o_hypertables.sql => 00018_convert_to_hypertables.sql} | 8 ++++---- db/migrations/00022_update_db_version.sql | 6 ------ 6 files changed, 7 insertions(+), 10 deletions(-) rename db/migrations/{00016_create_db_version_table.sql => 00014_create_db_version_table.sql} (62%) rename db/migrations/{00017_create_eth_meta_schema.sql => 00015_create_eth_meta_schema.sql} (100%) rename db/migrations/{00018_create_watched_addresses_table.sql => 00016_create_watched_addresses_table.sql} (100%) rename db/migrations/{00020_create_stored_functions.sql => 00017_create_stored_functions.sql} (100%) rename db/migrations/{00019_convert_to_hypertables.sql => 00018_convert_to_hypertables.sql} (98%) delete mode 100644 db/migrations/00022_update_db_version.sql diff --git a/db/migrations/00016_create_db_version_table.sql b/db/migrations/00014_create_db_version_table.sql similarity index 62% rename from db/migrations/00016_create_db_version_table.sql rename to db/migrations/00014_create_db_version_table.sql index 2cf57e9..10bcb20 100644 --- a/db/migrations/00016_create_db_version_table.sql +++ b/db/migrations/00014_create_db_version_table.sql @@ -5,5 +5,8 @@ CREATE TABLE IF NOT EXISTS public.db_version ( tstamp TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() ); +INSERT INTO public.db_version (singleton, version) VALUES (true, 'v5.0.0') + ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v5.0.0', NOW()); + -- +goose Down DROP TABLE public.db_version; diff --git a/db/migrations/00017_create_eth_meta_schema.sql b/db/migrations/00015_create_eth_meta_schema.sql similarity index 100% rename from db/migrations/00017_create_eth_meta_schema.sql rename to db/migrations/00015_create_eth_meta_schema.sql diff --git a/db/migrations/00018_create_watched_addresses_table.sql b/db/migrations/00016_create_watched_addresses_table.sql similarity index 100% rename from db/migrations/00018_create_watched_addresses_table.sql rename to db/migrations/00016_create_watched_addresses_table.sql diff --git a/db/migrations/00020_create_stored_functions.sql b/db/migrations/00017_create_stored_functions.sql similarity index 100% rename from db/migrations/00020_create_stored_functions.sql rename to db/migrations/00017_create_stored_functions.sql diff --git a/db/migrations/00019_convert_to_hypertables.sql b/db/migrations/00018_convert_to_hypertables.sql similarity index 98% rename from db/migrations/00019_convert_to_hypertables.sql rename to db/migrations/00018_convert_to_hypertables.sql index 4040450..eef0cb1 100644 --- a/db/migrations/00019_convert_to_hypertables.sql +++ b/db/migrations/00018_convert_to_hypertables.sql @@ -10,12 +10,12 @@ SELECT create_hypertable('eth.access_list_elements', 'block_number', migrate_dat SELECT create_hypertable('eth.log_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768); -- update version -INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.0-h') - ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v4.0.0-h', NOW()); +INSERT INTO public.db_version (singleton, version) VALUES (true, 'v5.0.0-h') + ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v5.0.0-h', NOW()); -- +goose Down -INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.0') - ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v4.0.0', NOW()); +INSERT INTO public.db_version (singleton, version) VALUES (true, 'v5.0.0') + ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v5.0.0', NOW()); -- reversing conversion to hypertable requires migrating all data from every chunk back to a single table -- create new regular tables diff --git a/db/migrations/00022_update_db_version.sql b/db/migrations/00022_update_db_version.sql deleted file mode 100644 index 918822e..0000000 --- a/db/migrations/00022_update_db_version.sql +++ /dev/null @@ -1,6 +0,0 @@ --- +goose Up -INSERT INTO public.db_version (singleton, version) VALUES (true, 'v5.0.0') -ON CONFLICT (singleton) DO UPDATE SET (version, tstamp) = ('v5.0.0', NOW()); - --- +goose Down -DELETE FROM public.db_version WHERE version = 'v5.0.0';