Spaces:
Sleeping
Sleeping
docs: merge professional visuals with detailed technical specs for ultimate README
Browse files
README.md
CHANGED
|
@@ -15,14 +15,38 @@ pinned: false
|
|
| 15 |
[](https://opensource.org/licenses/MIT)
|
| 16 |
[](https://huggingface.co/spaces/Eishaan/sql-migration-env)
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
---
|
| 21 |
|
| 22 |
## ποΈ Architecture Overview
|
| 23 |
|
| 24 |
-
The
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
```mermaid
|
| 27 |
sequenceDiagram
|
| 28 |
participant Agent
|
|
@@ -53,83 +77,83 @@ sequenceDiagram
|
|
| 53 |
|
| 54 |
## π― Benchmark Tasks
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
| 59 |
-
|
|
| 60 |
-
|
|
| 61 |
-
|
|
| 62 |
-
|
|
| 63 |
-
|
|
| 64 |
-
|
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
---
|
| 69 |
|
| 70 |
-
## βοΈ
|
| 71 |
-
|
| 72 |
-
The benchmark uses a **Dynamic Golden Database Grader**. Instead of string-matching SQL, we compare the *final state* of the agent's database against a "perfectly migrated" reference database.
|
| 73 |
-
|
| 74 |
-
### The Reward Formula
|
| 75 |
-
Rewards are sparse/dense deltas calculated at every step:
|
| 76 |
-
|
| 77 |
-
$$R_t = P_t - P_{t-1}$$
|
| 78 |
|
| 79 |
-
|
| 80 |
-
-
|
| 81 |
-
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
---
|
| 86 |
|
| 87 |
-
## π‘οΈ Security &
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
- **
|
| 93 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
---
|
| 96 |
|
| 97 |
-
## π
|
| 98 |
|
| 99 |
-
### Local Deployment
|
| 100 |
```bash
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
cd sql-migration-env
|
| 104 |
-
|
| 105 |
-
# Build and run
|
| 106 |
-
docker build -t sql-migration-env .
|
| 107 |
-
docker run -p 7860:7860 sql-migration-env
|
| 108 |
```
|
| 109 |
|
| 110 |
-
###
|
| 111 |
```bash
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
```
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
- **Avg. Benchmark Score:** 0.83 (Production ready)
|
| 122 |
-
- **Task Success Rates:**
|
| 123 |
-
- Easy: 0.99
|
| 124 |
-
- Medium: 0.82
|
| 125 |
-
- Hard: 0.60
|
| 126 |
|
| 127 |
---
|
| 128 |
|
| 129 |
-
## πΌοΈ Observations
|
| 130 |
-
Each observation includes
|
| 131 |
-
|
| 132 |
-
---
|
| 133 |
|
| 134 |
## π License
|
| 135 |
-
|
|
|
|
| 15 |
[](https://opensource.org/licenses/MIT)
|
| 16 |
[](https://huggingface.co/spaces/Eishaan/sql-migration-env)
|
| 17 |
|
| 18 |
+
An OpenEnv-compatible environment for evaluating AI agents on autonomous SQLite database migration tasks. The agent receives a broken/drifted schema and must write SQL to transform it to a target state without losing data.
|
| 19 |
|
| 20 |
---
|
| 21 |
|
| 22 |
## ποΈ Architecture Overview
|
| 23 |
|
| 24 |
+
The suite combines formal sequence modeling with a modular local engine.
|
| 25 |
|
| 26 |
+
### System Mapping
|
| 27 |
+
```
|
| 28 |
+
βββββββββββββββββββββββββββββββββββ
|
| 29 |
+
β inference.py (Baseline Agent) β
|
| 30 |
+
β - LLM API calls (OpenAI fmt) β
|
| 31 |
+
β - JSON mode + fallback parser β
|
| 32 |
+
βββββββββββ¬ββββββββββββββββββββββββ
|
| 33 |
+
β MigrationAction
|
| 34 |
+
βββββββββββΌββββββββββββββββββββββββ
|
| 35 |
+
β environment.py (OpenEnv Env) β
|
| 36 |
+
β - SQLite execution engine β
|
| 37 |
+
β - ERD & Schema Diff generator β
|
| 38 |
+
β - SQL timeout & Blacklist β
|
| 39 |
+
βββββββββββ¬ββββββββββββββββββββββββ
|
| 40 |
+
β score()
|
| 41 |
+
βββββββββββΌββββββββββββββββββββββββ
|
| 42 |
+
β grader.py (Golden DB Engine) β
|
| 43 |
+
β - Dynamic golden reference DB β
|
| 44 |
+
β - Schema + data + FK scoring β
|
| 45 |
+
β - Anti-exploit checks β
|
| 46 |
+
βββββββββββββββββββββββββββββββββββ
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### Protocol Flow
|
| 50 |
```mermaid
|
| 51 |
sequenceDiagram
|
| 52 |
participant Agent
|
|
|
|
| 77 |
|
| 78 |
## π― Benchmark Tasks
|
| 79 |
|
| 80 |
+
| # | Task | Difficulty | Challenge |
|
| 81 |
+
|---|------|-----------|-----------|
|
| 82 |
+
| 1 | `column-restructure` | π’ Easy | Merge first_name + last_name β full_name (with apostrophes) |
|
| 83 |
+
| 2 | `soft-delete-restoration` | π’ Easy | Restore deleted products from `deletion_log` |
|
| 84 |
+
| 3 | `table-normalization` | π‘ Medium | Normalize `purchases` β `customers` + `orders` + FK |
|
| 85 |
+
| 4 | `schema-version-merge` | π‘ Medium | Merge v1/v2 product tables with price coercion |
|
| 86 |
+
| 5 | `multi-entity-extraction` | π‘ Medium | 3NF decomposition with invalid data routing |
|
| 87 |
+
| 6 | `cascade-migration` | π΄ Hard | 4-table FK cascade, type coercion, orphan audit |
|
| 88 |
+
| 7 | `dual-source-consolidation`| π΄ Hard | 6β4 table merge, cross-system email dedup |
|
| 89 |
+
|
| 90 |
+
### π οΈ Adversarial Edge Cases (The "Stress Tests")
|
| 91 |
+
- **O'Brien**: Apostrophe in data β tests SQL escaping and string literal handling.
|
| 92 |
+
- **$90,000 salary**: TEXTβINTEGER coercion β tests complex string parsing and casting.
|
| 93 |
+
- **Empty string emails**: NOT NULL vs Empty β tests data quality validation logic.
|
| 94 |
+
- **Leading whitespace**: ` alice@company.com` β tests TRIM awareness.
|
| 95 |
+
- **ID conflicts**: Overlapping IDs in dual sources β tests intelligent merge logic.
|
| 96 |
+
- **Orphaned FKs**: References to deleted entities β tests environment's audit logging.
|
| 97 |
+
- **NULL currency**: Must default to 'USD' β tests COALESCE usage.
|
| 98 |
|
| 99 |
---
|
| 100 |
|
| 101 |
+
## βοΈ Evaluation Baselines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
| Task | Qwen 32B Score | GPT-OSS 120B |
|
| 104 |
+
|------|--------------|--------------|
|
| 105 |
+
| `column-restructure` | 0.99 | 0.99 |
|
| 106 |
+
| `soft-delete-restoration` | 0.99 | 0.99 |
|
| 107 |
+
| `table-normalization` | 0.94 | 0.99 |
|
| 108 |
+
| `schema-version-merge` | 0.93 | 0.98 |
|
| 109 |
+
| `multi-entity-extraction` | 0.35 | 0.65 |
|
| 110 |
+
| `cascade-migration` | 0.61 | 0.83 |
|
| 111 |
+
| `dual-source-consolidation`| 0.28 | 0.38 |
|
| 112 |
|
| 113 |
---
|
| 114 |
|
| 115 |
+
## π‘οΈ Security & Reward Function
|
| 116 |
|
| 117 |
+
### The Reward Formula
|
| 118 |
+
Rewards are calculated as progress deltas: $R_t = P_t - P_{t-1}$.
|
| 119 |
+
Progress $P_t$ is a weighted sum (0.01 to 0.99):
|
| 120 |
+
- **Schema Match (30%)**: Tables exist with correct `(name, type)` signatures.
|
| 121 |
+
- **Data Match (40%)**: Row content matches golden DB (order-independent).
|
| 122 |
+
- **FK & Integrity (20%)**: Foreign keys enforced, `integrity_check` passes.
|
| 123 |
+
- **Anti-Exploit (10%)**: Penalty for empty tables or schema pollution.
|
| 124 |
+
|
| 125 |
+
### Security Guardrails
|
| 126 |
+
- **PRAGMA Blacklist**: `foreign_keys = OFF` and `writable_schema = ON` are blocked.
|
| 127 |
+
- **Query Timeout**: SQLite progress handler terminates queries exceeding 500k ops.
|
| 128 |
+
- **Dangerous SQL**: `ATTACH`, `DETACH`, and `LOAD_EXTENSION` are filtered.
|
| 129 |
|
| 130 |
---
|
| 131 |
|
| 132 |
+
## π Setup & Usage
|
| 133 |
|
| 134 |
+
### Local Deployment
|
| 135 |
```bash
|
| 136 |
+
pip install -r requirements.txt
|
| 137 |
+
python -m server.app # Starts OpenEnv server on port 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
```
|
| 139 |
|
| 140 |
+
### Environment Variables
|
| 141 |
```bash
|
| 142 |
+
export HF_TOKEN=your_token
|
| 143 |
+
export API_BASE_URL=https://router.huggingface.co/v1
|
| 144 |
+
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
|
| 145 |
```
|
| 146 |
|
| 147 |
+
### API Endpoints
|
| 148 |
+
- `POST /reset`: Initialize migration episode.
|
| 149 |
+
- `POST /step`: Execute SQL and reasoning.
|
| 150 |
+
- `GET /tasks`: List all available scenarios.
|
| 151 |
+
- `POST /grader`: Run deep comparison against Golden DB.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
---
|
| 154 |
|
| 155 |
+
## πΌοΈ Observations
|
| 156 |
+
Each observation includes `erd_visualization` (Mermaid.js) and `schema_diff` to assist agents in understanding the current drift.
|
|
|
|
|
|
|
| 157 |
|
| 158 |
## π License
|
| 159 |
+
MIT. Built for the **OpenEnv Hackathon 2026**.
|