Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean topics and schema subjects datagen creates #55

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions datagen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const alert = require('cli-alerts');
const { parseSqlSchema } = require('./src/schemas/parseSqlSchema');
const { parseAvroSchema } = require('./src/schemas/parseAvroSchema');
const { parseJsonSchema } = require('./src/schemas/parseJsonSchema');
const jsonDataGenerator = require('./src/dataGenerator');
const cleanKafka = require('./src/kafka/cleanKafka');
const dataGenerator = require('./src/dataGenerator');
const fs = require('fs');
const { program, Option } = require('commander');

Expand All @@ -36,6 +37,11 @@ program
.choices(['true', 'false'])
.default('false')
)
.addOption(
new Option('-c, --clean <char>')
.choices(['true', 'false'])
.default('false')
)
.addOption(
new Option('-dr, --dry-run <char>', 'Dry run (no data will be produced')
.choices(['true', 'false'])
Expand All @@ -60,6 +66,8 @@ if (!fs.existsSync(options.schema)) {
global.debug = options.debug;
global.recordSize = options.recordSize;
global.wait = options.wait;
global.clean = options.clean;
global.dryRun = options.dryRun;

if (debug === 'true') {
console.log(options);
Expand Down Expand Up @@ -106,13 +114,20 @@ if (!wait) {
process.exit();
}

if (clean == 'true') {
let topics = []
for (table of parsedSchema){
topics.push(table._meta.topic)
}
await cleanKafka(options.format,topics)
process.exit(0);
}

// Generate data
await jsonDataGenerator({
await dataGenerator({
format: options.format,
schema: parsedSchema,
number: options.number,
dryRun: options.dryRun,
debug: options.debug
number: options.number
})

await end();
Expand Down
156 changes: 154 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
},
"dependencies": {
"@avro/types": "^1.0.25",
"@kafkajs/confluent-schema-registry": "^3.3.0",
"@faker-js/faker": "^7.6.0",
"@kafkajs/confluent-schema-registry": "^3.3.0",
"arg": "^5.0.2",
"avro-js": "^1.11.1",
"axios": "^1.3.4",
"cli-alerts": "^1.2.2",
"cli-handle-unhandled": "^1.1.1",
"cli-welcome": "^2.2.2",
Expand Down
4 changes: 1 addition & 3 deletions src/dataGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ async function prepareSchema(megaRecord, topic, registry, avroSchemas) {
module.exports = async ({
format,
schema,
number,
dryRun = false,
debug = false
number
}) => {
let payload;
if (recordSize) {
Expand Down
Loading