feat: identity PATCH update, alias system, name UNIQUE removal
- Add PATCH /api/v1/identity/:identity_uuid endpoint - Migration 030: remove name UNIQUE, add tmdb_id index - TMDb upsert: ON CONFLICT (name) -> ON CONFLICT (tmdb_id) - get_or_create_identity: pre-check by name - upload_identity: ON CONFLICT (name) -> ON CONFLICT (uuid) - Search: include aliases in identity text search - Add scripts/llm_metadata_enhancer.py - Add DESIGN/IdentityUpdateAndAliasSystem.md
This commit is contained in:
@@ -3210,12 +3210,27 @@ impl PostgresDb {
|
||||
|
||||
pub async fn get_or_create_identity(&self, name: &str) -> Result<i32> {
|
||||
let identities_table = schema::table_name("identities");
|
||||
let id: i32 = sqlx::query_scalar(&format!(
|
||||
"INSERT INTO {} (name, identity_type, source, status) VALUES ($1, 'people', 'user_defined', 'confirmed') \
|
||||
ON CONFLICT (name) DO UPDATE SET updated_at = CURRENT_TIMESTAMP RETURNING id", identities_table
|
||||
// First: try to find existing identity by name
|
||||
if let Some(id) = sqlx::query_scalar::<_, i32>(&format!(
|
||||
"SELECT id FROM {} WHERE name = $1 LIMIT 1",
|
||||
identities_table
|
||||
))
|
||||
.bind(name)
|
||||
.fetch_one(&self.pool).await?;
|
||||
.fetch_optional(&self.pool)
|
||||
.await?
|
||||
{
|
||||
return Ok(id);
|
||||
}
|
||||
// Not found: create new with generated uuid
|
||||
let id: i32 = sqlx::query_scalar(&format!(
|
||||
"INSERT INTO {} (uuid, name, identity_type, source, status) \
|
||||
VALUES (gen_random_uuid(), $1, 'people', 'user_defined', 'confirmed') \
|
||||
RETURNING id",
|
||||
identities_table
|
||||
))
|
||||
.bind(name)
|
||||
.fetch_one(&self.pool)
|
||||
.await?;
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user