schema-seed 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +166 -2
  2. package/package.json +9 -9
package/README.md CHANGED
@@ -1,5 +1,169 @@
1
1
  # schema-seed
2
2
 
3
- Part of the [schema-seed](https://github.com/AliNazar-111/schema-seed) project.
3
+ A production-ready tool to seed your database with realistic, deterministic data. `schema-seed` automatically introspects your database schema, resolves foreign key dependencies, and generates semantic data using a powerful inference engine.
4
4
 
5
- For full documentation and usage, please visit the [main repository](https://github.com/AliNazar-111/schema-seed).
5
+ ## Features
6
+
7
+ - **Multi-database support**: Native adapters for Postgres, MySQL, SQLite, MSSQL, Oracle, and MongoDB.
8
+ - **Dependency Resolution**: Automatically calculates the correct insertion order based on foreign keys.
9
+ - **Semantic Inference**: Intelligently chooses generators based on column names and types (e.g., `email`, `first_name`, `created_at`).
10
+ - **Deterministic**: Use a fixed seed to generate the exact same data every time.
11
+ - **Extensible**: Powerful override system, lifecycle hooks, and a plugin architecture.
12
+ - **Safety First**: Production environment detection and mandatory confirmation flags.
13
+ - **Redaction**: Sensitive data (passwords, tokens) is automatically redacted from reports.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install -g schema-seed
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Seed All Tables
24
+ ```bash
25
+ schema-seed seed --db "postgres://user:pass@localhost:5432/mydb" --all
26
+ ```
27
+
28
+ ### Seed Specific Table
29
+ ```bash
30
+ schema-seed seed --db "mysql://user:pass@localhost:3306/mydb" --table users --rows 50
31
+ ```
32
+
33
+ ### Seed with Parents
34
+ Automatically seeds parent tables required by foreign keys:
35
+ ```bash
36
+ schema-seed seed --db "sqlite://data.db" --table orders --with-parents
37
+ ```
38
+
39
+ ### Deterministic Seeding
40
+ Generate the same data every time:
41
+ ```bash
42
+ schema-seed seed --db "postgres://localhost/db" --all --seed "my-fixed-seed"
43
+ ```
44
+
45
+ ## Configuration (`seed.config.ts`)
46
+
47
+ For advanced usage, create a `seed.config.ts` in your project root.
48
+
49
+ ```typescript
50
+ import { defineConfig } from 'schema-seed';
51
+
52
+ export default defineConfig({
53
+ db: "postgres://localhost/mydb",
54
+ rows: 10,
55
+ overrides: {
56
+ users: {
57
+ // Custom logic
58
+ email: ({ i }) => `user${i}@example.com`,
59
+ // Weighted enum
60
+ status: { enum: ["active", "blocked"], weights: [95, 5] },
61
+ // Date range
62
+ created_at: { dateBetween: ["2024-01-01", "2025-12-31"] },
63
+ // Literal value
64
+ role: 'user'
65
+ }
66
+ },
67
+ hooks: {
68
+ beforeInsert: async (table, rows) => {
69
+ console.log(`Preparing ${rows.length} rows for ${table}`);
70
+ return rows;
71
+ }
72
+ },
73
+ plugins: ["@schema-seed/plugin-ecommerce"]
74
+ });
75
+ ```
76
+
77
+ ## MongoDB Seeding (Config-Based)
78
+
79
+ `schema-seed` supports MongoDB seeding exclusively through a `seed.config.ts` file. Since MongoDB is schema-less, you must define the structure of the documents you want to generate.
80
+
81
+ ### Example Configuration
82
+
83
+ ```typescript
84
+ // seed.config.ts
85
+ import { defineConfig } from 'schema-seed';
86
+
87
+ export default defineConfig({
88
+ dbType: "mongodb",
89
+ seed: 123, // Deterministic random seed
90
+ // The seed option controls how random data is generated. When a seed value is provided (for example seed: 123), Schema-Seed will generate the same data every time you run the seeder with the same configuration. This makes database seeding deterministic and reproducible, which is especially useful for team environments, CI pipelines, debugging, and demos. Changing the seed value will produce a different, but still consistent, dataset. If no seed is provided, the generated data will be random on each run.
91
+ mongodb: {
92
+ uri: "mongodb://localhost:27017/appdb",
93
+
94
+ collections: {
95
+ users: {
96
+ rows: 200,
97
+ fields: {
98
+ _id: "objectId",
99
+ email: { type: "email", unique: true },
100
+ firstName: "firstName",
101
+ lastName: "lastName",
102
+ age: { type: "int", min: 18, max: 65 },
103
+ status: {
104
+ type: "enum",
105
+ values: ["active", "blocked"],
106
+ weights: [95, 5]
107
+ },
108
+ profile: {
109
+ type: "object",
110
+ fields: {
111
+ city: "city",
112
+ country: "country"
113
+ }
114
+ },
115
+ createdAt: {
116
+ type: "dateBetween",
117
+ from: "2024-01-01",
118
+ to: "2025-12-31"
119
+ }
120
+ }
121
+ },
122
+
123
+ orders: {
124
+ rows: 500,
125
+ fields: {
126
+ _id: "objectId",
127
+ userId: { ref: "users._id" }, // Reference to another collection
128
+ total: { type: "decimal", min: 5, max: 500 },
129
+ createdAt: "dateRecent"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ });
135
+ ```
136
+
137
+ ### Key Features
138
+
139
+ - **References**: Use `{ ref: "collection.field" }` to link documents across collections. `schema-seed` automatically calculates the correct insertion order.
140
+ - **Nested Objects**: Define complex structures using the `object` type and a nested `fields` map.
141
+ - **Arrays**: Use the `array` type with `of` to generate lists of values.
142
+ - **Deterministic**: Provide a `seed` at the top level to ensure the same data is generated every time.
143
+ - **Safety**: Production detection prevents accidental seeding of live databases unless `--allow-production` is used.
144
+
145
+
146
+ ## Safety Features
147
+
148
+ - **Production Check**: Refuses to run if `NODE_ENV=production` or if the DB host looks like production. Use `--allow-production` to override.
149
+ - **Confirmation**: Require a typed string to proceed.
150
+ ```bash
151
+ schema-seed seed --db "postgres://prod-db/db" --allow-production --confirm "SEED_PROD"
152
+ ```
153
+
154
+ ## Supported Adapters
155
+
156
+ - `schema-seed-adapter-postgres`
157
+ - `schema-seed-adapter-mysql`
158
+ - `schema-seed-adapter-sqlite`
159
+ - `schema-seed-adapter-mssql`
160
+ - `schema-seed-adapter-oracle`
161
+ - `schema-seed-adapter-mongodb`
162
+
163
+ ## Contributing
164
+
165
+ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to get involved.
166
+
167
+ ## License
168
+
169
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-seed",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "CLI for schema-seed",
6
6
  "author": "Ali Nazar",
@@ -40,20 +40,20 @@
40
40
  "commander": "^12.1.0",
41
41
  "dotenv": "^17.2.3",
42
42
  "jiti": "^2.6.1",
43
- "schema-seed-core": "0.1.1",
44
- "schema-seed-generators": "0.1.1"
43
+ "schema-seed-core": "0.1.3",
44
+ "schema-seed-generators": "0.1.3"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^20.19.27",
48
48
  "tsup": "^8.3.5",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^2.1.8",
51
- "schema-seed-adapter-mongodb": "0.1.1",
52
- "schema-seed-adapter-mysql": "0.1.1",
53
- "schema-seed-adapter-postgres": "0.1.1",
54
- "schema-seed-adapter-sqlite": "0.1.1",
55
- "schema-seed-adapter-mssql": "0.1.1",
56
- "schema-seed-adapter-oracle": "0.1.1"
51
+ "schema-seed-adapter-mongodb": "0.1.3",
52
+ "schema-seed-adapter-mysql": "0.1.3",
53
+ "schema-seed-adapter-postgres": "0.1.3",
54
+ "schema-seed-adapter-sqlite": "0.1.3",
55
+ "schema-seed-adapter-mssql": "0.1.3",
56
+ "schema-seed-adapter-oracle": "0.1.3"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",