Skip to content

Instantly share code, notes, and snippets.

@marvinhosea
Created February 2, 2022 12:25
Show Gist options
  • Save marvinhosea/34010552b3246b2dad442dff0d25804d to your computer and use it in GitHub Desktop.
Save marvinhosea/34010552b3246b2dad442dff0d25804d to your computer and use it in GitHub Desktop.
Liquibase Changelog Name Convention Using Date
#!/bin/sh
while getopts c:u: flag
do
case "${flag}" in
c) changelogname=${OPTARG};;
u) username=${OPTARG};;
esac
done
if [ -z $changelogname ]; then
echo "changelog name not provided"
exit 1
fi
if [ -z $username ]; then
username=$USER
fi
current_time=$(date "+%Y_%m_%d_%H%M%S")
new_fileName="_"$changelogname"_changelog.sql"
converted="$(echo $new_fileName | sed 's/\([^A-Z]\)\([A-Z0-9]\)/\1_\2/g' \
| sed 's/\([A-Z0-9]\)\([A-Z0-9]\)\([^A-Z]\)/\1_\2\3/g' \
| tr '[:upper:]' '[:lower:]')"
echo "--liquibase formatted sql
--changeset $username:1
-- rollback " > ../db/liquibase/changelog/$current_time$converted
echo "Changelog created successfully : $current_time$converted"
@marvinhosea
Copy link
Author

Created this bash script to help create liquibase changelogs based on time. This is important when you're working with a team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment