schema-seed 0.1.3 → 0.1.4

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 +85 -102
  2. package/package.json +9 -9
package/README.md CHANGED
@@ -18,67 +18,53 @@ A production-ready tool to seed your database with realistic, deterministic data
18
18
  npm install -g schema-seed
19
19
  ```
20
20
 
21
- ## Quick Start
21
+ ## Supported Databases
22
22
 
23
- ### Seed All Tables
23
+ | Database | Adapter Package | Connection String Example |
24
+ | :--- | :--- | :--- |
25
+ | **PostgreSQL** | `schema-seed-adapter-postgres` | `postgres://user:pass@localhost:5432/db` |
26
+ | **MySQL** | `schema-seed-adapter-mysql` | `mysql://user:pass@localhost:3306/db` |
27
+ | **SQLite** | `schema-seed-adapter-sqlite` | `sqlite://path/to/database.db` |
28
+ | **SQL Server** | `schema-seed-adapter-mssql` | `sqlserver://user:pass@localhost:1433?database=db` |
29
+ | **Oracle** | `schema-seed-adapter-oracle` | `oracle://user:pass@localhost:1521/service_name` |
30
+ | **MongoDB** | `schema-seed-adapter-mongodb` | `mongodb://localhost:27017/db` |
31
+
32
+ ---
33
+
34
+ ## Database-Specific Usage
35
+
36
+ ### 🐘 PostgreSQL
37
+ Seed all tables in a Postgres database:
24
38
  ```bash
25
- schema-seed seed --db "postgres://user:pass@localhost:5432/mydb" --all
39
+ schema-seed seed --db "postgres://postgres:password@localhost:5432/my_db" --all
26
40
  ```
27
41
 
28
- ### Seed Specific Table
42
+ ### 🐬 MySQL
43
+ Seed 50 rows into the `users` table:
29
44
  ```bash
30
- schema-seed seed --db "mysql://user:pass@localhost:3306/mydb" --table users --rows 50
45
+ schema-seed seed --db "mysql://root:password@127.0.0.1:3306/my_db" --table users --rows 50
31
46
  ```
32
47
 
33
- ### Seed with Parents
34
- Automatically seeds parent tables required by foreign keys:
48
+ ### 📁 SQLite
49
+ Seed a local SQLite file:
35
50
  ```bash
36
- schema-seed seed --db "sqlite://data.db" --table orders --with-parents
51
+ schema-seed seed --db "sqlite://./dev.db" --all
37
52
  ```
38
53
 
39
- ### Deterministic Seeding
40
- Generate the same data every time:
54
+ ### 🏢 Microsoft SQL Server (MSSQL)
55
+ Seed with identity insert support:
41
56
  ```bash
42
- schema-seed seed --db "postgres://localhost/db" --all --seed "my-fixed-seed"
57
+ schema-seed seed --db "sqlserver://sa:Password123!@localhost:1433?database=master" --all
43
58
  ```
44
59
 
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
- });
60
+ ### 🔴 Oracle
61
+ Seed an Oracle database:
62
+ ```bash
63
+ schema-seed seed --db "oracle://system:password@localhost:1521/xe" --all
75
64
  ```
76
65
 
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
66
+ ### 🍃 MongoDB (Config-Based)
67
+ Since MongoDB is schema-less, you must define your collection structures in a `seed.config.ts` file.
82
68
 
83
69
  ```typescript
84
70
  // seed.config.ts
@@ -86,83 +72,80 @@ import { defineConfig } from 'schema-seed';
86
72
 
87
73
  export default defineConfig({
88
74
  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
75
  mongodb: {
92
76
  uri: "mongodb://localhost:27017/appdb",
93
-
94
77
  collections: {
95
78
  users: {
96
- rows: 200,
79
+ rows: 100,
97
80
  fields: {
98
81
  _id: "objectId",
99
82
  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"
83
+ name: "fullName",
84
+ age: { type: "int", min: 18, max: 99 }
130
85
  }
131
86
  }
132
87
  }
133
88
  }
134
89
  });
135
90
  ```
91
+ Then run:
92
+ ```bash
93
+ schema-seed seed
94
+ ```
136
95
 
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.
96
+ ---
144
97
 
98
+ ## Advanced Configuration (`seed.config.ts`)
145
99
 
146
- ## Safety Features
100
+ For complex seeding logic, create a `seed.config.ts` in your project root.
147
101
 
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
- ```
102
+ ```typescript
103
+ import { defineConfig } from 'schema-seed';
153
104
 
154
- ## Supported Adapters
105
+ export default defineConfig({
106
+ db: "postgres://localhost/mydb",
107
+ rows: 10,
108
+ overrides: {
109
+ users: {
110
+ // Custom function
111
+ email: ({ i }) => `user${i}@example.com`,
112
+ // Weighted enum (95% active, 5% blocked)
113
+ status: { enum: ["active", "blocked"], weights: [95, 5] },
114
+ // Date range
115
+ created_at: { dateBetween: ["2024-01-01", "2025-12-31"] },
116
+ // Constant value
117
+ role: 'user'
118
+ }
119
+ },
120
+ hooks: {
121
+ beforeInsert: async (table, rows) => {
122
+ console.log(`Seeding ${table}...`);
123
+ return rows;
124
+ }
125
+ }
126
+ });
127
+ ```
155
128
 
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`
129
+ ## CLI Reference
130
+
131
+ | Flag | Description | Default |
132
+ | :--- | :--- | :--- |
133
+ | `--db <url>` | Database connection string | - |
134
+ | `--dbType <type>` | Force database type (postgres, mysql, etc.) | Auto-inferred |
135
+ | `--all` | Seed all discovered tables | `true` |
136
+ | `--table <names...>` | Seed specific tables only | - |
137
+ | `--rows <n>` | Number of rows per table | `10` |
138
+ | `--seed <string>` | Fixed seed for deterministic data | Random |
139
+ | `--dry-run` | Preview changes without writing to DB | `false` |
140
+ | `--truncate` | Delete all data from tables before seeding | `false` |
141
+ | `--with-parents` | Automatically seed required parent tables | `false` |
142
+ | `--confirm <str>` | Require a confirmation string (for safety) | - |
143
+ | `--allow-production`| Allow running against production hosts | `false` |
162
144
 
163
- ## Contributing
145
+ ## Safety Features
164
146
 
165
- Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to get involved.
147
+ - **Production Detection**: The tool will refuse to run if the database host looks like a production environment (e.g., `aws.com`, `rds.com`) or if `NODE_ENV=production`, unless the `--allow-production` flag is provided.
148
+ - **Confirmation**: Use `--confirm "YES"` to force a manual confirmation step before seeding.
166
149
 
167
150
  ## License
168
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-seed",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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.3",
44
- "schema-seed-generators": "0.1.3"
43
+ "schema-seed-core": "0.1.4",
44
+ "schema-seed-generators": "0.1.4"
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.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"
51
+ "schema-seed-adapter-mongodb": "0.1.4",
52
+ "schema-seed-adapter-mysql": "0.1.4",
53
+ "schema-seed-adapter-postgres": "0.1.4",
54
+ "schema-seed-adapter-sqlite": "0.1.4",
55
+ "schema-seed-adapter-mssql": "0.1.4",
56
+ "schema-seed-adapter-oracle": "0.1.4"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",