@@ -182,7 +182,7 @@ func (d *DBStore) Migrate(ctx context.Context) error {
182182//
183183// Empty default + partial indexes preserve existing query plans for
184184// rows written before this column existed. Readers that want the
185- // chatter should COALESCE(NULLIF(chatter_user_id,'' ), user_id) — the
185+ // chatter should COALESCE(NULLIF(chatter_user_id,” ), user_id) — the
186186// fallback is exactly right for the web channel (user_id was already
187187// the chatter there) and matches the pre-fix behavior on IM (where
188188// every chatter was mis-attributed to the channel owner anyway).
@@ -222,7 +222,7 @@ func (d *DBStore) migrateSessionsAddChatterUserID(ctx context.Context) error {
222222}
223223
224224// migrateAgentGoalsAddRouting retrofits channel/account_id/chat_id/
225- // project_id onto legacy agent_goals tables. All four default to ''
225+ // project_id onto legacy agent_goals tables. All four default to ”
226226// — pre-existing rows had no continuation infrastructure attached
227227// anyway, so the empty value just means "no routing recorded; can't
228228// auto-continue this goal" and TryFireContinuation bails safely.
@@ -523,7 +523,7 @@ func (d *DBStore) migrateConfigsAddScopeColumn(ctx context.Context) error {
523523// (user_id, agent_id) into a single lookup key: whichever is non-empty
524524// wins (they're mutually exclusive for provider/setting rows — the only
525525// kinds that remain in configs now that channels have their own table).
526- // System rows get scope_id='' .
526+ // System rows get scope_id=” .
527527//
528528// Idempotent: skips the ALTER if the column already exists and only
529529// backfills rows where scope_id is still empty.
@@ -2002,7 +2002,8 @@ func (d *DBStore) DeleteUser(ctx context.Context, id string) error {
20022002 return err
20032003 }
20042004 if _ , err := tx .ExecContext (ctx ,
2005- fmt .Sprintf ("DELETE FROM configs WHERE agent_id = %s" , d .ph (1 )), aid ); err != nil {
2005+ fmt .Sprintf ("DELETE FROM configs WHERE scope_id = %s OR scope_id LIKE %s" , d .ph (1 ), d .ph (2 )),
2006+ aid , "%/" + aid ); err != nil {
20062007 return err
20072008 }
20082009 }
@@ -2272,7 +2273,16 @@ func (d *DBStore) DeleteAgent(ctx context.Context, agentID string) error {
22722273 return err
22732274 }
22742275 defer tx .Rollback ()
2275- for _ , t := range []string {"agent_files" , "sessions" , "session_messages" , "session_events" , "cron_jobs" } {
2276+ for _ , t := range []string {
2277+ "agent_files" ,
2278+ "sessions" ,
2279+ "session_messages" ,
2280+ "session_events" ,
2281+ "cron_jobs" ,
2282+ "projects" ,
2283+ "project_runtimes" ,
2284+ "agent_goals" ,
2285+ } {
22762286 if _ , err := tx .ExecContext (ctx ,
22772287 fmt .Sprintf (`DELETE FROM %s WHERE agent_id = %s` , t , d .ph (1 )), agentID ); err != nil {
22782288 return err
@@ -2282,12 +2292,11 @@ func (d *DBStore) DeleteAgent(ctx context.Context, agentID string) error {
22822292 fmt .Sprintf (`DELETE FROM apikey_agents WHERE agent_id = %s` , d .ph (1 )), agentID ); err != nil {
22832293 return err
22842294 }
2285- // Drop every config row pointing at this agent — owner's official
2286- // rows (user_id='', agent_id=X), agent owner's per-agent overrides
2287- // (user_id=owner, agent_id=X), and any non-owner per-agent
2288- // overrides (user_id=other, agent_id=X).
2295+ // Drop every config row pointing at this agent — official agent rows
2296+ // (scope_id=X) and per-user agent overrides (scope_id=user/X).
22892297 if _ , err := tx .ExecContext (ctx ,
2290- fmt .Sprintf (`DELETE FROM configs WHERE agent_id = %s` , d .ph (1 )), agentID ); err != nil {
2298+ fmt .Sprintf (`DELETE FROM configs WHERE scope_id = %s OR scope_id LIKE %s` , d .ph (1 ), d .ph (2 )),
2299+ agentID , "%/" + agentID ); err != nil {
22912300 return err
22922301 }
22932302 if _ , err := tx .ExecContext (ctx ,
@@ -2818,7 +2827,7 @@ func (d *DBStore) ListSessionMessages(ctx context.Context, userID, agentID, sess
28182827//
28192828// Filter is strictly on chatter_user_id (no fallback to user_id). Old
28202829// rows written before the chatter_user_id column existed have it set
2821- // to '' and are not counted; those predate per-chatter resolution and
2830+ // to ” and are not counted; those predate per-chatter resolution and
28222831// folding them in would over-count (they're keyed by channel owner,
28232832// not the actual chatter). New conversations write chatter_user_id
28242833// correctly so this is only a concern for sessions migrated from
@@ -3385,9 +3394,9 @@ func (d *DBStore) migrateChannelsFromConfigs(ctx context.Context) error {
33853394 // Each config row may have multiple accounts in its data JSON.
33863395 // Extract them and create one channel row per account.
33873396 var cc struct {
3388- BotToken string `json:"botToken"`
3389- BaseURL string `json:"baseUrl"`
3390- Accounts map [string ]json.RawMessage `json:"accounts"`
3397+ BotToken string `json:"botToken"`
3398+ BaseURL string `json:"baseUrl"`
3399+ Accounts map [string ]json.RawMessage `json:"accounts"`
33913400 }
33923401 if blob , merr := json .Marshal (cfg .Data ); merr == nil {
33933402 _ = json .Unmarshal (blob , & cc )
0 commit comments