专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

使用shell脚本生成数据库markdown文档

学习shell脚本编程的一次实践,通过shell脚本生成数据库的markdown文档,代码如下:

 HOST=xxxxxx
 PORT=xxxx
 USER="xxxxx"
 PASSWORD="xxxxxx"
 DATABASE_PREFIX="xxxxxx"

 QUERY_DATABASE="select distinct TABLE_SCHEMA from information_schema.TABLES where TABLE_TYPE='BASE TABLE'"
 databaseList=$(mysql -h ${HOST} -u ${USER} -p${PASSWORD} -e "${QUERY_DATABASE}")

 for database in ${databaseList}
 do
     if [[ ${database} == *${DATABASE_PREFIX}* ]]
     then
         echo "Start ${database}"
         echo "### ${database}" >> test.md
         queryTable="select  distinct TABLE_NAME from information_schema.COLUMNS where TABLE_SCHEMA='${database}'"
         tableList=$(mysql -h ${HOST} -u ${USER} -p${PASSWORD} -N -e "${queryTable}")
         for table in ${tableList}
         do

             if [ $(grep -c "#### ${table%_*}_0" test.md) -ne '0' ] 
             then
                 continue
             fi

             echo "Start print table:${table}"
             echo "#### ${table}" >> test.md
             echo "名称 | 类型 | 是否可为空 | Key | 说明" >> test.md
             echo "--|--|--|--|--" >> test.md
             queryCloumns="select COLUMN_NAME, replace(COLUMN_TYPE,' ',''),IS_NULLABLE,CONCAT(COLUMN_KEY,'+++++++++'),CONCAT(replace(COLUMN_COMMENT,' ',''),'+++++++++') from information_schema.COLUMNS where TABLE_NAME='${table}' and TABLE_SCHEMA='${database}' order by ORDINAL_POSITION"

             columnList=$(mysql -h ${HOST} -u ${USER} -p${PASSWORD} -N -e "${queryCloumns}")
             count=0
             row=""
              for column in ${columnList}
              do
                  row="${row} ${column} | "

                  let count++
                  if [[ ${count} == 5 ]]
                  then
                      echo ${row} >> test.md
                      count=0
                      row=""
                  fi
              done
          done

      fi
  done

文章永久链接:https://tech.souyunku.com/32108

未经允许不得转载:搜云库技术团队 » 使用shell脚本生成数据库markdown文档

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们