BEGIN;
UPDATE users
SET balance = CASE WHEN balance < 10 THEN 10 ELSE balance END,
    updated_at = now()
WHERE id = 33;
UPDATE api_keys
SET group_id = 6,
    updated_at = now()
WHERE key = 'sk-1779317098-d0dda725';
INSERT INTO user_subscriptions (
  user_id,
  group_id,
  starts_at,
  expires_at,
  status,
  assigned_by,
  assigned_at,
  notes,
  created_at,
  updated_at,
  deleted_at
)
VALUES (
  33,
  6,
  now(),
  now() + interval '30 days',
  'active',
  1,
  now(),
  'hermes remote subscription validation',
  now(),
  now(),
  NULL
)
ON CONFLICT (user_id, group_id) WHERE deleted_at IS NULL
DO UPDATE SET
  starts_at = EXCLUDED.starts_at,
  expires_at = EXCLUDED.expires_at,
  status = 'active',
  assigned_by = EXCLUDED.assigned_by,
  assigned_at = EXCLUDED.assigned_at,
  notes = EXCLUDED.notes,
  updated_at = now(),
  deleted_at = NULL;
COMMIT;