Skip to content

Commit

Permalink
Add database schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Oct 15, 2024
1 parent ffc4025 commit 8cfc9c7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend-rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ cargo run --bin ccdscan-api
### GraphiQL IDE

Starting the GraphQL API Service above will provide you an interface
(usually at 127.0.0.1:8000) to execute graphQL querries.
(usually at 127.0.0.1:8000) to execute graphQL queries.

An examples is shown below:
An example is shown below:

Query:

Expand Down
96 changes: 96 additions & 0 deletions backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ CREATE TABLE transactions(
BOOLEAN
NOT NULL,
-- Transaction details. Events if success is true.
-- TODO: It would be nice to have every event in a separate row in a table to easily query a specific event from a specific transaction.
events
JSONB,
-- Transaction details. Reject reason if success is false.
Expand Down Expand Up @@ -249,6 +250,7 @@ CREATE TABLE bakers(

-- Every WASM module on chain.
CREATE TABLE smart_contract_modules(
-- Index/id of the module (row number).
index
BIGINT
PRIMARY KEY,
Expand Down Expand Up @@ -305,6 +307,100 @@ CREATE TABLE contracts(
PRIMARY KEY (index, sub_index)
);

-- Every event that links or unlinks a contract to a module.
CREATE TABLE module_contract_link_events(
-- An index/id for this event (row number).
index
BIGINT
SERIAL
PRIMARY KEY
NOT NULL,
-- Event index of the event.
event_index
BIGINT
NOT NULL,
-- Transaction index including the event.
transaction_index
BIGINT
NOT NULL,
-- Module index that gets linked/unlinked.
module_index
BIGINT
NOT NULL,
-- Contract index that gets linked/unlinked.
contract_index
BIGINT
NOT NULL,
-- Contract subindex that gets linked/unlinked.
contract_sub_index
BIGINT
NOT NULL,
-- True if contract gets linked to the given module, false if contract gets unlinked to the given module.
is_linked
BOOLEAN
NOT NULL,

-- TODO: link_action = int? source = int?
)

-- Every successful event associated to a contract.
-- TODO: add index over the contract (index,subindex)
CREATE TABLE contract_events(
-- An index/id for this event (row number).
index
BIGINT
SERIAL
PRIMARY KEY
NOT NULL,
-- Transaction index including the event.
transaction_index
BIGINT
NOT NULL,
-- Event index of the event.
event_index
BIGINT
NOT NULL,
-- Contract index that event is associated with.
contract_index
BIGINT
NOT NULL,
-- Contract subindex that event is associated with.
contract_sub_index
BIGINT
NOT NULL,

-- TODO: source = int?
)

-- Every rejected event associated to a contract.
-- TODO: add index over the contract (index,subindex)
CREATE TABLE contract_reject_events(
-- An index/id for this event (row number).
index
BIGINT
SERIAL
PRIMARY KEY
NOT NULL,
-- Transaction index including the event.
transaction_index
BIGINT
NOT NULL,
-- Event index of the event.
event_index
BIGINT
NOT NULL,
-- Contract index that event is associated with.
contract_index
BIGINT
NOT NULL,
-- Contract subindex that event is associated with.
contract_sub_index
BIGINT
NOT NULL,

-- TODO: source = int?
)

CREATE OR REPLACE FUNCTION block_added_notify_trigger_function() RETURNS trigger AS $trigger$
DECLARE
rec blocks;
Expand Down

0 comments on commit 8cfc9c7

Please sign in to comment.