Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #apaga arquivos antigos.
- rm -rf *.elb*;
- mysqldump --compatible=ansi --skip-comments --skip-extended-insert --compact --hex-blob "$@" | sed -e "s/,0x\([0-9A-Z]*\),/,X'\L\1',/g" | sed -e "s/,0x\([0-9A-Z]*\),/,X'\L\1',/g" | \
- awk '
- #inicio
- BEGIN {
- FS=",$"
- print "PRAGMA synchronous = OFF;"
- print "PRAGMA journal_mode = MEMORY;"
- print "BEGIN TRANSACTION;"
- }
- # tratando trigger
- /^\/\*.*CREATE.*TRIGGER/ {
- gsub( /^.*TRIGGER/, "CREATE TRIGGER" )
- print
- inTrigger = 1
- next
- }
- # The end of CREATE TRIGGER has a stray comment terminator
- /END \*\/;;/ { gsub( /\*\//, "" ); print; inTrigger = 0; next }
- # matando trigger
- inTrigger != 0 { print; next }
- # Skip other comments
- /^\/\*/ { next }
- # arrumando os quotes
- /INSERT/ {
- gsub( /\\\047/, "\047\047" )
- gsub(/\\n/, "\n")
- gsub(/\\r/, "\r")
- gsub(/\\"/, "\"")
- gsub(/\\\\/, "\\")
- gsub(/\\\032/, "\032")
- print
- next
- }
- # colocando o create table
- /^CREATE/ {
- print
- if ( match( $0, /\"[^\"]+/ ) ) tableName = substr( $0, RSTART+1, RLENGTH-1 )
- }
- # Replace `FULLTEXT KEY` or any other `XXXXX KEY` except PRIMARY by `KEY`
- /^ [^"]+KEY/ && !/^ PRIMARY KEY/ { gsub( /.+KEY/, " KEY" ) }
- # pegando tamanho dos campos
- / KEY/ { gsub(/\([0-9]+\)/, "") }
- # subistituindo as palavras e tirando os lixos
- /^ / && !/^( KEY|\);)/ {
- gsub( /AUTO_INCREMENT|auto_increment/, "" )
- gsub( /NOT NULL DEFAULT \047\047/, "NOT NULL DEFAULT NULL" )
- gsub( /(COMMENT|comment)/,"")
- gsub( /\047\T ou E\047/, "" )
- gsub( /(CHARACTER SET|character set) [^ ]+ /, "" )
- gsub( /DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP|default current_timestamp on update current_timestamp/, "" )
- gsub( /(COLLATE|collate) [^ ]+ /, "" )
- gsub(/(ENUM|enum)[^)]+\)/, "text ")
- gsub(/(SET|set)\([^)]+\)/, "text ")
- gsub(/UNSIGNED|unsigned/, "")
- if (prev) print prev ","
- prev = $1
- }
- # evitando keys duplicada
- /^( KEY|\);)/ {
- if (prev) print prev
- prev=""
- if ($0 == ");"){
- print
- } else {
- if ( match( $0, /\"[^"]+/ ) ) indexName = substr( $0, RSTART+1, RLENGTH-1 )
- if ( match( $0, /\([^()]+/ ) ) indexKey = substr( $0, RSTART+1, RLENGTH-1 )
- key[tableName]=key[tableName] "CREATE INDEX \"" tableName "_" indexName "\" ON \"" tableName "\" (" indexKey ");\n"
- }
- }
- # imprimindo
- END {
- for (table in key) printf key[table]
- print "END TRANSACTION;"
- }
- '
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement