lepao_proxy_pool.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. -- 乐跑出站代理池 + 全局配置 + lepao_account.assigned_proxy_id
  2. -- MySQL:请使用有 DDL 权限的账号执行;重复执行会使用 INFORMATION_SCHEMA 跳过已存在对象。
  3. CREATE TABLE IF NOT EXISTS lepao_proxy_pool (
  4. id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  5. host VARCHAR(128) NOT NULL,
  6. port INT UNSIGNED NOT NULL,
  7. scheme VARCHAR(16) NOT NULL DEFAULT 'http',
  8. is_active TINYINT NOT NULL DEFAULT 1,
  9. latency_ms INT UNSIGNED DEFAULT NULL,
  10. last_check_at BIGINT DEFAULT NULL,
  11. last_error VARCHAR(255) DEFAULT NULL,
  12. source VARCHAR(32) NOT NULL DEFAULT 'manual',
  13. remark VARCHAR(255) DEFAULT NULL,
  14. created_at BIGINT NOT NULL,
  15. updated_at BIGINT NOT NULL,
  16. PRIMARY KEY (id),
  17. UNIQUE KEY uniq_host_port (host, port),
  18. KEY idx_is_active (is_active),
  19. KEY idx_last_check_at (last_check_at)
  20. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  21. CREATE TABLE IF NOT EXISTS lepao_proxy_global (
  22. id TINYINT NOT NULL,
  23. random_proxy_enabled TINYINT NOT NULL DEFAULT 0,
  24. import_url VARCHAR(1024) NOT NULL,
  25. probe_target_url VARCHAR(1024) NOT NULL DEFAULT 'https://www.baidu.com',
  26. check_timeout_ms INT UNSIGNED NOT NULL DEFAULT 8000,
  27. check_concurrency INT UNSIGNED NOT NULL DEFAULT 10,
  28. created_at BIGINT NOT NULL,
  29. updated_at BIGINT NOT NULL,
  30. PRIMARY KEY (id)
  31. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  32. INSERT INTO lepao_proxy_global (
  33. id,
  34. random_proxy_enabled,
  35. import_url,
  36. probe_target_url,
  37. check_timeout_ms,
  38. check_concurrency,
  39. created_at,
  40. updated_at
  41. )
  42. SELECT
  43. 1,
  44. 0,
  45. 'http://api.89ip.cn/tqdl.html?api=1&num=60&port=&address=%E9%87%8D%E5%BA%86&isp=',
  46. 'https://www.baidu.com',
  47. 8000,
  48. 10,
  49. UNIX_TIMESTAMP() * 1000,
  50. UNIX_TIMESTAMP() * 1000
  51. WHERE NOT EXISTS (
  52. SELECT 1 FROM lepao_proxy_global WHERE id = 1
  53. );
  54. -- 下面三条为“首次执行”版本,兼容 MySQL 5.7/8.0。
  55. -- 若提示已存在(重复列/索引/外键),可忽略对应报错继续执行后续语句。
  56. ALTER TABLE lepao_account
  57. ADD COLUMN assigned_proxy_id BIGINT UNSIGNED NULL;
  58. ALTER TABLE lepao_account
  59. ADD INDEX idx_assigned_proxy_id (assigned_proxy_id);
  60. ALTER TABLE lepao_account
  61. ADD CONSTRAINT fk_lepao_account_proxy_id
  62. FOREIGN KEY (assigned_proxy_id)
  63. REFERENCES lepao_proxy_pool(id)
  64. ON DELETE SET NULL
  65. ON UPDATE RESTRICT;