Skip to content

Commit

Permalink
update ddl
Browse files Browse the repository at this point in the history
  • Loading branch information
gclaramunt committed Dec 19, 2024
1 parent 578d2f0 commit ca30d62
Showing 1 changed file with 58 additions and 35 deletions.
93 changes: 58 additions & 35 deletions sql/snapshot.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
-- public.block definition

-- Drop table

-- DROP TABLE block;

CREATE TABLE block (
hash varchar NOT NULL,
height int8 NOT NULL,
parent jsonb NULL,
lock_timestamp timestamp NOT NULL,
snapshot_hash varchar NOT NULL,
snapshot_ordinal int8 NOT NULL,
CONSTRAINT block_pkey PRIMARY KEY (hash)
);


-- public.global_snapshot definition

-- Drop table
Expand Down Expand Up @@ -32,43 +49,18 @@ CREATE TABLE dag_balance_change (
);


-- public.block definition
-- public.dag_block definition

-- Drop table

-- DROP TABLE block;

CREATE TABLE block (
hash varchar NOT NULL,
height int8 NOT NULL,
parent jsonb NULL,
lock_timestamp timestamp NOT NULL,
snapshot_hash varchar NOT NULL,
snapshot_ordinal int8 NOT NULL,
CONSTRAINT block_pkey PRIMARY KEY (hash)
);
-- DROP TABLE dag_block;

CREATE TABLE dag_block (
hash varchar NOT NULL,
CONSTRAINT dag_block_pkey PRIMARY KEY (hash)
);

CREATE TABLE currency_block (
hash varchar NOT NULL,
currency_id int8, -- ?????????????
CONSTRAINT currency_block_pkey PRIMARY KEY (hash)
);


-- public.reward_transaction definition

-- Drop table

-- DROP TABLE reward_transaction;

CREATE TABLE reward_transaction (
destination_tx varchar NOT NULL,
amount int8 NOT NULL
global_snapshot_ordinal int8 NULL,
CONSTRAINT dag_block_pkey PRIMARY KEY (hash),
CONSTRAINT dag_block_block_fk FOREIGN KEY (hash) REFERENCES block(hash),
CONSTRAINT dag_block_global_snapshot_fk FOREIGN KEY (global_snapshot_ordinal) REFERENCES global_snapshot(ordinal)
);


Expand All @@ -91,7 +83,7 @@ CREATE TABLE dag_transaction (
created_at timestamp NULL,
updated_at timestamp NULL,
CONSTRAINT dag_transaction_pkey PRIMARY KEY (hash),
CONSTRAINT dag_transaction_global_snapshot_fk FOREIGN KEY (global_ordinal) REFERENCES global_snapshot(ordinal)
CONSTRAINT dag_transaction_dag_block_fk FOREIGN KEY (block) REFERENCES dag_block(hash)
);


Expand All @@ -104,15 +96,46 @@ CREATE TABLE dag_transaction (
CREATE TABLE metagraph_snapshot (
metagraph_id varchar NOT NULL,
ordinal int8 NOT NULL,
global_ordinal int8 NULL,
global_snapshot_ordinal int8 NULL,
hash varchar NOT NULL,
height int8 NOT NULL,
subheight int8 NOT NULL,
last_snapshot_hash varchar NULL,
created_at timestamp NULL,
updated_at timestamp NULL,
CONSTRAINT metagraph_snapshot_pk PRIMARY KEY (metagraph_id, ordinal),
CONSTRAINT metagraph_snapshot_global_snapshot_fk FOREIGN KEY (ordinal) REFERENCES global_snapshot(ordinal)
CONSTRAINT metagraph_snapshot_global_snapshot_fk FOREIGN KEY (global_snapshot_ordinal) REFERENCES global_snapshot(ordinal)
);


-- public.reward_transaction definition

-- Drop table

-- DROP TABLE reward_transaction;

CREATE TABLE reward_transaction (
destination_tx varchar NOT NULL,
amount int8 NOT NULL,
global_snapshot_ordinal int8 NOT NULL,
CONSTRAINT reward_transaction_pk PRIMARY KEY (destination_tx, amount, global_snapshot_ordinal),
CONSTRAINT reward_transaction_global_snapshot_fk FOREIGN KEY (global_snapshot_ordinal) REFERENCES global_snapshot(ordinal)
);


-- public.metagraph_block definition

-- Drop table

-- DROP TABLE metagraph_block;

CREATE TABLE metagraph_block (
hash varchar NOT NULL,
metagraph_id varchar NULL,
ordinal int8 NULL,
CONSTRAINT currency_block_pkey PRIMARY KEY (hash),
CONSTRAINT currency_block_block_fk FOREIGN KEY (hash) REFERENCES block(hash),
CONSTRAINT currency_block_metagraph_snapshot_fk FOREIGN KEY (metagraph_id,ordinal) REFERENCES metagraph_snapshot(metagraph_id,ordinal)
);


Expand All @@ -136,5 +159,5 @@ CREATE TABLE metagraph_transaction (
updated_at timestamp NULL,
metagraph_ordinal int8 NULL,
CONSTRAINT metagraph_transaction_pkey PRIMARY KEY (hash),
CONSTRAINT metagraph_transaction_metagraph_snapshot_fk FOREIGN KEY (metagraph_id,metagraph_ordinal) REFERENCES metagraph_snapshot(metagraph_id,ordinal)
CONSTRAINT metagraph_transaction_metagraph_block_fk FOREIGN KEY (hash) REFERENCES metagraph_block(hash)
);

0 comments on commit ca30d62

Please sign in to comment.