#!/usr/bin/perl -w

use strict;
use DBI;

sub do_error($) {
    exit(1);
}

if(@ARGV != 3) {
  print("Usage: $0 <user> <password> <database>\n");
  exit(1);
}

my ($user, $pass, $dbname) = @ARGV;

my $db = DBI->connect("dbi:mysql:$dbname", "$user", "$pass");

if (!defined($db)) {
	print "did not connect to mysql\n";
	exit(1);
}

my $res; 
my $sth;
my $rows;

$res = $db->do("set character_set_client=utf8;");
if(!$res) {
  do_error(1);
}
$res = $db->do("set character_set_connection=utf8;");
if(!$res) {
  do_error(1);
}
$res = $db->do("set character_set_results=utf8;");

if(!$res) {
  do_error(1);
}

$res = $db->do("ALTER TABLE hierarchy DROP KEY parent, ADD KEY parent (parent,type,flags,owner)");

print "Done.\n";