feat(watchlist): add company identity catalog

Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection.

Refs #19

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 15:08:22 +01:00
parent 1123360914
commit d65222169a
50 changed files with 49897 additions and 193 deletions

View File

@ -0,0 +1,33 @@
package models
import (
"github.com/tradarr/backend/internal/companycatalog"
)
// UpsertCompanyAsset never converts legacy rows. Each owner/company identity
// has an independent follow, resolved from the trusted local catalogue.
func (r *Repository) UpsertCompanyAsset(owner string, company companycatalog.Company) (*UserAsset, error) {
tx, err := r.db.Begin()
if err != nil {
return nil, err
}
defer tx.Rollback()
if _, err = tx.Exec(`SELECT pg_advisory_xact_lock(hashtextextended($1,0))`, owner); err != nil {
return nil, err
}
a := &UserAsset{}
err = tx.QueryRow(`INSERT INTO user_assets(user_id,symbol,name,figi,company_id,yahoo_symbol,company_exchange,company_country,company_mic)
VALUES($1,$2::text,$3,NULLIF($4,''),$5,$2::text,$6,$7,$8)
ON CONFLICT(user_id,company_id) WHERE company_id IS NOT NULL DO UPDATE SET
symbol=EXCLUDED.symbol,name=EXCLUDED.name,figi=EXCLUDED.figi,yahoo_symbol=EXCLUDED.yahoo_symbol,
company_exchange=EXCLUDED.company_exchange,company_country=EXCLUDED.company_country,company_mic=EXCLUDED.company_mic
RETURNING id,user_id,symbol,name,figi,created_at,company_id,yahoo_symbol,company_exchange,company_country,company_mic`,
owner, company.YahooSymbol, company.Name, company.FIGI, company.CompanyID, company.Exchange, company.Country, company.MIC).Scan(&a.ID, &a.UserID, &a.Symbol, &a.Name, &a.FIGI, &a.CreatedAt, &a.CompanyID, &a.YahooSymbol, &a.CompanyExchange, &a.CompanyCountry, &a.CompanyMIC)
if err != nil {
return nil, err
}
if err = tx.Commit(); err != nil {
return nil, err
}
return a, nil
}