+ secret & metadata migration

This commit is contained in:
sam 2024-05-01 20:17:16 +02:00
parent 2c355ef75d
commit 0a0091c44f
3 changed files with 30 additions and 1 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ target/
go_client/openapi.json go_client/openapi.json
crates/storage-sled/sled_db crates/storage-sled/sled_db
test.db test.db
src/storage/database.db

View file

@ -0,0 +1,28 @@
-- Add migration script here
CREATE TABLE metadata (
secret_path TEXT PRIMARY KEY NOT NULL,
cas_required INTEGER NOT NULL, -- no bool datatype in sqlite
created_time TIMESTAMP NOT NULL,
delete_version_after TEXT, -- Maybe NOT NULL
max_versions INTEGER NOT NULL,
-- current_version INTEGER NOT NULL,
-- oldest_version INTEGER NOT NULL,
updated_time TIMESTAMP NOT NULL,
custom_data TEXT
);
CREATE TABLE secret_versions (
secret_data TEXT NOT NULL,
created_time TIMESTAMP NOT NULL,
deletion_time TIMESTAMP,
version_number INTEGER NOT NULL DEFAULT 0,
secret_path TEXT NOT NULL,
PRIMARY KEY (secret_path, version_number),
FOREIGN KEY (secret_path) REFERENCES metadata(secret_path)
);
CREATE INDEX idx_secret_versions_secret_path ON secret_versions (secret_path);

View file

@ -1,6 +1,6 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{collections::HashMap, hash::Hash, vec}; use std::{collections::HashMap, vec};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct KvSecret { pub struct KvSecret {