initTables conn =
    do t <- tables conn
       let t2 = map (map toUpper) t
       if not (elem "MISTORE" t2)
          then do execute conn "CREATE TABLE mistore (api TEXT)"
                  execute conn "INSERT INTO mistore VALUES ('media-index1')"
          else return ()
       if not (elem "MIFILES" t2)
          then do execute conn $ "CREATE TABLE mifiles (" ++
                   "discid TEXT, filename TEXT, filesize INTEGER, " ++
                   "md5 TEXT, mimetype TEXT)"
                  execute conn $ "CREATE UNIQUE INDEX mifilespri ON mifiles " ++
                          "(discid, filename)"
                  execute conn $ "CREATE INDEX mifilesmd5 ON mifiles " ++
                          "(md5)"
                  execute conn "CREATE INDEX mifilesfiles ON mifiles (filename)"
          else return ()
       if not (elem "MIDISCS" t2)
          then do execute conn "CREATE TABLE midiscs (discid TEXT, discdescrip TEXT)"
                  execute conn "CREATE UNIQUE INDEX midiscspri ON midiscs (discid)"
          else return ()

{- | Add a new disc to the system. -}
initTables conn =
    do t <- tables conn
       let t2 = map (map toUpper) t
       if not (elem "MISTORE" t2)
          then do execute conn "CREATE TABLE mistore (api TEXT)"
                  execute conn "INSERT INTO mistore VALUES ('media-index1')"
          else return ()
       if not (elem "MIFILES" t2)
          then do execute conn $ "CREATE TABLE mifiles (" ++
                   "discid TEXT, filename TEXT, filesize INTEGER, " ++
                   "md5 TEXT, mimetype TEXT)"
                  execute conn $ "CREATE UNIQUE INDEX mifilespri ON mifiles " ++
                          "(discid, filename)"
                  execute conn $ "CREATE INDEX mifilesmd5 ON mifiles " ++
                          "(md5)"
                  execute conn "CREATE INDEX mifilesfiles ON mifiles (filename)"
          else return ()
       if not (elem "MIDISCS" t2)
          then do execute conn "CREATE TABLE midiscs (discid TEXT, discdescrip TEXT)"
                  execute conn "CREATE UNIQUE INDEX midiscspri ON midiscs (discid)"
          else return ()

{- | Add a new disc to the system. -}
initTables conn =
    do t <- tables conn
       let t2 = map (map toUpper) t
       if not (elem "MISTORE" t2)
          then do execute conn "CREATE TABLE mistore (api TEXT)"
                  execute conn "INSERT INTO mistore VALUES ('media-index1')"
          else return ()
       if not (elem "MIFILES" t2)
          then do execute conn $ "CREATE TABLE mifiles (" ++
                   "discid TEXT, filename TEXT, filesize INTEGER, " ++
                   "md5 TEXT, mimetype TEXT)"
                  execute conn $ "CREATE UNIQUE INDEX mifilespri ON mifiles " ++
                          "(discid, filename)"
                  execute conn $ "CREATE INDEX mifilesmd5 ON mifiles " ++
                          "(md5)"
                  execute conn "CREATE INDEX mifilesfiles ON mifiles (filename)"
          else return ()
       if not (elem "MIDISCS" t2)
          then do execute conn "CREATE TABLE midiscs (discid TEXT, discdescrip TEXT)"
                  execute conn "CREATE UNIQUE INDEX midiscspri ON midiscs (discid)"
          else return ()

{- | Add a new disc to the system. -}