Skip to content

Commit

Permalink
feat(kafka): support several schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-dur committed Feb 8, 2024
1 parent 5bdeea0 commit a7f9367
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions kafka/check-local-schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ find_schema_class_file() {
# Otherwise we fallback on finding the filename containing the schema code
# to end with Schema or is named InputModel
# We might want to improve this in the future
schema_class_file="$(grep -lr "^@schema" src | head -n 1 || return 0)"
schema_class_files="$(grep -lr "^@schema" src || return 0)"

if [[ -z "${schema_class_file}" ]]; then
schema_class_file="$(find src -name "*Schema.scala" -o -name "InputModel.scala" | head -n 1 || return 0)"
fi

echo "${schema_class_file}"
#if [[ -z "${schema_class_file}" ]]; then
# schema_class_file="$(find src -name "*Schema.scala" -o -name "InputModel.scala" | head -n 1 || return 0)"
#fi

for schema_class_file in $(grep -lr "^@schema" src)
do
echo $schema_class_file
done
}

find_schema_class() {
Expand Down Expand Up @@ -135,27 +137,34 @@ trap clean_temporary_folder EXIT

check_binary_exists "sbt"

target_schema_file="schemas/schema.avsc"
target_dir_schema="schemas"

generator_source_folder="$(mktemp -d)"
generator_code_file="${generator_source_folder}/SchemaGenerator.scala"

[[ ! -f "${target_schema_file}" ]] || checksum_before="$(get_md5sum "${target_schema_file}")"
schema_class_files="$(find_schema_class_file)"
[[ -n "${schema_class_files}" ]] || error "Could not find any schema class file"

schema_class_file="$(find_schema_class_file)"
[[ -n "${schema_class_file}" ]] || error "Could not find any schema class file"
for schema_class_file in $schema_class_files
do
schema_class="$(find_schema_class "${schema_class_file}")"
schema_library="$(find_avro_library "${schema_class_file}")"

schema_class="$(find_schema_class "${schema_class_file}")"
schema_library="$(find_avro_library "${schema_class_file}")"
class_name="${schema_class##*.}"
target_schema_file="$target_dir_schema/$class_name.avsc"

[[ ! -f "${target_schema_file}" ]] || checksum_before="$(get_md5sum "${target_schema_file}")"

generate_schema_generator_code "${schema_class}" "${schema_library}" > "${generator_code_file}"
run_schema_generator_code "${generator_code_file}" "${target_schema_file}"
generate_schema_generator_code "${schema_class}" "${schema_library}" > "${generator_code_file}"
run_schema_generator_code "${generator_code_file}" "${target_schema_file}"

if ! is_git_tracked "${target_schema_file}"; then
error "Schema file \"${target_schema_file}\" is not tracked by git. Please commit it."
fi
if ! is_git_tracked "${target_schema_file}"; then
error "Schema file \"${target_schema_file}\" is not tracked by git. Please commit it."
fi

checksum_after="$(get_md5sum "${target_schema_file}")"
checksum_after="$(get_md5sum "${target_schema_file}")"
if [[ "${checksum_after}" != "${checksum_before:-}" ]]; then
error "Schema file \"${target_schema_file}\" was missing or not consistent with code. Please commit the updated version."
fi

done

0 comments on commit a7f9367

Please sign in to comment.