diff --git a/db/migrations/00002_create_nodes_table.sql b/db/migrations/00002_create_nodes_table.sql index 909d5789..76db3d71 100644 --- a/db/migrations/00002_create_nodes_table.sql +++ b/db/migrations/00002_create_nodes_table.sql @@ -5,8 +5,7 @@ CREATE TABLE nodes ( genesis_block VARCHAR(66), network_id VARCHAR, node_id VARCHAR(128), - chain_id INTEGER, - CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id, chain_id) + CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id) ); -- +goose Down diff --git a/db/migrations/00012_add_chain_id_to_nodes.sql b/db/migrations/00012_add_chain_id_to_nodes.sql new file mode 100644 index 00000000..50531c4d --- /dev/null +++ b/db/migrations/00012_add_chain_id_to_nodes.sql @@ -0,0 +1,21 @@ +-- +goose Up +ALTER TABLE public.nodes +ADD COLUMN chain_id INTEGER DEFAULT 1; + +ALTER TABLE public.nodes +DROP CONSTRAINT node_uc; + +ALTER TABLE public.nodes +ADD CONSTRAINT node_uc +UNIQUE (genesis_block, network_id, node_id, chain_id); + +-- +goose Down +ALTER TABLE public.nodes +DROP CONSTRAINT node_uc; + +ALTER TABLE public.nodes +ADD CONSTRAINT node_uc +UNIQUE (genesis_block, network_id, node_id); + +ALTER TABLE public.nodes +DROP COLUMN chain_id; \ No newline at end of file