diff --git a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-06-30-121000-initialize-tables/up.sql b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-06-30-121000-initialize-tables/up.sql deleted file mode 100644 index 7cca2187..00000000 --- a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-06-30-121000-initialize-tables/up.sql +++ /dev/null @@ -1,59 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -CREATE TABLE IF NOT EXISTS merkle_radix_tree ( - id BIGSERIAL PRIMARY KEY, - name VARCHAR(512), - UNIQUE(name) -); - -INSERT INTO merkle_radix_tree (name) VALUES ('default'); - -CREATE TABLE IF NOT EXISTS merkle_radix_leaf ( - id BIGSERIAL PRIMARY KEY, - tree_id BIGINT NOT NULL, - address VARCHAR(70) NOT NULL, - data BYTEA, - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) -); - -CREATE TABLE IF NOT EXISTS merkle_radix_tree_node ( - hash VARCHAR(64) NOT NULL, - tree_id BIGINT NOT NULL, - leaf_id BIGINT, - children VARCHAR(64)[], - PRIMARY KEY (hash, tree_id), - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf(id) -); - -CREATE TABLE IF NOT EXISTS merkle_radix_state_root ( - id BIGSERIAL PRIMARY KEY, - tree_id BIGINT NOT NULL, - state_root VARCHAR(64) NOT NULL, - parent_state_root VARCHAR(64) NOT NULL, - FOREIGN KEY(state_root, tree_id) REFERENCES merkle_radix_tree_node(hash, tree_id) -); - -CREATE TABLE IF NOT EXISTS merkle_radix_state_root_leaf_index ( - id BIGSERIAL PRIMARY KEY, - leaf_id BIGINT NOT NULL, - tree_id BIGINT NOT NULL, - from_state_root_id BIGINT NOT NULL, - to_state_root_id BIGINT, - FOREIGN KEY(from_state_root_id) REFERENCES merkle_radix_state_root(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf (id), - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) -); diff --git a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-08-18-drop-indexes/down.sql b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-08-18-drop-indexes/down.sql deleted file mode 100644 index 4d04cbe4..00000000 --- a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-08-18-drop-indexes/down.sql +++ /dev/null @@ -1,33 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -CREATE TABLE IF NOT EXISTS merkle_radix_state_root ( - id BIGSERIAL PRIMARY KEY, - tree_id BIGINT NOT NULL, - state_root VARCHAR(64) NOT NULL, - parent_state_root VARCHAR(64) NOT NULL, - FOREIGN KEY(state_root, tree_id) REFERENCES merkle_radix_tree_node(hash, tree_id) -); - -CREATE TABLE IF NOT EXISTS merkle_radix_state_root_leaf_index ( - id BIGSERIAL PRIMARY KEY, - leaf_id BIGINT NOT NULL, - tree_id BIGINT NOT NULL, - from_state_root_id BIGINT NOT NULL, - to_state_root_id BIGINT, - FOREIGN KEY(from_state_root_id) REFERENCES merkle_radix_state_root(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf (id), - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) -); diff --git a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-08-18-drop-indexes/up.sql b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-08-18-drop-indexes/up.sql deleted file mode 100644 index a90f05ae..00000000 --- a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-08-18-drop-indexes/up.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -DROP TABLE IF EXISTS merkle_radix_state_root_leaf_index; -DROP TABLE IF EXISTS merkle_radix_state_root; diff --git a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-06-30-121000-initialize-tables/down.sql b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-09-09-121000-initialize-tables/down.sql similarity index 87% rename from libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-06-30-121000-initialize-tables/down.sql rename to libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-09-09-121000-initialize-tables/down.sql index 91ccf555..99d57285 100644 --- a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-06-30-121000-initialize-tables/down.sql +++ b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-09-09-121000-initialize-tables/down.sql @@ -13,8 +13,8 @@ -- limitations under the License. -- ----------------------------------------------------------------------------- -DROP TABLE IF EXISTS merkle_radix_state_root_leaf_index; -DROP TABLE IF EXISTS merkle_radix_state_root; +DROP TABLE IF EXISTS merkle_radix_change_log_addition; +DROP TABLE IF EXISTS merkle_radix_change_log_deletion; DROP TABLE IF EXISTS merkle_radix_tree_node; DROP TABLE IF EXISTS merkle_radix_leaf; DROP TABLE IF EXISTS merkle_radix_tree; diff --git a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-07-29-105100-change-log/up.sql b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-09-09-121000-initialize-tables/up.sql similarity index 70% rename from libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-07-29-105100-change-log/up.sql rename to libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-09-09-121000-initialize-tables/up.sql index 0ec7f727..577a49c5 100644 --- a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-07-29-105100-change-log/up.sql +++ b/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-09-09-121000-initialize-tables/up.sql @@ -13,6 +13,32 @@ -- limitations under the License. -- ----------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS merkle_radix_tree ( + id BIGSERIAL PRIMARY KEY, + name VARCHAR(512), + UNIQUE(name) +); + +INSERT INTO merkle_radix_tree (name) VALUES ('default'); + +CREATE TABLE IF NOT EXISTS merkle_radix_leaf ( + id BIGSERIAL PRIMARY KEY, + tree_id BIGINT NOT NULL, + address VARCHAR(70) NOT NULL, + data BYTEA, + FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) +); + +CREATE TABLE IF NOT EXISTS merkle_radix_tree_node ( + hash VARCHAR(64) NOT NULL, + tree_id BIGINT NOT NULL, + leaf_id BIGINT, + children VARCHAR(64)[], + PRIMARY KEY (hash, tree_id), + FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree(id), + FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf(id) +); + create TABLE IF NOT EXISTS merkle_radix_change_log_addition ( id BIGSERIAL PRIMARY KEY, tree_id BIGINT NOT NULL, diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-15-013200-initialize-tables/down.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-15-013200-initialize-tables/down.sql deleted file mode 100644 index 5bdf7b9b..00000000 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-15-013200-initialize-tables/down.sql +++ /dev/null @@ -1,19 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -DROP TABLE IF EXISTS merkle_radix_state_root_leaf_index; -DROP TABLE IF EXISTS merkle_radix_state_root; -DROP TABLE IF EXISTS merkle_radix_tree_node; -DROP TABLE IF EXISTS merkle_radix_leaf; diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-15-013200-initialize-tables/up.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-15-013200-initialize-tables/up.sql deleted file mode 100644 index 131472d6..00000000 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-15-013200-initialize-tables/up.sql +++ /dev/null @@ -1,43 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -CREATE TABLE IF NOT EXISTS merkle_radix_leaf ( - id INTEGER PRIMARY KEY, - address STRING NOT NULL, - data BLOB -); - -CREATE TABLE IF NOT EXISTS merkle_radix_tree_node ( - hash STRING PRIMARY KEY, - leaf_id INTEGER, - children TEXT, - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf(id) -); - -CREATE TABLE IF NOT EXISTS merkle_radix_state_root ( - id INTEGER PRIMARY KEY, - state_root STRING NOT NULL, - parent_state_root STRING NOT NULL, - FOREIGN KEY(state_root) REFERENCES merkle_radix_tree_node (hash) -); - -CREATE TABLE IF NOT EXISTS merkle_radix_state_root_leaf_index ( - id INTEGER PRIMARY KEY, - leaf_id INTEGER NOT NULL, - from_state_root_id INTEGER NOT NULL, - to_state_root_id INTEGER, - FOREIGN KEY(from_state_root_id) REFERENCES merkle_radix_state_root(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf (id) -); diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-21-043900-multiple-tree-support/down.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-21-043900-multiple-tree-support/down.sql deleted file mode 100644 index e69de29b..00000000 diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-21-043900-multiple-tree-support/up.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-21-043900-multiple-tree-support/up.sql deleted file mode 100644 index 094d0e48..00000000 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-06-21-043900-multiple-tree-support/up.sql +++ /dev/null @@ -1,99 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -CREATE TABLE IF NOT EXISTS merkle_radix_tree ( - id INTEGER PRIMARY KEY, - name TEXT, - UNIQUE(name) -); - -INSERT INTO merkle_radix_tree (id, name) VALUES (1, 'default'); - --- Rename all the current tables to _old: -ALTER TABLE merkle_radix_state_root_leaf_index - RENAME TO _merkle_radix_state_root_leaf_index_old; - -ALTER TABLE merkle_radix_state_root RENAME TO _merkle_radix_state_root_old; - -ALTER TABLE merkle_radix_tree_node RENAME TO _merkle_radix_tree_node_old; - -ALTER TABLE merkle_radix_leaf RENAME TO _merkle_radix_leaf_old; - --- Recreate the tables with a tree ID, in the order of foreign key relationships - --- Add tree_id to the merkle_radix_leaf table -CREATE TABLE IF NOT EXISTS merkle_radix_leaf ( - id INTEGER PRIMARY KEY, - tree_id INTEGER NOT NULL, - address STRING NOT NULL, - data BLOB, - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) -); - -INSERT INTO merkle_radix_leaf - (id, tree_id, address, data) - SELECT id, 1, address, data FROM _merkle_radix_leaf_old; - --- Add tree_id to the merkle_radix_tree_node table -CREATE TABLE IF NOT EXISTS merkle_radix_tree_node ( - hash STRING NOT NULL, - tree_id INTEGER NOT NULL, - leaf_id INTEGER, - children TEXT, - PRIMARY KEY (hash, tree_id), - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf(id) -); - -INSERT INTO merkle_radix_tree_node - (hash, tree_id, leaf_id, children) - SELECT hash, 1, leaf_id, children FROM _merkle_radix_tree_node_old; - --- Add tree_id to the merkle_radix_state_root table -CREATE TABLE IF NOT EXISTS merkle_radix_state_root ( - id INTEGER PRIMARY KEY, - tree_id INTEGER NOT NULL, - state_root STRING NOT NULL, - parent_state_root STRING NOT NULL, - FOREIGN KEY(state_root, tree_id) REFERENCES merkle_radix_tree_node(hash, tree_id) -); - -INSERT INTO merkle_radix_state_root - (id, tree_id, state_root, parent_state_root) - SELECT id, 1, state_root, parent_state_root - FROM _merkle_radix_state_root_old; - --- Add tree_id to the merkle_radix_state_root_leaf_index table -CREATE TABLE IF NOT EXISTS merkle_radix_state_root_leaf_index ( - id INTEGER PRIMARY KEY, - leaf_id INTEGER NOT NULL, - tree_id INTEGER NOT NULL, - from_state_root_id INTEGER NOT NULL, - to_state_root_id INTEGER, - FOREIGN KEY(from_state_root_id) REFERENCES merkle_radix_state_root(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf (id), - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) -); - -INSERT INTO merkle_radix_state_root_leaf_index - (id, leaf_id, tree_id, from_state_root_id, to_state_root_id) - SELECT id, leaf_id, 1, from_state_root_id, to_state_root_id - FROM _merkle_radix_state_root_leaf_index_old; - --- Drop the old tables -DROP TABLE _merkle_radix_state_root_leaf_index_old; -DROP TABLE _merkle_radix_state_root_old; -DROP TABLE _merkle_radix_tree_node_old; -DROP TABLE _merkle_radix_leaf_old; diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-07-29-105100-change-log/down.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-07-29-105100-change-log/down.sql deleted file mode 100644 index 02ef69e1..00000000 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-07-29-105100-change-log/down.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -DROP TABLE IF EXISTS merkle_radix_change_log_addition; -DROP TABLE IF EXISTS merkle_radix_change_log_deletion; diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-08-18-drop-indexes/down.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-08-18-drop-indexes/down.sql deleted file mode 100644 index e2153482..00000000 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-08-18-drop-indexes/down.sql +++ /dev/null @@ -1,35 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - --- Add tree_id to the merkle_radix_state_root table -CREATE TABLE IF NOT EXISTS merkle_radix_state_root ( - id INTEGER PRIMARY KEY, - tree_id INTEGER NOT NULL, - state_root STRING NOT NULL, - parent_state_root STRING NOT NULL, - FOREIGN KEY(state_root, tree_id) REFERENCES merkle_radix_tree_node(hash, tree_id) -); - --- Add tree_id to the merkle_radix_state_root_leaf_index table -CREATE TABLE IF NOT EXISTS merkle_radix_state_root_leaf_index ( - id INTEGER PRIMARY KEY, - leaf_id INTEGER NOT NULL, - tree_id INTEGER NOT NULL, - from_state_root_id INTEGER NOT NULL, - to_state_root_id INTEGER, - FOREIGN KEY(from_state_root_id) REFERENCES merkle_radix_state_root(id), - FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf (id), - FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) -); diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-08-18-drop-indexes/up.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-08-18-drop-indexes/up.sql deleted file mode 100644 index a90f05ae..00000000 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-08-18-drop-indexes/up.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Copyright 2021 Cargill Incorporated --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- ----------------------------------------------------------------------------- - -DROP TABLE IF EXISTS merkle_radix_state_root_leaf_index; -DROP TABLE IF EXISTS merkle_radix_state_root; diff --git a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-07-29-105100-change-log/down.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-09-09-121000-initialize-tables/down.sql similarity index 86% rename from libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-07-29-105100-change-log/down.sql rename to libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-09-09-121000-initialize-tables/down.sql index 02ef69e1..99d57285 100644 --- a/libtransact/src/state/merkle/sql/migration/postgres/migrations/2021-07-29-105100-change-log/down.sql +++ b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-09-09-121000-initialize-tables/down.sql @@ -15,3 +15,6 @@ DROP TABLE IF EXISTS merkle_radix_change_log_addition; DROP TABLE IF EXISTS merkle_radix_change_log_deletion; +DROP TABLE IF EXISTS merkle_radix_tree_node; +DROP TABLE IF EXISTS merkle_radix_leaf; +DROP TABLE IF EXISTS merkle_radix_tree; diff --git a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-07-29-105100-change-log/up.sql b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-09-09-121000-initialize-tables/up.sql similarity index 70% rename from libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-07-29-105100-change-log/up.sql rename to libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-09-09-121000-initialize-tables/up.sql index 016af063..a22c6e4f 100644 --- a/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-07-29-105100-change-log/up.sql +++ b/libtransact/src/state/merkle/sql/migration/sqlite/migrations/2021-09-09-121000-initialize-tables/up.sql @@ -13,6 +13,32 @@ -- limitations under the License. -- ----------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS merkle_radix_tree ( + id INTEGER PRIMARY KEY, + name TEXT, + UNIQUE(name) +); + +INSERT INTO merkle_radix_tree (name) VALUES ('default'); + +CREATE TABLE IF NOT EXISTS merkle_radix_leaf ( + id INTEGER PRIMARY KEY, + tree_id INTEGER NOT NULL, + address STRING NOT NULL, + data BLOB, + FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id) +); + +CREATE TABLE IF NOT EXISTS merkle_radix_tree_node ( + hash STRING NOT NULL, + tree_id INTEGER NOT NULL, + leaf_id INTEGER, + children TEXT, + PRIMARY KEY (hash, tree_id), + FOREIGN KEY(tree_id) REFERENCES merkle_radix_tree (id), + FOREIGN KEY(leaf_id) REFERENCES merkle_radix_leaf(id) +); + create TABLE IF NOT EXISTS merkle_radix_change_log_addition ( id INTEGER PRIMARY KEY, tree_id BIGINT NOT NULL,