let note = entity::note::ActiveModel {
note_id: note_id.clone(),
collection_id: Set(self.collection_id),
+ nodename: Set(title.clone()), // TODO: create unique nodename
kind: Set(self.kind.clone()),
title: Set(title),
lastmodified: Set(Utc::now().into()),
#[sea_orm(primary_key)]
pub note_id: i32,
pub collection_id: i32,
+ pub nodename: String,
pub kind: NoteType,
pub title: String,
Model {
note_id: 0,
collection_id: 0,
+ nodename: "".to_string(),
kind: Default::default(),
title: Default::default(),
lastmodified: Default::default(),
.if_not_exists()
.col(pk_auto("note_id"))
.col(integer("collection_id"))
+ .col(string("nodename"))
.col(integer("kind"))
.col(string("title"))
.col(timestamp_with_time_zone("lastmodified"))
.to_owned()
).await?;
+ manager.create_index(
+ Index::create()
+ .name("index-note-name")
+ .table("note")
+ .col(Note::CollectionId)
+ .col(Note::NodeName)
+ .unique()
+ .to_owned()
+ ).await?;
+
manager
.create_table(
Table::create()
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
+ manager
+ .drop_index(Index::drop().name("index-note-name").table("note").to_owned()).await?;
manager
.drop_table(Table::drop().table("note_content").to_owned()).await?;
manager
.await
}
}
+
+#[derive(Iden)]
+enum Note {
+ CollectionId,
+ NodeName
+}
\ No newline at end of file