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

feat(kafka): support several schemas #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take only one

schema_class_files="$(grep -lr "^@schema" src || return 0)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take all


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