mirror of
https://github.com/bitwarden/server
synced 2026-02-22 12:23:37 +00:00
Add initial table migrations
Note, there is a name change here relative to AKD. They use a `Users` table with username. However, that will be odd in our design, where we expect to store multiple values per user. Therefore, we generalize to `Values` and `raw_label`
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS dbo.akd_azks;
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS dbo.akd_history_tree_nodes;
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS dbo.akd_values;
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
9
akd/crates/akd_storage/src/migrations.rs
Normal file
9
akd/crates/akd_storage/src/migrations.rs
Normal file
@@ -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");
|
||||
Reference in New Issue
Block a user