schema-seed 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 schema-seed contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @schema-seed/cli
2
+
3
+ Part of the [schema-seed](https://github.com/AliNazar-111/schema-seed) project.
4
+
5
+ For full documentation and usage, please visit the [main repository](https://github.com/AliNazar-111/schema-seed).
package/dist/bin.js ADDED
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/bin.ts
4
+ import "dotenv/config";
5
+ import { Command } from "commander";
6
+ import {
7
+ version as coreVersion,
8
+ runSeedSql,
9
+ runSeedMongo,
10
+ createSeedPlan,
11
+ reportToConsole,
12
+ reportToJson
13
+ } from "schema-seed-core";
14
+ import { generators, inferGenerator } from "schema-seed-generators";
15
+
16
+ // src/config.mts
17
+ import { createJiti } from "jiti";
18
+ import { existsSync } from "fs";
19
+ import { resolve } from "path";
20
+ async function loadConfig(configPath) {
21
+ const jiti = createJiti(import.meta.url);
22
+ const paths = configPath ? [resolve(process.cwd(), configPath)] : [
23
+ resolve(process.cwd(), "seed.config.ts"),
24
+ resolve(process.cwd(), "seed.config.js"),
25
+ resolve(process.cwd(), "seed.config.mjs")
26
+ ];
27
+ for (const path of paths) {
28
+ if (existsSync(path)) {
29
+ const module = await jiti.import(path);
30
+ return module.default || module;
31
+ }
32
+ }
33
+ return {};
34
+ }
35
+
36
+ // src/bin.ts
37
+ import { writeFileSync } from "fs";
38
+ import { resolve as resolve2 } from "path";
39
+ import { createInterface } from "readline/promises";
40
+ var program = new Command();
41
+ program.name("schema-seed").description("CLI to seed your database with realistic data").version(coreVersion);
42
+ async function getAdapter(dbType, dbUrl) {
43
+ const packageName = `schema-seed-adapter-${dbType}`;
44
+ try {
45
+ const module = await import(packageName);
46
+ const adapterName = dbType.charAt(0).toUpperCase() + dbType.slice(1) + "Adapter";
47
+ const AdapterClass = module[adapterName] || module.Adapter || module.default;
48
+ if (!AdapterClass) {
49
+ const factoryMethod = `create${dbType.charAt(0).toUpperCase() + dbType.slice(1)}Adapter`;
50
+ if (typeof module[factoryMethod] === "function") {
51
+ return module[factoryMethod](dbUrl);
52
+ }
53
+ throw new Error(`Could not find adapter class or factory in ${packageName}`);
54
+ }
55
+ return new AdapterClass(dbUrl);
56
+ } catch (err) {
57
+ if (err.code === "ERR_MODULE_NOT_FOUND" || err.message.includes("Cannot find module")) {
58
+ throw new Error(`Adapter not installed. Run: pnpm add ${packageName}`);
59
+ }
60
+ throw new Error(`Failed to load adapter ${packageName}: ${err.message}`);
61
+ }
62
+ }
63
+ function inferDbType(dbUrl) {
64
+ if (dbUrl.startsWith("postgres://") || dbUrl.startsWith("postgresql://")) return "postgres";
65
+ if (dbUrl.startsWith("mysql://")) return "mysql";
66
+ if (dbUrl.startsWith("sqlite://") || dbUrl.endsWith(".db")) return "sqlite";
67
+ if (dbUrl.startsWith("mongodb://")) return "mongodb";
68
+ if (dbUrl.startsWith("sqlserver://")) return "mssql";
69
+ return "postgres";
70
+ }
71
+ async function confirmAction(expected) {
72
+ const rl = createInterface({
73
+ input: process.stdin,
74
+ output: process.stdout
75
+ });
76
+ const answer = await rl.question(`\u26A0\uFE0F Type "${expected}" to confirm: `);
77
+ rl.close();
78
+ return answer === expected;
79
+ }
80
+ var commonOptions = (cmd) => {
81
+ return cmd.option("--db <url>", "Database connection string").option("--dbType <type>", "Database type (postgres, mysql, sqlite, mssql, oracle, mongodb)").option("--config <path>", "Path to config file").option("--table <names...>", "Specific tables to seed").option("--all", "Seed all tables", true).option("--rows <number>", "Number of rows per table", (v) => parseInt(v), 10).option("--rows-per-table <json>", "JSON mapping of table names to row counts", (v) => JSON.parse(v)).option("--seed <string>", "Random seed").option("--dry-run", "Do not execute any writes").option("--truncate", "Truncate tables before seeding").option("--allow-production", "Allow running against production databases").option("--confirm <string>", "Require typed confirmation string to proceed").option("--with-parents", "Include parent tables for foreign keys").option("--out <path>", "Output report to JSON file");
82
+ };
83
+ commonOptions(program.command("seed")).description("Seed the database").action(async (options) => {
84
+ const config = await loadConfig(options.config);
85
+ const mergedOptions = { ...config, ...options };
86
+ if (options.rowsPerTable) {
87
+ mergedOptions.rows = options.rowsPerTable;
88
+ }
89
+ if (mergedOptions.confirm && !mergedOptions.dryRun) {
90
+ const confirmed = await confirmAction(mergedOptions.confirm);
91
+ if (!confirmed) {
92
+ console.error("\u274C Confirmation failed. Aborting.");
93
+ process.exit(1);
94
+ }
95
+ }
96
+ let dbUrl = mergedOptions.db;
97
+ if (mergedOptions.dbType === "mongodb" && mergedOptions.mongodb?.uri) {
98
+ dbUrl = mergedOptions.mongodb.uri;
99
+ }
100
+ if (!dbUrl) {
101
+ console.error("Error: Database connection string (--db) is required");
102
+ process.exit(1);
103
+ }
104
+ const dbType = mergedOptions.dbType || inferDbType(dbUrl);
105
+ try {
106
+ const adapter = await getAdapter(dbType, dbUrl);
107
+ let report;
108
+ if (dbType === "mongodb") {
109
+ report = await runSeedMongo(adapter, mergedOptions, {
110
+ dryRun: mergedOptions.dryRun,
111
+ allowProduction: mergedOptions.allowProduction
112
+ }, { generators, inferGenerator });
113
+ } else {
114
+ await adapter.connect();
115
+ const schema = await adapter.introspectSchema();
116
+ const plan = createSeedPlan(schema, mergedOptions, adapter.capabilities?.deferrableConstraints);
117
+ report = await runSeedSql(adapter, schema, plan, mergedOptions, {
118
+ generators,
119
+ inferGenerator,
120
+ overrides: mergedOptions.overrides
121
+ });
122
+ }
123
+ reportToConsole(report);
124
+ if (options.out) {
125
+ writeFileSync(resolve2(process.cwd(), options.out), reportToJson(report));
126
+ }
127
+ } catch (err) {
128
+ console.error(`
129
+ \u274C Error: ${err.message}`);
130
+ process.exit(1);
131
+ }
132
+ });
133
+ program.command("preview").description("Preview the seeding plan without executing").action(async (options) => {
134
+ const seedCmd = program.commands.find((c) => c.name() === "seed");
135
+ await seedCmd?.parseAsync(["--dry-run", ...process.argv.slice(3)], { from: "user" });
136
+ });
137
+ program.command("reset").description("Truncate all tables").option("--db <url>", "Database connection string").option("--allow-production", "Allow running against production databases").action(async (options) => {
138
+ console.log("Resetting database...");
139
+ });
140
+ program.command("introspect").description("Introspect the database schema and print as JSON").option("--db <url>", "Database connection string").action(async (options) => {
141
+ console.log("Introspecting database...");
142
+ });
143
+ program.parse();
144
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bin.ts","../src/config.mts"],"sourcesContent":["import 'dotenv/config'\nimport { Command } from 'commander'\nimport {\n version as coreVersion,\n runSeedSql,\n runSeedMongo,\n createSeedPlan,\n reportToConsole,\n reportToJson\n} from 'schema-seed-core'\nimport { generators, inferGenerator } from 'schema-seed-generators'\nimport { loadConfig } from './config.mjs'\nimport { writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { createInterface } from 'node:readline/promises'\n\nconst program = new Command()\n\nprogram\n .name('schema-seed')\n .description('CLI to seed your database with realistic data')\n .version(coreVersion)\n\nasync function getAdapter(dbType: string, dbUrl: string) {\n const packageName = `schema-seed-adapter-${dbType}`\n try {\n const module = await import(packageName)\n const adapterName = dbType.charAt(0).toUpperCase() + dbType.slice(1) + 'Adapter'\n const AdapterClass = module[adapterName] || module.Adapter || module.default\n\n if (!AdapterClass) {\n // Try factory function\n const factoryMethod = `create${dbType.charAt(0).toUpperCase() + dbType.slice(1)}Adapter`\n if (typeof module[factoryMethod] === 'function') {\n return module[factoryMethod](dbUrl)\n }\n throw new Error(`Could not find adapter class or factory in ${packageName}`)\n }\n\n return new AdapterClass(dbUrl)\n } catch (err: any) {\n if (err.code === 'ERR_MODULE_NOT_FOUND' || err.message.includes('Cannot find module')) {\n throw new Error(`Adapter not installed. Run: pnpm add ${packageName}`)\n }\n throw new Error(`Failed to load adapter ${packageName}: ${err.message}`)\n }\n}\n\nfunction inferDbType(dbUrl: string): string {\n if (dbUrl.startsWith('postgres://') || dbUrl.startsWith('postgresql://')) return 'postgres'\n if (dbUrl.startsWith('mysql://')) return 'mysql'\n if (dbUrl.startsWith('sqlite://') || dbUrl.endsWith('.db')) return 'sqlite'\n if (dbUrl.startsWith('mongodb://')) return 'mongodb'\n if (dbUrl.startsWith('sqlserver://')) return 'mssql'\n return 'postgres' // Default\n}\n\nasync function confirmAction(expected: string): Promise<boolean> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout\n })\n const answer = await rl.question(`⚠️ Type \"${expected}\" to confirm: `)\n rl.close()\n return answer === expected\n}\n\nconst commonOptions = (cmd: Command) => {\n return cmd\n .option('--db <url>', 'Database connection string')\n .option('--dbType <type>', 'Database type (postgres, mysql, sqlite, mssql, oracle, mongodb)')\n .option('--config <path>', 'Path to config file')\n .option('--table <names...>', 'Specific tables to seed')\n .option('--all', 'Seed all tables', true)\n .option('--rows <number>', 'Number of rows per table', (v) => parseInt(v), 10)\n .option('--rows-per-table <json>', 'JSON mapping of table names to row counts', (v) => JSON.parse(v))\n .option('--seed <string>', 'Random seed')\n .option('--dry-run', 'Do not execute any writes')\n .option('--truncate', 'Truncate tables before seeding')\n .option('--allow-production', 'Allow running against production databases')\n .option('--confirm <string>', 'Require typed confirmation string to proceed')\n .option('--with-parents', 'Include parent tables for foreign keys')\n .option('--out <path>', 'Output report to JSON file')\n}\n\ncommonOptions(program.command('seed'))\n .description('Seed the database')\n .action(async (options) => {\n const config = await loadConfig(options.config)\n const mergedOptions = { ...config, ...options }\n\n if (options.rowsPerTable) {\n mergedOptions.rows = options.rowsPerTable\n }\n\n if (mergedOptions.confirm && !mergedOptions.dryRun) {\n const confirmed = await confirmAction(mergedOptions.confirm)\n if (!confirmed) {\n console.error('❌ Confirmation failed. Aborting.')\n process.exit(1)\n }\n }\n\n let dbUrl = mergedOptions.db\n if (mergedOptions.dbType === 'mongodb' && mergedOptions.mongodb?.uri) {\n dbUrl = mergedOptions.mongodb.uri\n }\n\n if (!dbUrl) {\n console.error('Error: Database connection string (--db) is required')\n process.exit(1)\n }\n\n const dbType = mergedOptions.dbType || inferDbType(dbUrl)\n\n try {\n const adapter = await getAdapter(dbType, dbUrl)\n\n let report;\n if (dbType === 'mongodb') {\n // For MongoDB, we use the new config-based seeding\n report = await runSeedMongo(adapter as any, mergedOptions as any, {\n dryRun: mergedOptions.dryRun,\n allowProduction: mergedOptions.allowProduction\n }, { generators, inferGenerator })\n } else {\n await adapter.connect()\n const schema = await (adapter as any).introspectSchema()\n const plan = createSeedPlan(schema, mergedOptions, (adapter as any).capabilities?.deferrableConstraints)\n\n report = await runSeedSql(adapter as any, schema, plan, mergedOptions, {\n generators,\n inferGenerator,\n overrides: mergedOptions.overrides\n })\n }\n\n reportToConsole(report)\n\n if (options.out) {\n writeFileSync(resolve(process.cwd(), options.out), reportToJson(report))\n }\n } catch (err: any) {\n console.error(`\\n❌ Error: ${err.message}`)\n process.exit(1)\n }\n })\n\nprogram.command('preview')\n .description('Preview the seeding plan without executing')\n .action(async (options) => {\n // Same as seed --dry-run\n const seedCmd = program.commands.find(c => c.name() === 'seed')\n await seedCmd?.parseAsync(['--dry-run', ...process.argv.slice(3)], { from: 'user' })\n })\n\nprogram.command('reset')\n .description('Truncate all tables')\n .option('--db <url>', 'Database connection string')\n .option('--allow-production', 'Allow running against production databases')\n .action(async (options) => {\n console.log('Resetting database...')\n // Implementation would call adapter.truncateTables()\n })\n\nprogram.command('introspect')\n .description('Introspect the database schema and print as JSON')\n .option('--db <url>', 'Database connection string')\n .action(async (options) => {\n console.log('Introspecting database...')\n // Implementation would call adapter.introspectSchema()\n })\n\nprogram.parse()\n","import { createJiti } from 'jiti'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { type SeedOptions } from 'schema-seed-core'\nimport { type MongoSeedConfig } from 'schema-seed-core/mongo'\n\nexport type Config = (SeedOptions & {\n db?: string\n dbType?: string\n overrides?: Record<string, any>\n}) | MongoSeedConfig\n\nexport async function loadConfig(configPath?: string): Promise<Config> {\n const jiti = createJiti(import.meta.url)\n const paths = configPath\n ? [resolve(process.cwd(), configPath)]\n : [\n resolve(process.cwd(), 'seed.config.ts'),\n resolve(process.cwd(), 'seed.config.js'),\n resolve(process.cwd(), 'seed.config.mjs'),\n ]\n\n for (const path of paths) {\n if (existsSync(path)) {\n const module = await jiti.import(path) as any\n return module.default || module\n }\n }\n\n return {}\n}\n"],"mappings":";;;AAAA,OAAO;AACP,SAAS,eAAe;AACxB;AAAA,EACI,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,YAAY,sBAAsB;;;ACV3C,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAUxB,eAAsB,WAAW,YAAsC;AACnE,QAAM,OAAO,WAAW,YAAY,GAAG;AACvC,QAAM,QAAQ,aACR,CAAC,QAAQ,QA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BAAc,IAAI,OAAO,EAAE;AACzC,YAAQ,KAAK,CAAC;AAAA,EAClB;AACJ,CAAC;AAEL,QAAQ,QAAQ,SAAS,EACpB,YAAY,4CAA4C,EACxD,OAAO,OAAO,YAAY;AAEvB,QAAM,UAAU,QAAQ,SAAS,KAAK,OAAK,EAAE,KAAK,MAAM,MAAM;AAC9D,QAAM,SAAS,WAAW,CAAC,aAAa,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,OAAO,CAAC;AACvF,CAAC;AAEL,QAAQ,QAAQ,OAAO,EAClB,YAAY,qBAAqB,EACjC,OAAO,cAAc,4BAA4B,EACjD,OAAO,sBAAsB,4CAA4C,EACzE,OAAO,OAAO,YAAY;AACvB,UAAQ,IAAI,uBAAuB;AAEvC,CAAC;AAEL,QAAQ,QAAQ,YAAY,EACvB,YAAY,kDAAkD,EAC9D,OAAO,cAAc,4BAA4B,EACjD,OAAO,OAAO,YAAY;AACvB,UAAQ,IAAI,2BAA2B;AAE3C,CAAC;AAEL,QAAQ,MAAM;","names":["resolve"]}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/config.mts
4
+ import { createJiti } from "jiti";
5
+ import { existsSync } from "fs";
6
+ import { resolve } from "path";
7
+ async function loadConfig(configPath) {
8
+ const jiti = createJiti(import.meta.url);
9
+ const paths = configPath ? [resolve(process.cwd(), configPath)] : [
10
+ resolve(process.cwd(), "seed.config.ts"),
11
+ resolve(process.cwd(), "seed.config.js"),
12
+ resolve(process.cwd(), "seed.config.mjs")
13
+ ];
14
+ for (const path of paths) {
15
+ if (existsSync(path)) {
16
+ const module = await jiti.import(path);
17
+ return module.default || module;
18
+ }
19
+ }
20
+ return {};
21
+ }
22
+
23
+ // src/index.ts
24
+ function defineConfig(config) {
25
+ return config;
26
+ }
27
+ export {
28
+ defineConfig,
29
+ loadConfig
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config.mts","../src/index.ts"],"sourcesContent":["import { createJiti } from 'jiti'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { type SeedOptions } from 'schema-seed-core'\nimport { type MongoSeedConfig } from 'schema-seed-core/mongo'\n\nexport type Config = (SeedOptions & {\n db?: string\n dbType?: string\n overrides?: Record<string, any>\n}) | MongoSeedConfig\n\nexport async function loadConfig(configPath?: string): Promise<Config> {\n const jiti = createJiti(import.meta.url)\n const paths = configPath\n ? [resolve(process.cwd(), configPath)]\n : [\n resolve(process.cwd(), 'seed.config.ts'),\n resolve(process.cwd(), 'seed.config.js'),\n resolve(process.cwd(), 'seed.config.mjs'),\n ]\n\n for (const path of paths) {\n if (existsSync(path)) {\n const module = await jiti.import(path) as any\n return module.default || module\n }\n }\n\n return {}\n}\n","import { Config } from './config.mjs'\nexport { Config } from './config.mjs'\n\nexport function defineConfig(config: Config): Config {\n return config\n}\n\nexport { loadConfig } from './config.mjs'\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAUxB,eAAsB,WAAW,YAAsC;AACnE,QAAM,OAAO,WAAW,YAAY,GAAG;AACvC,QAAM,QAAQ,aACR,CAAC,QAAQ,QAAQ,IAAI,GAAG,UAAU,CAAC,IACnC;AAAA,IACE,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,IAAI,GAAG,gBAAgB;AAAA,IACvC,QAAQ,QAAQ,IAAI,GAAG,iBAAiB;AAAA,EAC5C;AAEJ,aAAW,QAAQ,OAAO;AACtB,QAAI,WAAW,IAAI,GAAG;AAClB,YAAM,SAAS,MAAM,KAAK,OAAO,IAAI;AACrC,aAAO,OAAO,WAAW;AAAA,IAC7B;AAAA,EACJ;AAEA,SAAO,CAAC;AACZ;;;AC3BO,SAAS,aAAa,QAAwB;AACjD,SAAO;AACX;","names":[]}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "schema-seed",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "CLI for schema-seed",
6
+ "author": "Ali Nazar",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/alinazar-111/schema-seed.git"
12
+ },
13
+ "homepage": "https://github.com/alinazar-111/schema-seed#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/alinazar-111/schema-seed/issues"
16
+ },
17
+ "keywords": [
18
+ "database",
19
+ "seeding",
20
+ "test-data",
21
+ "cli",
22
+ "schema-seed"
23
+ ],
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "bin": {
32
+ "schema-seed": "./dist/bin.js"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "dependencies": {
40
+ "commander": "^12.1.0",
41
+ "dotenv": "^17.2.3",
42
+ "jiti": "^2.6.1",
43
+ "schema-seed-core": "0.1.0",
44
+ "schema-seed-generators": "0.1.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^20.19.27",
48
+ "tsup": "^8.3.5",
49
+ "typescript": "^5.7.2",
50
+ "vitest": "^2.1.8",
51
+ "schema-seed-adapter-mongodb": "0.1.0",
52
+ "schema-seed-adapter-mysql": "0.1.0",
53
+ "schema-seed-adapter-postgres": "0.1.0",
54
+ "schema-seed-adapter-sqlite": "0.1.0",
55
+ "schema-seed-adapter-mssql": "0.1.0",
56
+ "schema-seed-adapter-oracle": "0.1.0"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "clean": "rm -rf dist",
61
+ "dev": "tsup --watch",
62
+ "lint": "eslint .",
63
+ "test": "vitest run --passWithNoTests",
64
+ "typecheck": "tsc --noEmit"
65
+ }
66
+ }