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:
M5Max128
2026-05-22 08:35:28 +08:00
parent e1dbd27333
commit 701e71463d
6 changed files with 524 additions and 16 deletions

View File

@@ -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)
}
}