Skip to content

Commit

Permalink
chore(v1): add missing migrations (#2986)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Pfeiffer <[email protected]>
  • Loading branch information
guybrush and guybrush authored Dec 10, 2024
1 parent 1b94cbd commit cd9220f
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 3 deletions.
18 changes: 18 additions & 0 deletions db/migrations/20240527142321_consensus_rewards.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- +goose Up
-- +goose StatementBegin
SELECT('up SQL query - create consensus_payloads table');
CREATE TABLE consensus_payloads (
slot BIGINT,
cl_attestations_reward BIGINT, -- gwei
cl_sync_aggregate_reward BIGINT, -- gwei
cl_slashing_inclusion_reward BIGINT, -- gwei
CONSTRAINT consensus_payloads_pk PRIMARY KEY (slot)
);

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
SELECT('down SQL query - drop consensus_payloads table');
DROP TABLE consensus_payloads;
-- +goose StatementEnd
6 changes: 3 additions & 3 deletions db/migrations/20240723105539_add_ratelimit_buckets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ ALTER TABLE api_statistics DROP CONSTRAINT api_statistics_pkey, ADD PRIMARY KEY
-- +goose Down
-- +goose StatementBegin
SELECT('down SQL query - update api_products');
ALTER TABLE api_products DROP COLUMN IF EXISTS bucket;
ALTER TABLE api_products DROP CONSTRAINT api_products_pkey, ADD PRIMARY KEY (name, valid_from);
ALTER TABLE api_products DROP COLUMN IF EXISTS bucket;
SELECT('down SQL query - update api_ratelimits');
ALTER TABLE api_ratelimits DROP COLUMN IF EXISTS bucket;
ALTER TABLE api_ratelimits DROP CONSTRAINT api_ratelimits_pkey, ADD PRIMARY KEY (user_id);
ALTER TABLE api_ratelimits DROP COLUMN IF EXISTS bucket;
SELECT('down SQL query - update api_statistics');
ALTER TABLE api_statistics DROP COLUMN IF EXISTS bucket;
ALTER TABLE api_statistics DROP CONSTRAINT api_statistics_pkey, ADD PRIMARY KEY (ts, apikey, endpoint);
ALTER TABLE api_statistics DROP COLUMN IF EXISTS bucket;
-- +goose StatementEnd
152 changes: 152 additions & 0 deletions db/migrations/20240820111812_add_v2_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
-- +goose Up
-- Validator Dashboard

-- +goose StatementBegin
SELECT 'create users_val_dashboards table';
CREATE TABLE IF NOT EXISTS users_val_dashboards (
id BIGSERIAL NOT NULL,
user_id BIGINT NOT NULL,
network SMALLINT NOT NULL, -- indicate gnosis/eth mainnet and potentially testnets
name VARCHAR(50) NOT NULL,
created_at TIMESTAMP DEFAULT(NOW()),
is_archived TEXT,
primary key (id)
);
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'create users_val_dashboards_groups table';
CREATE TABLE IF NOT EXISTS users_val_dashboards_groups (
id SMALLINT DEFAULT(0),
dashboard_id BIGINT NOT NULL,
name VARCHAR(50) NOT NULL,
foreign key (dashboard_id) references users_val_dashboards(id) ON DELETE CASCADE,
primary key (dashboard_id, id)
);
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'create users_val_dashboards_validators table';
CREATE TABLE IF NOT EXISTS users_val_dashboards_validators ( -- a validator must not be in multiple groups
dashboard_id BIGINT NOT NULL,
group_id SMALLINT NOT NULL,
validator_index BIGINT NOT NULL,
foreign key (dashboard_id, group_id) references users_val_dashboards_groups(dashboard_id, id) ON DELETE CASCADE,
primary key (dashboard_id, validator_index)
);
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'create users_val_dashboards_sharing table';
CREATE TABLE IF NOT EXISTS users_val_dashboards_sharing (
dashboard_id BIGINT NOT NULL,
public_id CHAR(38) DEFAULT ('v-' || gen_random_uuid()::text) UNIQUE, -- prefix with "v" for validator dashboards. Public ID to dashboard
name VARCHAR(50) NOT NULL,
shared_groups bool NOT NULL, -- all groups or default 0
foreign key (dashboard_id) references users_val_dashboards(id) ON DELETE CASCADE,
primary key (public_id)
);
-- +goose StatementEnd

-- Account Dashboard

-- +goose StatementBegin
SELECT 'create users_val_dashboards_groups table';
CREATE TABLE IF NOT EXISTS users_acc_dashboards (
id BIGSERIAL NOT NULL,
user_id BIGINT NOT NULL,
name VARCHAR(50) NOT NULL,
user_settings JSONB DEFAULT '{}'::jsonb, -- or do we want to use a separate kv table for this?
created_at TIMESTAMP DEFAULT(NOW()),
primary key (id)
);
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'create users_val_dashboards_groups table';
CREATE TABLE IF NOT EXISTS users_acc_dashboards_groups (
id INT NOT NULL,
dashboard_id BIGINT NOT NULL,
name VARCHAR(50) NOT NULL,
foreign key (dashboard_id) references users_acc_dashboards(id) ON DELETE CASCADE,
primary key (dashboard_id, id)
);
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'create users_val_dashboards_groups table';
CREATE TABLE IF NOT EXISTS users_acc_dashboards_accounts ( -- an account must not be in multiple groups
dashboard_id BIGINT NOT NULL,
group_id SMALLINT NOT NULL,
address BYTEA NOT NULL,
foreign key (dashboard_id, group_id) references users_acc_dashboards_groups(dashboard_id, id) ON DELETE CASCADE,
primary key (dashboard_id, address)
);
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'create users_val_dashboards_groups table';
CREATE TABLE IF NOT EXISTS users_acc_dashboards_sharing (
dashboard_id BIGINT NOT NULL,
public_id CHAR(38) DEFAULT('a-' || gen_random_uuid()::text) UNIQUE, -- prefix with "a" for validator dashboards
name VARCHAR(50) NOT NULL,
user_settings JSONB DEFAULT '{}'::jsonb, -- snapshots users_dashboards.user_settings at the time of creating the share
shared_groups bool NOT NULL, -- all groups or default 0
tx_notes_shared BOOLEAN NOT NULL, -- not snapshoted
foreign key (dashboard_id) references users_acc_dashboards(id) ON DELETE CASCADE,
primary key (public_id)
);
-- +goose StatementEnd

-- Notification Dashboard (wip)

-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS users_not_dashboards (
id BIGINT,
user_id BIGINT,
name VARCHAR(50) NOT NULL,
created_at timestamp,
primary key (id)
);
-- +goose StatementEnd


-- +goose Down
-- +goose StatementBegin
SELECT 'delete users_val_dashboards_validators table';
DROP TABLE IF EXISTS users_val_dashboards_validators;
-- +goose StatementEnd
-- +goose StatementBegin
SELECT 'delete users_val_dashboards_groups table';
DROP TABLE IF EXISTS users_val_dashboards_groups;
-- +goose StatementEnd
-- +goose StatementBegin
SELECT 'delete users_val_dashboards_sharing table';
DROP TABLE IF EXISTS users_val_dashboards_sharing;
-- +goose StatementEnd
-- +goose StatementBegin
SELECT 'delete users_val_dashboards table';
DROP TABLE IF EXISTS users_val_dashboards;
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'delete users_acc_dashboards_accounts table';
DROP TABLE IF EXISTS users_acc_dashboards_accounts;
-- +goose StatementEnd
-- +goose StatementBegin
SELECT 'delete users_acc_dashboards_groups table';
DROP TABLE IF EXISTS users_acc_dashboards_groups;
-- +goose StatementEnd
-- +goose StatementBegin
SELECT 'delete users_acc_dashboards_sharing table';
DROP TABLE IF EXISTS users_acc_dashboards_sharing;
-- +goose StatementEnd
-- +goose StatementBegin
SELECT 'delete users_acc_dashboards table';
DROP TABLE IF EXISTS users_acc_dashboards;
-- +goose StatementEnd

-- +goose StatementBegin
SELECT 'delete users_not_dashboards table';
DROP TABLE IF EXISTS users_not_dashboards;
-- +goose StatementEnd
11 changes: 11 additions & 0 deletions db/migrations/20240820141500_is_archived.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query - add is_archived column';
ALTER TABLE users_val_dashboards ADD COLUMN IF NOT EXISTS is_archived TEXT;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query - drop is_archived column';
ALTER TABLE users_val_dashboards DROP COLUMN IF EXISTS is_archived;
-- +goose StatementEnd
15 changes: 15 additions & 0 deletions db/migrations/20240822134034_add_address_tags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- +goose Up
-- +goose StatementBegin
SELECT('up SQL query - create address_names table');
CREATE TABLE IF NOT EXISTS address_names (
address bytea NOT NULL UNIQUE,
name TEXT NOT NULL,
PRIMARY KEY (address, name)
);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
SELECT('down SQL query - drop address_names table');
DROP TABLE IF EXISTS address_names;
-- +goose StatementEnd

0 comments on commit cd9220f

Please sign in to comment.