synthdb 0.1.3

The Universal Database Seeder. Production-grade synthetic data generator for PostgreSQL. Zero config, context-aware.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<div align="center">

# πŸ¦€ SynthDB

### **The Universal Database Seeder**
#### Production-grade synthetic data. Zero config. Context-aware.

[![Crates.io](https://img.shields.io/crates/v/synthdb.svg)](https://crates.io/crates/synthdb)
[![Built with Rust](https://img.shields.io/badge/built_with-Rust-d33833.svg)](https://www.rust-lang.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.rs/synthdb)

[Features](#-features) β€’ [Quick Start](#-quick-start) β€’ [Examples](#-examples) β€’ [Contributing](#-contributing)

---

</div>

## πŸ“– Overview

**SynthDB** is a next-generation database seeding engine that reads your existing PostgreSQL schema and generates **statistically realistic, relational data** automatically.

Unlike traditional tools that generate random gibberish, SynthDB employs a **Deep Semantic Engine** to understand your data model's context and relationships, producing data that looks and feels real.

```sql
-- Instead of this garbage:
INSERT INTO users VALUES ('XJ9K2', 'asdf@qwerty', '99999', 'ZZZ');

-- SynthDB generates this:
INSERT INTO users VALUES ('John Doe', 'john.doe@techcorp.com', '+1-555-0142', 'San Francisco, CA');
```

---

## ✨ Features

### 🧠 **Deep Semantic Intelligence**

SynthDB understands the *meaning* of your columns, not just their types.

#### 🎯 Context-Aware Identity
If a table has `first_name`, `last_name`, and `email`, SynthDB ensures they match perfectly:
- **Name:** "Sarah Martinez"
- **Email:** "sarah.martinez@company.com"
- **Username:** "smartinez"

#### 🏷️ Smart Categorization
Automatically detects and generates valid data across multiple domains:

<table>
<tr>
<td width="50%">

**πŸ’° Finance**
- Credit Cards (valid Luhn)
- IBANs & Swift Codes
- Cryptocurrency Addresses
- Currency Codes & Amounts

**🌍 Geography**
- Coherent Addresses
- Cities ↔ States ↔ Zip Codes
- Latitude/Longitude Pairs
- Time Zones

**πŸ”¬ Science**
- Chemical Formulas
- DNA Sequences
- Medical/ICD Codes
- Laboratory Values

</td>
<td width="50%">

**πŸ’» Technology**
- IPv4 & IPv6 Addresses
- MAC Addresses
- User Agents
- File Paths & URLs

**🏒 Business**
- Company Names
- Job Titles
- Department Names
- Stock Tickers

**πŸ“± Personal**
- Phone Numbers
- Social Security Numbers
- Passport Numbers
- Driver's License IDs

</td>
</tr>
</table>

---

### πŸ”— **Referential Integrity**

#### πŸ“Š Topological Sort
Automatically analyzes foreign key dependencies and inserts data in the correct order:
```
Users β†’ Orders β†’ OrderItems β†’ Shipments
```

#### βœ… Zero Broken Links
Generated foreign keys **always** reference valid, existing parent rows. No orphaned records, ever.

```sql
-- Parent record created first
INSERT INTO customers (id, name) VALUES (1, 'Acme Corp');

-- Child record references existing parent
INSERT INTO orders (id, customer_id, total) VALUES (101, 1, 1299.99);
```

---

### πŸ›‘οΈ **Production Ready**

| Feature | Description |
|---------|-------------|
| **Strict Precision** | Respects `NUMERIC(10,2)`, `VARCHAR(15)`, and all constraint types |
| **Smart Nulls** | Intelligently applies NULL values to optional fields while keeping critical data populated |
| **Unique Constraints** | Guarantees uniqueness for columns with UNIQUE or PRIMARY KEY constraints |
| **Check Constraints** | Honors CHECK constraints and enum types |
| **Zero Configuration** | No YAML files, no mapping rules. Just point it at your database |
| **Performance** | Written in Rust πŸ¦€ for blazing-fast data generation |

---

## ⚑ Quick Start

### πŸ“₯ Installation

```bash
# Via Cargo
cargo install synthdb
```

### 🎯 Basic Usage

**Step 1:** Create a target database with your schema (tables must exist)

**Step 2:** Run SynthDB

```bash
synthdb clone \
  --url "postgres://user:pass@localhost:5432/my_staging_db" \
  --rows 1000 \
  --output seed.sql
```

**Step 3:** Apply the generated data

```bash
psql -d my_staging_db -f seed.sql
```

### πŸ”§ Advanced Options

```bash
# Generate data directly to database (no SQL file)
synthdb clone --url "postgres://..." --rows 5000 --execute

# Specify custom row counts per table
synthdb clone --url "postgres://..." --config counts.json

# Exclude specific tables
synthdb clone --url "postgres://..." --exclude "logs,temp_*"

# Set data locale
synthdb clone --url "postgres://..." --locale "en_GB"
```

---

## πŸ’‘ Examples

### 🎨 How SynthDB Handles Data

<table>
<thead>
<tr>
<th>Column Name</th>
<th>Generated Value</th>
<th>Logic</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>merchant_name</code></td>
<td><code>'Acme Corporation'</code></td>
<td>🏒 Detected Company entity</td>
</tr>
<tr>
<td><code>support_email</code></td>
<td><code>'support@acmecorp.com'</code></td>
<td>πŸ“§ Matched to Company Name</td>
</tr>
<tr>
<td><code>mac_address</code></td>
<td><code>'00:1A:2B:3C:4D:5E'</code></td>
<td>πŸ”§ Valid hexadecimal format</td>
</tr>
<tr>
<td><code>ipv6_address</code></td>
<td><code>'2001:0db8:85a3::8a2e:0370'</code></td>
<td>🌐 Valid IPv6 format</td>
</tr>
<tr>
<td><code>contract_value</code></td>
<td><code>45021.50</code></td>
<td>πŸ’― Respected <code>NUMERIC(10,2)</code></td>
</tr>
<tr>
<td><code>tracking_code</code></td>
<td><code>'TRK-9281-A02'</code></td>
<td>🎯 Semantic ID generation</td>
</tr>
<tr>
<td><code>audit_log_path</code></td>
<td><code>'/var/logs/audit/2024-11.log'</code></td>
<td>πŸ“ Context-aware file path</td>
</tr>
<tr>
<td><code>birth_date</code></td>
<td><code>'1985-06-15'</code></td>
<td>πŸŽ‚ Realistic age distribution</td>
</tr>
<tr>
<td><code>website_url</code></td>
<td><code>'https://acmecorp.com'</code></td>
<td>πŸ”— Matched to company domain</td>
</tr>
</tbody>
</table>

### πŸ—‚οΈ Real-World Schema Example

```sql
-- Your existing schema
CREATE TABLE companies (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    website VARCHAR(255),
    industry VARCHAR(50)
);

CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    company_id INTEGER REFERENCES companies(id),
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    phone VARCHAR(20),
    job_title VARCHAR(100),
    salary NUMERIC(10,2),
    hire_date DATE NOT NULL
);
```

**SynthDB generates:**

```sql
-- Coherent company data
INSERT INTO companies VALUES 
(1, 'TechVision Solutions', 'https://techvision.io', 'Software'),
(2, 'Global Logistics Inc', 'https://globallogistics.com', 'Transportation');

-- Employees with matching company context
INSERT INTO employees VALUES 
(1, 1, 'Alice', 'Chen', 'alice.chen@techvision.io', '+1-555-0123', 'Senior Software Engineer', 125000.00, '2022-03-15'),
(2, 1, 'Bob', 'Kumar', 'bob.kumar@techvision.io', '+1-555-0124', 'Product Manager', 135000.00, '2021-08-22'),
(3, 2, 'Carol', 'Rodriguez', 'carol.rodriguez@globallogistics.com', '+1-555-0198', 'Operations Director', 145000.00, '2020-01-10');
```

---

## πŸ—οΈ Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     SynthDB Engine                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  1. Schema Introspection                                β”‚
β”‚     └─ Read tables, columns, constraints, relationships β”‚
β”‚                                                          β”‚
β”‚  2. Dependency Analysis                                 β”‚
β”‚     └─ Build dependency graph via topological sort      β”‚
β”‚                                                          β”‚
β”‚  3. Semantic Classification                             β”‚
β”‚     └─ Detect column meaning from names & types         β”‚
β”‚                                                          β”‚
β”‚  4. Context-Aware Generation                            β”‚
β”‚     └─ Generate coherent, relational data               β”‚
β”‚                                                          β”‚
β”‚  5. Constraint Validation                               β”‚
β”‚     └─ Ensure all DB constraints are satisfied          β”‚
β”‚                                                          β”‚
β”‚  6. Output                                              β”‚
β”‚     └─ SQL file or direct database insertion            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ—ΊοΈ Roadmap

- [x] PostgreSQL support
- [x] Semantic column detection
- [x] Foreign key resolution
- [ ] MySQL/MariaDB support
- [ ] SQLite support
- [ ] Custom data providers
- [ ] GraphQL schema support
- [ ] Performance benchmarking suite
- [ ] Web UI for configuration
- [ ] Machine learning-based pattern detection

---

## 🀝 Contributing

We love Rustaceans! πŸ¦€ Contributions are welcome and appreciated.

### How to Contribute

1. **Fork the repository**
2. **Create a feature branch**
   ```bash
   git checkout -b feature/amazing-feature
   ```
3. **Make your changes**
   ```bash
   cargo fmt
   cargo clippy
   cargo test
   ```
4. **Commit your changes**
   ```bash
   git commit -m 'Add amazing feature'
   ```
5. **Push to your fork**
   ```bash
   git push origin feature/amazing-feature
   ```
6. **Open a Pull Request**

### Development Setup

```bash
# Clone the repository
git clone https://github.com/yourusername/synthdb.git
cd synthdb

# Build the project
cargo build

# Run tests
cargo test

# Run with example
cargo run -- clone --url "postgres://localhost/testdb" --rows 100
```

### Code of Conduct

Please read our [Code of Conduct](CODE_OF_CONDUCT.md) before contributing.

---


---

## πŸ™ Acknowledgments

Built with ❀️ using:
- [Rust]https://www.rust-lang.org/ - Systems programming language
- [Tokio]https://tokio.rs/ - Async runtime
- [SQLx]https://github.com/launchbadge/sqlx - Database toolkit
- [Fake]https://github.com/cksac/fake-rs - Data generation library

---

## πŸ“„ License

Distributed under the **MIT License**. See [LICENSE](LICENSE) for more information.

---

## πŸ’¬ Community & Support

- **Issues:** [GitHub Issues]https://github.com/synthdb/synthdb/issues
- **Discussions:** [GitHub Discussions]https://github.com/synthdb/synthdb/discussions

---

<div align="center">

**If SynthDB helps your project, consider giving it a ⭐ on GitHub!**

Made with πŸ¦€ by the SynthDB team

</div>