-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundles): add bundle/data item GQL index schema PE-3769
Adds the DB schema required for indexing data items for GraphQL querying. Also includes a table for tracking bundle status (processed_at + data_item_count). Bundles use a separate SQLite DB (similar to data) to reduce lock contention and support greater bootstrapping flexibility.
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
CREATE TABLE IF NOT EXISTS bundle_formats ( | ||
id INTEGER PRIMARY KEY, | ||
name TEXT NOT NULL | ||
); | ||
|
||
INSERT INTO bundle_formats (id, name) VALUES (0, 'ans-102'); | ||
INSERT INTO bundle_formats (id, name) VALUES (1, 'ans-104'); | ||
|
||
CREATE TABLE IF NOT EXISTS bundles ( | ||
id BLOB PRIMARY KEY, | ||
format INTEGER NOT NULL, | ||
data_item_count INTEGER NOT NULL, | ||
first_processed_at INTEGER NOT NULL, | ||
last_processed_at INTEGER NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS bundle_data_items ( | ||
id BLOB, | ||
parent_id BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (id, parent_id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS wallets ( | ||
address BLOB PRIMARY KEY, | ||
public_modulus BLOB | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS stable_data_items ( | ||
-- Identity | ||
id BLOB NOT NULL, | ||
parent_id BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
height INTEGER NOT NULL, | ||
block_transaction_index INTEGER NOT NULL, | ||
signature BLOB NOT NULL, | ||
anchor BLOB NOT NULL, | ||
|
||
-- Ownership | ||
owner_address BLOB NOT NULL, | ||
target BLOB, | ||
|
||
-- Data | ||
data_offset INTEGER NOT NULL, | ||
data_size INTEGER NOT NULL, | ||
content_type TEXT, | ||
|
||
-- Metadata | ||
tag_count INTEGER NOT NULL, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS stable_data_items_height_block_transaction_index_id_idx ON stable_data_items (height, block_transaction_index, id); | ||
CREATE INDEX IF NOT EXISTS stable_data_items_target_height_block_transaction_index_id_idx ON stable_data_items (target, height, block_transaction_index, id); | ||
CREATE INDEX IF NOT EXISTS stable_data_items_owner_address_height_block_transaction_index_id_idx ON stable_data_items (owner_address, height, block_transaction_index, id); | ||
CREATE INDEX IF NOT EXISTS stable_data_items_parent_id_height_block_transaction_index_id_idx ON stable_data_items (parent_id, height, block_transaction_index, id); | ||
|
||
CREATE TABLE IF NOT EXISTS tag_names ( | ||
hash BLOB PRIMARY KEY, | ||
name BLOB NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS tag_values ( | ||
hash BLOB PRIMARY KEY, | ||
value BLOB NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS stable_data_item_tags ( | ||
tag_name_hash BLOB NOT NULL, | ||
tag_value_hash BLOB NOT NULL, | ||
height INTEGER NOT NULL, | ||
block_transaction_index INTEGER NOT NULL, | ||
data_item_tag_index INTEGER NOT NULL, | ||
data_item_id BLOB NOT NULL, | ||
parent_id BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
PRIMARY KEY (tag_name_hash, tag_value_hash, height, block_transaction_index, data_item_id, data_item_tag_index) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS stable_data_item_tags_transaction_id_idx ON stable_data_item_tags (data_item_id); | ||
|
||
CREATE TABLE IF NOT EXISTS new_data_items ( | ||
-- Identity | ||
id BLOB NOT NULL, | ||
parent_id BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
height INTEGER, | ||
signature BLOB NOT NULL, | ||
anchor BLOB NOT NULL, | ||
|
||
-- Ownership | ||
owner_address BLOB NOT NULL, | ||
target BLOB, | ||
|
||
-- Data | ||
data_offset INTEGER NOT NULL, | ||
data_size INTEGER NOT NULL, | ||
content_type TEXT, | ||
|
||
-- Metadata | ||
tag_count INTEGER NOT NULL, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS new_data_items_parent_id_id_idx ON new_data_items (parent_id, id); | ||
CREATE INDEX IF NOT EXISTS new_data_items_root_transaction_id_id_idx ON new_data_items (root_transaction_id, id); | ||
CREATE INDEX IF NOT EXISTS new_data_items_target_id_idx ON new_data_items (target, id); | ||
CREATE INDEX IF NOT EXISTS new_data_items_owner_address_id_idx ON new_data_items (owner_address, id); | ||
CREATE INDEX IF NOT EXISTS new_data_items_height_indexed_at_idx ON new_data_items (height, indexed_at); | ||
|
||
CREATE TABLE IF NOT EXISTS new_data_item_tags ( | ||
tag_name_hash BLOB NOT NULL, | ||
tag_value_hash BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
data_item_id BLOB NOT NULL, | ||
data_item_tag_index INTEGER NOT NULL, | ||
height INTEGER, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (tag_name_hash, tag_value_hash, root_transaction_id, data_item_id, data_item_tag_index) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS new_data_item_tags_height_indexed_at_idx ON new_data_item_tags (height, indexed_at); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
DROP TABLE IF EXISTS new_data_item_tags; | ||
DROP TABLE IF EXISTS new_data_items; | ||
DROP TABLE IF EXISTS stable_data_item_tags; | ||
DROP TABLE IF EXISTS tag_values; | ||
DROP TABLE IF EXISTS tag_names; | ||
DROP TABLE IF EXISTS stable_data_items; | ||
DROP TABLE IF EXISTS wallets; | ||
DROP TABLE IF EXISTS bundles; | ||
DROP TABLE IF EXISTS bundle_formats; |