Replace document_id with relative path
This commit is contained in:
parent
476c0ed672
commit
fe7ff5349d
11 changed files with 83 additions and 270 deletions
|
|
@ -1,27 +1,25 @@
|
|||
CREATE TABLE IF NOT EXISTS documents (
|
||||
vault_id TEXT NOT NULL,
|
||||
document_id TEXT NOT NULL,
|
||||
relative_path TEXT NOT NULL,
|
||||
version_id INTEGER NOT NULL,
|
||||
created_date TIMESTAMP NOT NULL,
|
||||
updated_date TIMESTAMP NOT NULL,
|
||||
relative_path TEXT NOT NULL,
|
||||
content BLOB NOT NULL,
|
||||
is_binary BOOLEAN NOT NULL,
|
||||
is_deleted BOOLEAN NOT NULL,
|
||||
PRIMARY KEY (vault_id, document_id, version_id)
|
||||
PRIMARY KEY (vault_id, relative_path, version_id)
|
||||
);
|
||||
|
||||
CREATE VIEW IF NOT EXISTS latest_documents AS
|
||||
CREATE VIEW IF NOT EXISTS latest_document_versions AS
|
||||
SELECT d.*
|
||||
FROM documents d
|
||||
INNER JOIN (
|
||||
SELECT vault_id, document_id, MAX(version_id) AS max_version_id
|
||||
SELECT vault_id, relative_path, MAX(version_id) AS max_version_id
|
||||
FROM documents
|
||||
GROUP BY vault_id, document_id
|
||||
GROUP BY vault_id, relative_path
|
||||
) max_versions
|
||||
ON d.vault_id = max_versions.vault_id
|
||||
AND d.document_id = max_versions.document_id
|
||||
AND d.relative_path = max_versions.relative_path
|
||||
AND d.version_id = max_versions.max_version_id;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_documents_vault_doc
|
||||
ON documents (vault_id, document_id);
|
||||
ON documents (vault_id, relative_path);
|
||||
|
|
|
|||
|
|
@ -4,17 +4,15 @@ use serde::Serialize;
|
|||
use sync_lib::bytes_to_base64;
|
||||
|
||||
pub type VaultId = String;
|
||||
pub type DocumentId = uuid::Uuid;
|
||||
pub type DocumentVersionId = i64;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StoredDocumentVersion {
|
||||
pub vault_id: VaultId,
|
||||
pub document_id: DocumentId,
|
||||
pub relative_path: String,
|
||||
pub version_id: DocumentVersionId,
|
||||
pub created_date: DateTime<Utc>,
|
||||
pub updated_date: DateTime<Utc>,
|
||||
pub relative_path: String,
|
||||
pub content: Vec<u8>,
|
||||
pub is_deleted: bool,
|
||||
}
|
||||
|
|
@ -23,11 +21,10 @@ pub struct StoredDocumentVersion {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DocumentVersionWithoutContent {
|
||||
pub vault_id: VaultId,
|
||||
pub document_id: DocumentId,
|
||||
pub relative_path: String,
|
||||
pub version_id: DocumentVersionId,
|
||||
pub created_date: DateTime<Utc>,
|
||||
pub updated_date: DateTime<Utc>,
|
||||
pub relative_path: String,
|
||||
pub is_deleted: bool,
|
||||
}
|
||||
|
||||
|
|
@ -35,11 +32,10 @@ impl From<StoredDocumentVersion> for DocumentVersionWithoutContent {
|
|||
fn from(value: StoredDocumentVersion) -> Self {
|
||||
Self {
|
||||
vault_id: value.vault_id,
|
||||
document_id: value.document_id,
|
||||
relative_path: value.relative_path,
|
||||
version_id: value.version_id,
|
||||
created_date: value.created_date,
|
||||
updated_date: value.updated_date,
|
||||
relative_path: value.relative_path,
|
||||
is_deleted: value.is_deleted,
|
||||
}
|
||||
}
|
||||
|
|
@ -56,11 +52,10 @@ pub struct PingResponse {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DocumentVersion {
|
||||
pub vault_id: VaultId,
|
||||
pub document_id: DocumentId,
|
||||
pub relative_path: String,
|
||||
pub version_id: DocumentVersionId,
|
||||
pub created_date: DateTime<Utc>,
|
||||
pub updated_date: DateTime<Utc>,
|
||||
pub relative_path: String,
|
||||
pub content_base64: String,
|
||||
pub is_deleted: bool,
|
||||
}
|
||||
|
|
@ -69,11 +64,10 @@ impl From<StoredDocumentVersion> for DocumentVersion {
|
|||
fn from(value: StoredDocumentVersion) -> Self {
|
||||
Self {
|
||||
vault_id: value.vault_id,
|
||||
document_id: value.document_id,
|
||||
relative_path: value.relative_path,
|
||||
version_id: value.version_id,
|
||||
created_date: value.created_date,
|
||||
updated_date: value.updated_date,
|
||||
relative_path: value.relative_path,
|
||||
content_base64: bytes_to_base64(&value.content),
|
||||
is_deleted: value.is_deleted,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue