'Add Tag Browser views'

def upgrade_version_8(self):

    def create_tag_browser_view(table_name, column_name):
        self.db.execute(u'\n                                                                DROP    VIEW    IF    EXISTS    tag_browser_{tn};\n                                                                CREATE    VIEW    tag_browser_{tn}    AS    SELECT\n                                                                                id,\n                                                                                name,\n                                                                                (SELECT    COUNT(id)    FROM    books_{tn}_link    WHERE    {cn}={tn}.id)    count\n                                                                FROM    {tn};\n                                                                '.format(tn=table_name, cn=column_name))
    for tn in (u'authors', u'tags', u'publishers', u'series'):
        cn = tn[:(-1)]
        if (tn == u'series'):
            cn = tn
        create_tag_browser_view(tn, cn)
