Made some UI states persistent across sessions, ref #484
This commit is contained in:
@@ -35,7 +35,7 @@ namespace lms::db
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 66 };
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 67 };
|
||||
}
|
||||
|
||||
VersionInfo::VersionInfo()
|
||||
@@ -744,6 +744,22 @@ SELECT
|
||||
session.getDboSession()->execute("UPDATE scan_settings SET scan_version = scan_version + 1");
|
||||
}
|
||||
|
||||
void migrateFromV66(Session& session)
|
||||
{
|
||||
// New way of handling UI settings
|
||||
session.getDboSession()->execute(R"(CREATE TABLE IF NOT EXISTS "ui_state" (
|
||||
"id" integer primary key autoincrement,
|
||||
"version" integer not null,
|
||||
"item" text not null,
|
||||
"value" text not null,
|
||||
"user_id" bigint,
|
||||
constraint "fk_ui_state_user" foreign key ("user_id") references "user" ("id") on delete cascade deferrable initially deferred
|
||||
))");
|
||||
|
||||
session.getDboSession()->execute("ALTER TABLE user DROP COLUMN repeat_all");
|
||||
session.getDboSession()->execute("ALTER TABLE user DROP COLUMN radio");
|
||||
}
|
||||
|
||||
bool doDbMigration(Session& session)
|
||||
{
|
||||
static const std::string outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
||||
@@ -786,6 +802,7 @@ SELECT
|
||||
{ 63, migrateFromV63 },
|
||||
{ 64, migrateFromV64 },
|
||||
{ 65, migrateFromV65 },
|
||||
{ 66, migrateFromV66 },
|
||||
};
|
||||
|
||||
bool migrationPerformed{};
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "database/TrackFeatures.hpp"
|
||||
#include "database/TrackList.hpp"
|
||||
#include "database/TransactionChecker.hpp"
|
||||
#include "database/UIState.hpp"
|
||||
#include "database/User.hpp"
|
||||
|
||||
#include "EnumSetTraits.hpp"
|
||||
@@ -117,6 +118,7 @@ namespace lms::db
|
||||
_session.mapClass<TrackFeatures>("track_features");
|
||||
_session.mapClass<TrackList>("tracklist");
|
||||
_session.mapClass<TrackListEntry>("tracklist_entry");
|
||||
_session.mapClass<UIState>("ui_state");
|
||||
_session.mapClass<User>("user");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "database/UIState.hpp"
|
||||
|
||||
#include "core/ILogger.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/User.hpp"
|
||||
|
||||
#include "IdTypeTraits.hpp"
|
||||
#include "StringViewTraits.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace lms::db
|
||||
{
|
||||
UIState::UIState(std::string_view item, ObjectPtr<User> user)
|
||||
: _item{ item }
|
||||
, _user{ getDboPtr(user) }
|
||||
{
|
||||
}
|
||||
|
||||
UIState::pointer UIState::create(Session& session, std::string_view item, ObjectPtr<User> user)
|
||||
{
|
||||
return session.getDboSession()->add(std::unique_ptr<UIState>{ new UIState{ item, user } });
|
||||
}
|
||||
|
||||
std::size_t UIState::getCount(Session& session)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<int>("SELECT COUNT(*) FROM ui_state"));
|
||||
}
|
||||
|
||||
UIState::pointer UIState::find(Session& session, UIStateId settingId)
|
||||
{
|
||||
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<UIState>>("SELECT ui_s from ui_state ui_s").where("ui_s.id = ?").bind(settingId) };
|
||||
return utils::fetchQuerySingleResult(query);
|
||||
}
|
||||
|
||||
UIState::pointer UIState::find(Session& session, std::string_view item, UserId userId)
|
||||
{
|
||||
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<UIState>>("SELECT ui_s from ui_state ui_s").where("ui_s.item = ?").bind(item).where("ui_s.user_id = ?").bind(userId) };
|
||||
return utils::fetchQuerySingleResult(query);
|
||||
}
|
||||
} // namespace lms::db
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "database/Release.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/Track.hpp"
|
||||
#include "database/UIState.hpp"
|
||||
|
||||
#include "IdTypeTraits.hpp"
|
||||
#include "StringViewTraits.hpp"
|
||||
|
||||
Reference in New Issue
Block a user