diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_azks_table/down.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_azks_table/down.sql new file mode 100644 index 0000000000..adcf41f158 --- /dev/null +++ b/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_azks_table/down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS dbo.akd_azks; diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_azks_table/up.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_azks_table/up.sql new file mode 100644 index 0000000000..1a7d3e647c --- /dev/null +++ b/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_azks_table/up.sql @@ -0,0 +1,9 @@ +IF OBJECT_ID('dbo.akd_azks', 'U') IS NULL +BEGIN + CREATE TABLE dbo.akd_azks ( + [key] SMALLINT NOT NULL CHECK ([key] >= 0), + epoch BIGINT NOT NULL CHECK (epoch >= 0), + num_nodes BIGINT NOT NULL CHECK (num_nodes >= 0), + PRIMARY KEY ([key]) + ); +END diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_tables/down.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_tables/down.sql deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_tables/up.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_01_create_tables/up.sql deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_02_create_history_tree_nodes_table/down.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_02_create_history_tree_nodes_table/down.sql new file mode 100644 index 0000000000..06374fad66 --- /dev/null +++ b/akd/crates/akd_storage/migrations/ms_sql/20251002_02_create_history_tree_nodes_table/down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS dbo.akd_history_tree_nodes; diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_02_create_history_tree_nodes_table/up.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_02_create_history_tree_nodes_table/up.sql new file mode 100644 index 0000000000..e3c3dbad8d --- /dev/null +++ b/akd/crates/akd_storage/migrations/ms_sql/20251002_02_create_history_tree_nodes_table/up.sql @@ -0,0 +1,28 @@ +IF OBJECT_ID('dbo.akd_history_tree_nodes', 'U') IS NULL +BEGIN + CREATE TABLE dbo.akd_history_tree_nodes ( + label_len INT NOT NULL CHECK (label_len >= 0), + label_val VARBINARY(32) NOT NULL, + last_epoch BIGINT NOT NULL CHECK (last_epoch >= 0), + least_descendant_ep BIGINT NOT NULL CHECK (least_descendant_ep >= 0), + parent_label_len INT NOT NULL CHECK (parent_label_len >= 0), + parent_label_val VARBINARY(32) NOT NULL, + node_type SMALLINT NOT NULL CHECK (node_type >= 0), + left_child_len INT NULL CHECK (left_child_len IS NULL OR left_child_len >= 0), + left_child_label_val VARBINARY(32) NULL, + right_child_len INT NULL CHECK (right_child_len IS NULL OR right_child_len >= 0), + right_child_label_val VARBINARY(32) NULL, + [hash] VARBINARY(32) NOT NULL, + p_last_epoch BIGINT NULL CHECK (p_last_epoch IS NULL OR p_last_epoch >= 0), + p_least_descendant_ep BIGINT NULL CHECK (p_least_descendant_ep IS NULL OR p_least_descendant_ep >= 0), + p_parent_label_len INT NULL CHECK (p_parent_label_len IS NULL OR p_parent_label_len >= 0), + p_parent_label_val VARBINARY(32) NULL, + p_node_type SMALLINT NULL CHECK (p_node_type IS NULL OR p_node_type >= 0), + p_left_child_len INT NULL CHECK (p_left_child_len IS NULL OR p_left_child_len >= 0), + p_left_child_label_val VARBINARY(32) NULL, + p_right_child_len INT NULL CHECK (p_right_child_len IS NULL OR p_right_child_len >= 0), + p_right_child_label_val VARBINARY(32) NULL, + p_hash VARBINARY(32) NULL, + PRIMARY KEY (label_len, label_val) + ); +END diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_03_create_values_table/down.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_03_create_values_table/down.sql new file mode 100644 index 0000000000..f1268a9e7b --- /dev/null +++ b/akd/crates/akd_storage/migrations/ms_sql/20251002_03_create_values_table/down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS dbo.akd_values; diff --git a/akd/crates/akd_storage/migrations/ms_sql/20251002_03_create_values_table/up.sql b/akd/crates/akd_storage/migrations/ms_sql/20251002_03_create_values_table/up.sql new file mode 100644 index 0000000000..b1f4a2b063 --- /dev/null +++ b/akd/crates/akd_storage/migrations/ms_sql/20251002_03_create_values_table/up.sql @@ -0,0 +1,12 @@ +IF OBJECT_ID('dbo.akd_values', 'U') IS NULL +BEGIN + CREATE TABLE dbo.akd_values ( + raw_label VARBINARY(256) NOT NULL, + epoch BIGINT NOT NULL CHECK (epoch >= 0), + [version] BIGINT NOT NULL CHECK ([version] >= 0), + node_label_val VARBINARY(32) NOT NULL, + node_label_len INT NOT NULL CHECK (node_label_len >= 0), + [data] VARBINARY(2000) NULL, + PRIMARY KEY (raw_label, epoch) + ); +END diff --git a/akd/crates/akd_storage/src/lib.rs b/akd/crates/akd_storage/src/lib.rs index b5aa61d92d..e964aeb4d3 100644 --- a/akd/crates/akd_storage/src/lib.rs +++ b/akd/crates/akd_storage/src/lib.rs @@ -1,16 +1,2 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} - +mod migrations; mod ms_sql; diff --git a/akd/crates/akd_storage/src/migrations.rs b/akd/crates/akd_storage/src/migrations.rs new file mode 100644 index 0000000000..0e63522c5a --- /dev/null +++ b/akd/crates/akd_storage/src/migrations.rs @@ -0,0 +1,9 @@ +use ms_database::{load_migrations, Migration}; + +// Table names as constants +pub(crate) const TABLE_AZKS: &str = "akd_azks"; +pub(crate) const TABLE_HISTORY_TREE_NODES: &str = "akd_history_tree_nodes"; +pub(crate) const TABLE_VALUES: &str = "akd_values"; +pub(crate) const TEMP_IDS_TABLE: &str = "#akd_temp_ids"; + +pub(crate) const MIGRATIONS: &[Migration] = load_migrations!("migrations/ms_sql");