Skip to content

Instantly share code, notes, and snippets.

@mkamakura
Created October 29, 2014 06:14
Show Gist options
  • Save mkamakura/2149bb492acd73af5768 to your computer and use it in GitHub Desktop.
Save mkamakura/2149bb492acd73af5768 to your computer and use it in GitHub Desktop.
テーブルやカラムにコメントがあるかチェックするシェルスクリプト
#!/bin/sh
DBNAME='<db_name>'
DBUSER='<db_user>'
DBPASSWORD='<db_password>'
get_not_exists_comment_of_table() {
echo "SELECT TABLE_SCHEMA, TABLE_NAME FROM information_schema.tables WHERE table_schema = '$DBNAME' AND table_comment = ''; " | mysql -u$DBUSER -p$DBPASSWORD
}
get_not_exists_comment_of_column() {
echo "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM information_schema.columns WHERE table_schema = '$DBNAME' AND column_comment = ''; " | mysql -u$DBUSER -p$DBPASSWORD
}
result = 0
if [ "`get_not_exists_comment_of_table`" != '' ]; then
echo '!!!! NOT EXISTS TABLE COMMENT !!!!';
get_not_exists_comment_of_table
result = 1
echo
fi
if [ "`get_not_exists_comment_of_comment`" != '' ]; then
echo '!!!! NOT EXISTS COLUMN COMMENT !!!!';
get_not_exists_comment_of_column
result = 1
echo
fi
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment