sing-ui/README.md

85 lines
3.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# sling-ui
一个本地运行的 Web UI把「测试环境 → 本地 dev 库」的数据同步流程自动化:
- **Schema 迁移**[Atlas](https://atlasgo.io)(表 / 索引 / 主外键约束)
- **数据迁移**[sling](https://slingdata.io)full-refresh / truncate / incremental / snapshot
第一阶段支持 MySQL / MariaDB / TiDB。
## 前置依赖
应用本身不内置迁移引擎,需要单独安装以下两个 CLI启动后顶部 banner 会检测是否可用):
- Node.js 20+ 与 pnpm
- **sling CLI**(数据迁移)。需要**官方构建**`conns discover` 在 OSS 自编译版不可用):
```bash
# Mac / Linux 一行安装(装到 ~/.sling/bin应用会自动探测该路径
curl -fsSL https://slingdata.io/install.sh | bash
# 或 Mac 用 brew
brew install slingdata-io/sling/sling
```
其他方式见 [sling 官方安装文档](https://docs.slingdata.io/sling-cli/getting-started)。
- **Atlas CLI**schema 迁移,社区版即可):
```bash
# Mac
brew install ariga/tap/atlas
# Linux
curl -sSf https://atlasgo.sh | sh
```
其他方式见 [Atlas 安装文档](https://atlasgo.io/getting-started#installation)。
不需要安装 docker 或 mysql 客户端Atlas 的 dev database 复用目标服务器上的 scratch schema`sling_ui_atlas_dev`),数据库连接全部走 sling/atlas 自带的驱动。
## 启动
```bash
pnpm install
pnpm dev # 或 pnpm build && pnpm start
```
打开 http://localhost:3000 。
## 使用流程
1. **Connections**:新建源(测试环境)和目标(本地 dev连接点「测试连接」确认可用。
2. **Pipelines → 新建流水线**:选源/目标连接、mode、是否开启 schema sync「加载表」勾选要迁移的表。
3. **流水线详情**
- 「Schema Diff 预览」查看 Atlas dry-run 生成的 DDL
- 「运行」执行迁移:先 `atlas schema apply`(同步表结构,含索引/约束),再 `sling run`(灌数据),日志实时流式展示。
4. **Runs**:全部运行历史与日志回放。
### mode 说明
- `schema_sync` 开启时Atlas 负责目标端表结构;此时即使选择 `full-refresh`,实际执行会翻译为 `truncate`(保留 Atlas 建的表结构重灌全量数据,避免 sling drop+重建丢掉索引/约束)。
- `incremental` 需要为每张表配置 `primary_key``update_key`
- sling 连接 URL 自动带 `foreign_key_checks=0`(会话级),避免外键顺序问题;约束定义本身保留。
- 连接支持自定义「连接参数」URL query stringsling/Atlas 均生效),流水线支持自定义「环境变量」(写入 replication 的 `env:`)。
## 已知问题
- TiDB 目标库报 `Error 8048: isolation level 'SERIALIZABLE' is not supported`:见 [docs/tidb-serializable-isolation.md](docs/tidb-serializable-isolation.md),给连接加参数 `tidb_skip_isolation_level_check=1` 即可。
## 数据与安全说明
- 所有应用数据在项目根 `data/` 目录(已 gitignoreSQLite`sling-ui.db`)、生成的 sling `env.yaml`、replication yaml、运行日志。
- **连接密码以明文存储在本地 SQLite**;运行日志中的命令行已做密码脱敏,但 sling/atlas 自身的输出可能仍含连接信息。本工具定位为本地单人使用,请勿暴露到网络。
- Atlas 需要一个 dev database 做 schema 规范化:实现为在**目标服务器**上创建专用 scratch schema `sling_ui_atlas_dev`(自动创建,保持干净),不依赖 docker。
- sling 使用应用自管的 home 目录(`data/sling-home`),不会读写你的 `~/.sling`
## 技术栈
Next.js 16App Router+ TypeScript + Tailwind 4 + shadcn/ui + better-sqlite3通过 shell 调用 sling / atlas 二进制,`SLING_LOGGING=JSON` 解析结构化日志SSE 实时推送。
## 路线图
- PostgreSQL 支持(连接类型 + pg_dump/Atlas 均已抽象)
- 流水线编辑 UI、定时调度、运行并发队列