Commit Graph
1 Commits
  • fix(inbound): avoid UNIQUE email constraint when importing inbounds that share clients
    Importing a second inbound whose clients overlap an already-imported inbound
    failed with "UNIQUE constraint failed: client_traffics.email". The import path
    carries exported ClientStats, and tx.Save(inbound) cascaded that has-many
    association as INSERTs whose ON CONFLICT targets only the primary key, so a
    shared email (already owning a row from the first import) tripped the global
    unique constraint.
    
    Omit the ClientStats association on save and insert the carried stats ourselves
    with the same OnConflict{email, DoNothing} guard AddClientStat already uses:
    new clients keep their imported counters, shared emails reuse the existing row.
    Then run an idempotent AddClientStat pass over all clients so any client present
    in settings but missing from the stats payload still gets a traffic row (else it
    would escape quota/expiry accounting), and propagate insert errors so the tx
    rolls back instead of committing a partial state.