File indexing completed on 2025-03-09 04:24:17
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_DATABASEUPDATER_H 0018 #define AMAROK_DATABASEUPDATER_H 0019 0020 #include <QHash> 0021 #include <QString> 0022 0023 #include "amarok_sqlcollection_export.h" 0024 0025 0026 namespace Collections { 0027 class SqlCollection; 0028 } 0029 0030 /** The DatabaseUpdater class is a collection of function that can update the sql database from previous versions or create it from new. 0031 */ 0032 class AMAROK_SQLCOLLECTION_EXPORT DatabaseUpdater { 0033 public: 0034 explicit DatabaseUpdater( Collections::SqlCollection *collection ); 0035 ~DatabaseUpdater(); 0036 0037 static int expectedDatabaseVersion(); 0038 0039 /** 0040 * Return true if the current database schema is outdated or non-existent and needs to 0041 * be updated using to update() method. 0042 */ 0043 bool needsUpdate() const; 0044 0045 /** 0046 * Return true if database schema already exists in the database. When this method 0047 * returns false, needsUpdate() returns true. 0048 */ 0049 bool schemaExists() const; 0050 0051 /** 0052 * Updates the database to @see expectedDatabaseVersion() 0053 * @returns true if a update was performed, false otherwise 0054 */ 0055 bool update(); 0056 0057 void upgradeVersion1to2(); 0058 void upgradeVersion2to3(); 0059 void upgradeVersion3to4(); 0060 void upgradeVersion4to5(); 0061 void upgradeVersion5to6(); 0062 void upgradeVersion6to7(); 0063 void upgradeVersion7to8(); 0064 void upgradeVersion8to9(); 0065 void upgradeVersion9to10(); 0066 void upgradeVersion10to11(); 0067 void upgradeVersion11to12(); 0068 void upgradeVersion12to13(); 0069 void upgradeVersion13to14(); 0070 void upgradeVersion14to15(); 0071 0072 /** Checks the given table for redundant entries. 0073 * Table can be artist,album,genre,composer,urls or year 0074 * Note that you should check album table first so that the rest can 0075 * be deleted fully. 0076 * Note: it can handle also the directories table but that is better 0077 * be left to the ScannerProcessor 0078 * 0079 * TODO: also check the remaining 8 tables 0080 */ 0081 void deleteAllRedundant( const QString &type ); 0082 0083 /** 0084 * Delete all entries from @p table with broken link to directories table. Currently 0085 * had only sense on the urls table. 0086 */ 0087 void deleteOrphanedByDirectory( const QString &table ); 0088 0089 /** 0090 * Use on tables that link to non-existent entries in the urls table, for example 0091 * urls_labels, statistics, lyrics. @param table must have a column named url. 0092 */ 0093 void deleteOrphanedByUrl( const QString &table ); 0094 0095 void removeFilesInDir( int deviceid, const QString &rdir ); 0096 0097 /** Cleans up the database 0098 * The current functionality is quite fuzzy because it does not have anything. 0099 * to clean. 0100 */ 0101 void cleanupDatabase(); 0102 0103 /** Checks all tables for errors. 0104 * It does not try to repair as this could be fatal. 0105 * The check results should be in the log file so the user would send them 0106 * to the developers upon request. 0107 */ 0108 void checkTables( bool full = true ); 0109 0110 void writeCSVFile( const QString &table, const QString &filename, bool forceDebug = false ); 0111 0112 static int textColumnLength() { return 255; } 0113 0114 private: 0115 /** creates all the necessary tables, indexes etc. for the database */ 0116 void createTables() const; 0117 0118 int adminValue( const QString &key ) const; 0119 0120 Collections::SqlCollection *m_collection; 0121 bool m_debugDatabaseContent; 0122 }; 0123 0124 #endif