use strict;
return sub
{
	my $dbh = shift;
	
	my ($sth, %h);
	
	$dbh->do("INSERT INTO jin_embedded_email (id,owner_id) select distinct id,owner_id from jin_template_set where tmpl_set_type='mail'");
	
	$sth = $dbh->prepare("SELECT id, owner_id FROM jin_embedded_email");
	$sth->execute;
	
	while (my @row = $sth->fetchrow_array)
	{
		my $sth1 = $dbh->prepare("select name, template from jin_template where owner_id=$row[1] and tmpl_set_id=$row[0]");
		$sth1->execute;
		%h = ();
		while (my $row1 = $sth1->fetchrow_hashref)
		{
			$h{$row1->{name}} = $row1->{template};
		}
		$dbh->do("UPDATE jin_embedded_email SET id=$row[1], ".join(',', map { "$_=" . $dbh->quote($h{$_}) } keys %h)." WHERE id=$row[0]");
	}
};