Skip to content

Commit

Permalink
clean topics and schema subjects datagen creates (#55)
Browse files Browse the repository at this point in the history
* implement feature to clean topics and schema subjects datagen creates

* better error handling and soft delete the subject

* limit the axios error message for schema registry

* log the names of the deleted topics
  • Loading branch information
chuck-alt-delete authored Mar 4, 2023
1 parent 7883af9 commit 19cdbd2
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 11 deletions.
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

0 comments on commit 19cdbd2

Please sign in to comment.