forked from alphagov/whitehall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-tables.sh
executable file
·62 lines (56 loc) · 1.59 KB
/
convert-tables.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
if [ "$#" != "4" ]; then
echo "Usage: `basename $0` db_name db_user db_password db_host"
exit 1
fi
DB=$1
DBUSER=$2
DBPASS=$3
DBHOST=$4
latin_tables=(
attachment_data
attachment_sources
classification_featuring_image_data
classification_featurings
consultation_participations
consultation_response_attachments
consultation_response_forms
consultation_response_form_data
corporate_information_page_attachments
corporate_information_pages
data_migration_records
delayed_jobs
document_collections
document_sources
edition_authors
edition_document_series
edition_organisation_image_data
edition_policy_groups
edition_role_appointments
edition_statistical_data_sets
edition_world_location_image_data
fatality_notice_casualties
force_publication_attempts
group_memberships
groups
import_errors
imports
import_logs
operational_fields
organisation_mainstream_links
organisational_relationships
policy_group_attachments
responses
sponsorships
worldwide_office_world_locations
worldwide_offices
)
for table in "${latin_tables[@]}"; do
LATIN1FILE="/tmp/${DB}.${table}.latin1.sql"
mysqldump -h$DBHOST -u$DBUSER -p$DBPASS --opt -e --skip-set-charset --default-character-set=latin1 --skip-extended-insert $DB --tables $table | sed 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/' > $LATIN1FILE
done
for table in "${latin_tables[@]}"; do
LATIN1FILE="/tmp/${DB}.${table}.latin1.sql"
mysql -h$DBHOST -u$DBUSER -p$DBPASS $DB < $LATIN1FILE
rm $LATIN1FILE
done