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

Update the script to remove Charset latin1_general cs and latin1_general ci #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion h2dump.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ createTables=$(cat $1)
#remove character sets
function filter {
echo "$1" | sed -e "/^--/d" \
-e 's/CHARACTER SET latin1 COLLATE latin1_general_cs //g' \
-e 's/CHARACTER SET latin1 COLLATE latin1_general_ci //g' \
-e 's/CHARACTER SET latin1 COLLATE utf8_unicode_cs //g' \
-e 's/CHARACTER SET latin1 COLLATE utf8_unicode_ci //g' \
-e 's/ COLLATE latin1_general_cs//g' \
-e 's/ COLLATE latin1_general_ci//g' \
-e 's/ COLLATE utf8_unicode_ci//g' \
-e 's/ COLLATE utf8_unicode_cs//g' \
-e 's/ CHARACTER SET latin1//g' \
-e 's/ CHARACTER SET utf8//g' \
-e 's/ GENERATED ALWAYS .* VIRTUAL//g' \
-e 's/`//g' \
-e '/^DROP TABLE/d' \
-e 's/ COMMENT [^\n]*/,/g' \
Expand All @@ -33,7 +44,6 @@ function filter {
-e 's/^CREATE TABLE/CREATE TABLE IF NOT EXISTS/g' \
-e 's/ text / varchar(65535) /g' \
-e "s/\\\'/''/g" \
| sed -r 's/"(.*)"/"\U\1"/g' \
| sed -r '/UNIQUE/ s/([^,]*)\([0-9]*\)/\1/g'
}

Expand Down
58 changes: 58 additions & 0 deletions h2dumpUpercase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

createTables=$(cat $1)

#remove all dash comments
#remove all tick marks
#bigint replaced with numberic
#int sizes to just integer
#delete lock tables lines
#remove all key lines
#convert all enums to varchars
#delete all CONSTRAINT "xxxNamexxx"
#remove KEY "xxxxNamexxxx" from all unique constraints
#remove all default values
#remove character sets
function filter {
echo "$1" | sed -e "/^--/d" \
-e 's/CHARACTER SET latin1 COLLATE latin1_general_cs //g' \
-e 's/CHARACTER SET latin1 COLLATE latin1_general_ci //g' \
-e 's/ COLLATE latin1_general_cs//g' \
-e 's/ COLLATE latin1_general_ci//g' \
-e 's/`//g' \
-e '/^DROP TABLE/d' \
-e 's/ COMMENT [^\n]*/,/g' \
-e 's/bigint/numeric/g' \
-e 's/double\(([^(]*)\)/double/' \
-e 's/[^ ]*int([0-9]*)/integer/g' \
-e '/^\/\*.*\*\//d' \
-e '/LOCK TABLES/d' \
-e '/^\/\*/,/\*\//c\;' \
-e '/^CREATE TABLE/,/);/{/^ KEY/d; }' \
-e 's/enum(.*)/varchar(255)/g' \
-e 's/CONSTRAINT "[^"]*"/ADD/g' \
-e 's/UNIQUE KEY "[^"]*"/UNIQUE/g' \
-e 's/ DEFAULT [^\n]*/,/g' \
-e 's/CHARACTER SET [^ ]*//g' \
-e 's/^CREATE TABLE/CREATE TABLE IF NOT EXISTS/g' \
-e 's/ text / varchar(65535) /g' \
-e "s/\\\'/''/g" \
| sed -r 's/"(.*)"/"\U\1"/g' \
| sed -r '/UNIQUE/ s/([^,]*)\([0-9]*\)/\1/g'
}

createTables=$(filter "$createTables")

foreignKeys=$(echo "$createTables" | sed -r 's/CREATE TABLE IF NOT EXISTS ("[^"]*") \(/ALTER TABLE \1/g' | sed -n -e '/ALTER TABLE/,/);/ {/ALTER TABLE/ {x} ; /FOREIGN/ {x;p;x;p} }' | sed -r -e '/REFERENCES/ s/,//g' -e 's/(REFERENCES .*)/\1;/g')

#delete create tables foreign key
createTables=$(echo "$createTables" | sed '/ADD FOREIGN KEY/d' | sed -n '/CREATE TABLE/,/);/ {/);/ {x ; s/,$//g; p; x; p} ; /);/ !{x ; p}}' | sed '/CREATE TABLE/,/);/ !{d}')

echo "$createTables"
echo "$foreignKeys"

if [ $# -eq 2 ]
then
filter "$(cat $2)"
fi