<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 09/15/2014 01:38 PM, Eric Sharkey
wrote:<br>
</div>
<blockquote
cite="mid:CAC73aR3b8-BA3974AX0--ECDX5JxKRaCVa88a78V_xQzxowoTg@mail.gmail.com"
type="cite">
<pre wrap="">On Mon, Sep 15, 2014 at 11:37 AM, Michael T. Dean
<a class="moz-txt-link-rfc2396E" href="mailto:mtdean@thirdcontact.com"><mtdean@thirdcontact.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 09/15/2014 10:25 AM, Martin Compton wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I was cleaning up my DISH-TV Schedules Direct listings and ran
mythfilldatabase to update the channels.
When I was checking the channels table I noticed that some have 2-3
duplicate entries for the same sourceid+channel+callsign+xmltvid (etc).
Can I safely reassign the chanid in the associated tables:
channelgroup
program (these duplicates can be deleted)
programgenres
programrating
record
recorded
oldrecorded
and remove the duplicate channels?
Am I missing any tables with a "chanid" column?
</pre>
</blockquote>
<pre wrap="">
The proper way to handle "ghost" channels (as you get when you don't
properly set the XMLTV ID on channels before running mythfilldatabase and
your broadcasters provide in-stream information about the channel that
mythfilldatabase can't match to one of your scanned channels) is to "Delete
all video sources" (to clear out everything--both the good and the bad
channel info--from all the tables that are affected) and then rescan, set
the XMLTV ID's, then run mythfilldatabase.
</pre>
</blockquote>
<pre wrap="">You've posted this response before. I can't say I recall anyone
agreeing that this is the best approach. There's too much collateral
damage.
Martin, I think your originally posted plan is best. There is no good
automated way to remove a channel that doesn't leave dangling foreign
key references from other tables.
</pre>
</blockquote>
That's what I ended up doing, "bashing" out the script included
below.<br>
<br>
Bear in mind, I was simply trying to cleanup what happened after I
ran "mythfilldatabase" with the "--do-channel-updates" option (more
than once) in an attempt to clean up DISH channel changes/additions
(via SchedulesDirect). The duplicates contain exactly the same
record data, only the "chanid" was different.<br>
<br>
After cleaning my Schedules Direct lineup and channels table, I have
about %40 fewer channels and program data. In my view proper
de-duplication was worth the effort versus dumping everything and
starting over.<br>
<br>
Here's the bash script (best to stop myth-backend and <i>backup
database</i> first!):<br>
<br>
#!/bin/bash<br>
# MythTV v0.27 remove duplicate channel: duplicate_chanid
valid_chanid<br>
# deletes duplicate channel/guide entries but preserves recording
history<br>
<br>
if [ $# -lt 2 ]; then<br>
echo -e "Usage:\n\tremove_dup_channel.sh duplicate_chanid
valid_chanid"<br>
exit 1<br>
fi<br>
<br>
DUPID=$1<br>
CHANID=$2<br>
<br>
cat << EOF | mysql -umythtv -pdIIOS40x mythconverg<br>
delete from channelgroup where chanid=${DUPID};<br>
update jobqueue set chanid=${CHANID} where chanid=${DUPID};<br>
delete from program where chanid=${DUPID};<br>
delete from programgenres where chanid=${DUPID};<br>
delete from programrating where chanid=${DUPID};<br>
update oldrecorded set chanid=${CHANID} where chanid=${DUPID};<br>
update recorded set chanid=${CHANID} where chanid=${DUPID};<br>
update recordedcredits set chanid=${CHANID} where chanid=${DUPID};<br>
update recordedfile set chanid=${CHANID} where chanid=${DUPID};<br>
update recordedmarkup set chanid=${CHANID} where chanid=${DUPID};<br>
update recordedprogram set chanid=${CHANID} where chanid=${DUPID};<br>
update recordedrating set chanid=${CHANID} where chanid=${DUPID};<br>
update recordedseek set chanid=${CHANID} where chanid=${DUPID};<br>
delete from recordmatch where chanid=${DUPID};<br>
update record_tmp set chanid=${CHANID} where chanid=${DUPID};<br>
update record set chanid=${CHANID} where chanid=${DUPID};<br>
update tvchain set chanid=${CHANID} where chanid=${DUPID};<br>
delete from channel where chanid=${DUPID}<br>
EOF<br>
<br>
</body>
</html>