-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4054: feat(module-index-server): add schema data to module index table before backfill r=zacharyhamm a=zacharyhamm Co-authored-by: Zachary Hamm <zack@systeminit.com>
- Loading branch information
Showing
6 changed files
with
181 additions
and
83 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
lib/module-index-server/src/migrations/U0006__modules_schema_id_etc.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE modules | ||
ADD schema_name TEXT, | ||
ADD schema_category TEXT, | ||
ADD schema_id ident; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use sea_orm::{entity::prelude::*, sea_query, TryGetError}; | ||
use serde::{Deserialize, Serialize}; | ||
use ulid::Ulid; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct ModuleId(pub Ulid); | ||
|
||
impl From<ModuleId> for Value { | ||
fn from(source: ModuleId) -> Self { | ||
Value::String(Some(Box::new(source.0.to_string()))) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for ModuleId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl TryFrom<String> for ModuleId { | ||
type Error = sea_orm::DbErr; | ||
fn try_from(s: String) -> Result<Self, Self::Error> { | ||
Ok(ModuleId( | ||
Ulid::from_string(&s).map_err(|err| DbErr::Type(err.to_string()))?, | ||
)) | ||
} | ||
} | ||
|
||
impl sea_orm::TryFromU64 for ModuleId { | ||
fn try_from_u64(_: u64) -> Result<Self, sea_orm::DbErr> { | ||
Err(sea_orm::DbErr::Exec(sea_orm::RuntimeErr::Internal( | ||
format!("{} cannot be converted from u64", stringify!(ModuleId)), | ||
))) | ||
} | ||
} | ||
|
||
impl From<ModuleId> for String { | ||
fn from(val: ModuleId) -> Self { | ||
val.0.to_string() | ||
} | ||
} | ||
|
||
impl sea_orm::sea_query::Nullable for ModuleId { | ||
fn null() -> sea_orm::Value { | ||
sea_orm::Value::String(None) | ||
} | ||
} | ||
|
||
impl sea_orm::TryGetable for ModuleId { | ||
fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> { | ||
let json_str: String = res.try_get_by(idx).map_err(TryGetError::DbErr)?; | ||
Ulid::from_string(&json_str) | ||
.map_err(|e| TryGetError::DbErr(DbErr::Type(e.to_string()))) | ||
.map(ModuleId) | ||
} | ||
} | ||
|
||
impl sea_query::ValueType for ModuleId { | ||
fn try_from(v: Value) -> Result<Self, sea_query::ValueTypeErr> { | ||
match v { | ||
Value::String(Some(x)) => Ok(ModuleId( | ||
Ulid::from_string(&x).map_err(|_| sea_query::ValueTypeErr)?, | ||
)), | ||
_ => Err(sea_query::ValueTypeErr), | ||
} | ||
} | ||
|
||
fn type_name() -> String { | ||
stringify!(ModuleId).to_owned() | ||
} | ||
|
||
fn array_type() -> sea_orm::sea_query::ArrayType { | ||
sea_orm::sea_query::ArrayType::String | ||
} | ||
|
||
fn column_type() -> sea_query::ColumnType { | ||
sea_query::ColumnType::String(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use sea_orm::{entity::prelude::*, sea_query, TryGetError}; | ||
use serde::{Deserialize, Serialize}; | ||
use ulid::Ulid; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct SchemaId(pub Ulid); | ||
|
||
impl From<SchemaId> for Value { | ||
fn from(source: SchemaId) -> Self { | ||
Value::String(Some(Box::new(source.0.to_string()))) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for SchemaId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl TryFrom<String> for SchemaId { | ||
type Error = sea_orm::DbErr; | ||
fn try_from(s: String) -> Result<Self, Self::Error> { | ||
Ok(SchemaId( | ||
Ulid::from_string(&s).map_err(|err| DbErr::Type(err.to_string()))?, | ||
)) | ||
} | ||
} | ||
|
||
impl sea_orm::TryFromU64 for SchemaId { | ||
fn try_from_u64(_: u64) -> Result<Self, sea_orm::DbErr> { | ||
Err(sea_orm::DbErr::Exec(sea_orm::RuntimeErr::Internal( | ||
format!("{} cannot be converted from u64", stringify!(SchemaId)), | ||
))) | ||
} | ||
} | ||
|
||
impl From<SchemaId> for String { | ||
fn from(val: SchemaId) -> Self { | ||
val.0.to_string() | ||
} | ||
} | ||
|
||
impl sea_orm::sea_query::Nullable for SchemaId { | ||
fn null() -> sea_orm::Value { | ||
sea_orm::Value::String(None) | ||
} | ||
} | ||
|
||
impl sea_orm::TryGetable for SchemaId { | ||
fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> { | ||
let json_str: String = res.try_get_by(idx).map_err(TryGetError::DbErr)?; | ||
Ulid::from_string(&json_str) | ||
.map_err(|e| TryGetError::DbErr(DbErr::Type(e.to_string()))) | ||
.map(SchemaId) | ||
} | ||
} | ||
|
||
impl sea_query::ValueType for SchemaId { | ||
fn try_from(v: Value) -> Result<Self, sea_query::ValueTypeErr> { | ||
match v { | ||
Value::String(Some(x)) => Ok(SchemaId( | ||
Ulid::from_string(&x).map_err(|_| sea_query::ValueTypeErr)?, | ||
)), | ||
_ => Err(sea_query::ValueTypeErr), | ||
} | ||
} | ||
|
||
fn type_name() -> String { | ||
stringify!(SchemaId).to_owned() | ||
} | ||
|
||
fn array_type() -> sea_orm::sea_query::ArrayType { | ||
sea_orm::sea_query::ArrayType::String | ||
} | ||
|
||
fn column_type() -> sea_query::ColumnType { | ||
sea_query::ColumnType::String(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters