Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default-members = [".", "crates/*"]
resolver = "2"

[workspace.package]
version = "0.6.0"
version = "0.7.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/SimCubeLtd/keryx"
Expand Down
13 changes: 13 additions & 0 deletions crates/keryx-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ pub struct UploadMetadata {
pub cli_version: Option<String>,
}

/// Shared dashboard organisation metadata, independent of document summaries.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tag {
pub id: String,
pub name: String,
}

/// A dashboard row. Tags are never part of the CLI/TUI summary contract.
pub struct DashboardDraft {
pub summary: DraftSummary,
pub tags: Vec<Tag>,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
13 changes: 13 additions & 0 deletions crates/keryx-db/src/entity/draft_tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "draft_tags")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub draft_id: String,
#[sea_orm(primary_key, auto_increment = false)]
pub tag_id: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
4 changes: 4 additions & 0 deletions crates/keryx-db/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
//! columns are `bool`: INTEGER on SQLite, BOOLEAN on Postgres.

pub mod draft;
pub mod draft_tag;
pub mod draft_version;
pub mod notification_delivery;
pub mod notification_event;
pub mod push_subscription;
pub mod tag;

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -61,6 +63,8 @@ mod tests {
};
}
check!(draft::Entity);
check!(tag::Entity);
check!(draft_tag::Entity);
check!(draft_version::Entity);
check!(push_subscription::Entity);
check!(notification_event::Entity);
Expand Down
12 changes: 12 additions & 0 deletions crates/keryx-db/src/entity/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "tags")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
5 changes: 3 additions & 2 deletions crates/keryx-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod types;

pub use store::{DatabaseConfig, DraftStore, SeaOrmStore};
pub use types::{
normalize_wake_time, AvailabilityError, BlobRecord, NewUpload, PendingDelivery, ServedVersion,
UploadError, UploadOutcome, DEFAULT_DISABLE_REASON,
canonical_tag_name, normalize_wake_time, AvailabilityError, BlobRecord, DashboardTags,
NewUpload, PendingDelivery, ServedVersion, TagError, UploadError, UploadOutcome,
DEFAULT_DISABLE_REASON,
};
33 changes: 33 additions & 0 deletions crates/keryx-db/src/migration/m0002_tags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! Add organisation metadata without rewriting any existing table.
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared(
r#"
CREATE TABLE tags (id TEXT PRIMARY KEY NOT NULL, name TEXT NOT NULL UNIQUE);
CREATE TABLE draft_tags (
draft_id TEXT NOT NULL REFERENCES drafts(id) ON DELETE CASCADE,
tag_id TEXT NOT NULL REFERENCES tags(id) ON DELETE CASCADE,
PRIMARY KEY (draft_id, tag_id)
);
CREATE INDEX draft_tags_tag_id_idx ON draft_tags(tag_id, draft_id);
"#,
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared("DROP TABLE draft_tags; DROP TABLE tags;")
.await?;
Ok(())
}
}
10 changes: 8 additions & 2 deletions crates/keryx-db/src/migration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Schema migrations, tracked by SeaORM in `seaql_migrations`.

mod m0001_baseline;
mod m0002_tags;

use sea_orm_migration::prelude::*;

Expand All @@ -15,7 +16,10 @@ pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m0001_baseline::Migration)]
vec![
Box::new(m0001_baseline::Migration),
Box::new(m0002_tags::Migration),
]
}
}

Expand Down Expand Up @@ -45,17 +49,19 @@ mod tests {
assert_eq!(
names("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name").await,
[
"draft_tags",
"draft_versions",
"drafts",
"notification_deliveries",
"notification_events",
"push_subscriptions",
"seaql_migrations",
"tags",
]
);
assert_eq!(
names("SELECT version FROM seaql_migrations").await,
[BASELINE_NAME]
[BASELINE_NAME, "m0002_tags"]
);
}
}
Loading
Loading