sing-ui/README.md

57 lines
2.9 KiB
Markdown
Raw 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。
## 前置依赖
- Node.js 20+ 与 pnpm
- `sling` CLI`curl -LO 'https://github.com/slingdata-io/sling-cli/releases/latest/download/sling_darwin_arm64.tar.gz' ...`,见官方文档;需要官方构建,`conns discover` 在 OSS 自编译版不可用)
- `atlas` CLI`brew install ariga/tap/atlas`
启动后应用会在顶部 banner 检测这两个二进制是否可用。
## 启动
```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`(会话级),避免外键顺序问题;约束定义本身保留。
## 数据与安全说明
- 所有应用数据在项目根 `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、定时调度、运行并发队列