Skip to content

Commit 8cfc9c7

Browse files
committed
Add database schema
1 parent ffc4025 commit 8cfc9c7

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

backend-rust/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ cargo run --bin ccdscan-api
5555
### GraphiQL IDE
5656

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

60-
An examples is shown below:
60+
An example is shown below:
6161

6262
Query:
6363

backend-rust/migrations/0001_initialize.up.sql

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ CREATE TABLE transactions(
158158
BOOLEAN
159159
NOT NULL,
160160
-- Transaction details. Events if success is true.
161+
-- 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.
161162
events
162163
JSONB,
163164
-- Transaction details. Reject reason if success is false.
@@ -249,6 +250,7 @@ CREATE TABLE bakers(
249250

250251
-- Every WASM module on chain.
251252
CREATE TABLE smart_contract_modules(
253+
-- Index/id of the module (row number).
252254
index
253255
BIGINT
254256
PRIMARY KEY,
@@ -305,6 +307,100 @@ CREATE TABLE contracts(
305307
PRIMARY KEY (index, sub_index)
306308
);
307309

310+
-- Every event that links or unlinks a contract to a module.
311+
CREATE TABLE module_contract_link_events(
312+
-- An index/id for this event (row number).
313+
index
314+
BIGINT
315+
SERIAL
316+
PRIMARY KEY
317+
NOT NULL,
318+
-- Event index of the event.
319+
event_index
320+
BIGINT
321+
NOT NULL,
322+
-- Transaction index including the event.
323+
transaction_index
324+
BIGINT
325+
NOT NULL,
326+
-- Module index that gets linked/unlinked.
327+
module_index
328+
BIGINT
329+
NOT NULL,
330+
-- Contract index that gets linked/unlinked.
331+
contract_index
332+
BIGINT
333+
NOT NULL,
334+
-- Contract subindex that gets linked/unlinked.
335+
contract_sub_index
336+
BIGINT
337+
NOT NULL,
338+
-- True if contract gets linked to the given module, false if contract gets unlinked to the given module.
339+
is_linked
340+
BOOLEAN
341+
NOT NULL,
342+
343+
-- TODO: link_action = int? source = int?
344+
)
345+
346+
-- Every successful event associated to a contract.
347+
-- TODO: add index over the contract (index,subindex)
348+
CREATE TABLE contract_events(
349+
-- An index/id for this event (row number).
350+
index
351+
BIGINT
352+
SERIAL
353+
PRIMARY KEY
354+
NOT NULL,
355+
-- Transaction index including the event.
356+
transaction_index
357+
BIGINT
358+
NOT NULL,
359+
-- Event index of the event.
360+
event_index
361+
BIGINT
362+
NOT NULL,
363+
-- Contract index that event is associated with.
364+
contract_index
365+
BIGINT
366+
NOT NULL,
367+
-- Contract subindex that event is associated with.
368+
contract_sub_index
369+
BIGINT
370+
NOT NULL,
371+
372+
-- TODO: source = int?
373+
)
374+
375+
-- Every rejected event associated to a contract.
376+
-- TODO: add index over the contract (index,subindex)
377+
CREATE TABLE contract_reject_events(
378+
-- An index/id for this event (row number).
379+
index
380+
BIGINT
381+
SERIAL
382+
PRIMARY KEY
383+
NOT NULL,
384+
-- Transaction index including the event.
385+
transaction_index
386+
BIGINT
387+
NOT NULL,
388+
-- Event index of the event.
389+
event_index
390+
BIGINT
391+
NOT NULL,
392+
-- Contract index that event is associated with.
393+
contract_index
394+
BIGINT
395+
NOT NULL,
396+
-- Contract subindex that event is associated with.
397+
contract_sub_index
398+
BIGINT
399+
NOT NULL,
400+
401+
-- TODO: source = int?
402+
)
403+
308404
CREATE OR REPLACE FUNCTION block_added_notify_trigger_function() RETURNS trigger AS $trigger$
309405
DECLARE
310406
rec blocks;

0 commit comments

Comments
 (0)