-- Run once after deploying the agent-name-only API change.
-- This keeps the legacy NOT NULL agent_code column populated, but prevents it
-- from being equal to agent_name so user_agent cannot authenticate by code.

UPDATE tb_agent
SET agent_code = CONCAT('legacy_', id, '_', SUBSTRING(MD5(CONCAT(id, agent_name, secret_key)), 1, 12))
WHERE agent_code = agent_name;
