Add sorting preset table definitions
Signed-off-by: trivernis <trivernis@protonmail.com>pull/12/head
parent
426203b8e5
commit
ed68b76a42
@ -0,0 +1,20 @@
|
|||||||
|
-- Add migration script here
|
||||||
|
CREATE TABLE sorting_presets (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE sort_keys (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
key_type INTEGER NOT NULL DEFAULT 0,
|
||||||
|
ascending INTEGER NOT NULL CHECK (ascending IN (0, 1)),
|
||||||
|
value VARCHAR(128)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE sorting_preset_keys (
|
||||||
|
preset_id INTEGER REFERENCES sorting_presets (id) ON DELETE CASCADE,
|
||||||
|
key_id INTEGER REFERENCES sort_keys (id),
|
||||||
|
key_index INTEGER NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (preset_id, key_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX sorting_preset_index ON sorting_preset_keys (preset_id);
|
@ -0,0 +1,26 @@
|
|||||||
|
use sea_orm::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "sort_keys")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: i32,
|
||||||
|
pub key_type: i32,
|
||||||
|
pub ascending: bool,
|
||||||
|
pub value: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl Related<super::sorting_preset::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
super::sorting_preset_key::Relation::SortingPreset.def()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn via() -> Option<RelationDef> {
|
||||||
|
Some(super::sorting_preset_key::Relation::SortingKey.def().rev())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
@ -0,0 +1,27 @@
|
|||||||
|
use sea_orm::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "sorting_presets")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl Related<super::sort_key::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
super::sorting_preset_key::Relation::SortingKey.def()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn via() -> Option<RelationDef> {
|
||||||
|
Some(
|
||||||
|
super::sorting_preset_key::Relation::SortingPreset
|
||||||
|
.def()
|
||||||
|
.rev(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
@ -0,0 +1,44 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "sorting_preset_keys")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
preset_id: i32,
|
||||||
|
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
key_id: i32,
|
||||||
|
|
||||||
|
key_index: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::sorting_preset::Entity"
|
||||||
|
from = "Column::PresetId",
|
||||||
|
to = "super::sorting_preset::Column::Id"
|
||||||
|
)]
|
||||||
|
SortingPreset,
|
||||||
|
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::sort_key::Entity",
|
||||||
|
from = "Column::KeyId",
|
||||||
|
to = "super::sort_key::Column::Id"
|
||||||
|
)]
|
||||||
|
SortingKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::sorting_preset::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::SortingPreset.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::sort_key::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::SortingKey.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
Loading…
Reference in New Issue