Simplified a check in unit tests
This commit is contained in:
@@ -397,6 +397,16 @@ namespace lms::db
|
||||
LMS_LOG(DB, INFO, "Analyze complete!");
|
||||
}
|
||||
|
||||
bool Session::areAllTablesEmpty()
|
||||
{
|
||||
const std::vector<std::string> entryList{ utils::fetchQueryResults(_session.query<std::string>("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")) };
|
||||
|
||||
return std::all_of(entryList.cbegin(), entryList.cend(), [this](const std::string& entry) {
|
||||
const auto count{ utils::fetchQuerySingleResult(_session.query<long>("SELECT COUNT(*) FROM " + entry)) };
|
||||
return count == 0;
|
||||
});
|
||||
}
|
||||
|
||||
void Session::retrieveEntriesToAnalyze(std::vector<std::string>& entryList)
|
||||
{
|
||||
auto transaction{ createReadTransaction() };
|
||||
|
||||
@@ -96,6 +96,8 @@ namespace lms::db
|
||||
void retrieveEntriesToAnalyze(std::vector<std::string>& entryList);
|
||||
void analyzeEntry(const std::string& entry);
|
||||
|
||||
bool areAllTablesEmpty(); // need to acquire a read transaction
|
||||
|
||||
void prepareTablesIfNeeded(); // need to run only once at startup
|
||||
bool migrateSchemaIfNeeded(); // returns true if migration was performed
|
||||
void createIndexesIfNeeded();
|
||||
|
||||
@@ -19,23 +19,10 @@
|
||||
|
||||
#include "Common.hpp"
|
||||
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Cluster.hpp"
|
||||
#include "database/Db.hpp"
|
||||
#include "database/Image.hpp"
|
||||
#include "database/Listen.hpp"
|
||||
#include "database/MediaLibrary.hpp"
|
||||
#include "database/Release.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/StarredArtist.hpp"
|
||||
#include "database/StarredRelease.hpp"
|
||||
#include "database/StarredTrack.hpp"
|
||||
#include "database/Track.hpp"
|
||||
#include "database/TrackArtistLink.hpp"
|
||||
#include "database/TrackBookmark.hpp"
|
||||
#include "database/TrackList.hpp"
|
||||
#include "database/Types.hpp"
|
||||
#include "database/User.hpp"
|
||||
|
||||
namespace lms::db::tests
|
||||
{
|
||||
@@ -75,24 +62,9 @@ namespace lms::db::tests
|
||||
{
|
||||
using namespace db;
|
||||
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
EXPECT_EQ(Artist::getCount(session), 0);
|
||||
EXPECT_EQ(Cluster::getCount(session), 0);
|
||||
EXPECT_EQ(ClusterType::getCount(session), 0);
|
||||
EXPECT_EQ(Label::getCount(session), 0);
|
||||
EXPECT_EQ(Listen::getCount(session), 0);
|
||||
EXPECT_EQ(Image::getCount(session), 0);
|
||||
EXPECT_EQ(MediaLibrary::getCount(session), 0);
|
||||
EXPECT_EQ(Release::getCount(session), 0);
|
||||
EXPECT_EQ(ReleaseType::getCount(session), 0);
|
||||
EXPECT_EQ(StarredArtist::getCount(session), 0);
|
||||
EXPECT_EQ(StarredRelease::getCount(session), 0);
|
||||
EXPECT_EQ(StarredTrack::getCount(session), 0);
|
||||
EXPECT_EQ(Track::getCount(session), 0);
|
||||
EXPECT_EQ(TrackBookmark::getCount(session), 0);
|
||||
EXPECT_EQ(TrackList::getCount(session), 0);
|
||||
EXPECT_EQ(User::getCount(session), 0);
|
||||
EXPECT_TRUE(session.areAllTablesEmpty());
|
||||
}
|
||||
|
||||
TEST_F(DatabaseFixture, vacuum)
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace lms::artwork
|
||||
virtual std::shared_ptr<image::IEncodedImage> getImage(db::ImageId imageId, std::optional<image::ImageSize> width) = 0;
|
||||
virtual std::shared_ptr<image::IEncodedImage> getTrackEmbeddedImage(db::TrackEmbeddedImageId trackEmbeddedImageId, std::optional<image::ImageSize> width) = 0;
|
||||
|
||||
// Svg images dont have image "size"
|
||||
// Svg images don't have image "size"
|
||||
virtual std::shared_ptr<image::IEncodedImage> getDefaultReleaseCover() = 0;
|
||||
virtual std::shared_ptr<image::IEncodedImage> getDefaultArtistImage() = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user