The portal's v2 API replaced nested categories (proclamation_categories.parent_id)
with flat categories plus tag-like groups: a proclamation now belongs to one
category and optionally one group. This lets the Proclamation Options page drop
its special-cased two-level tree.
Database:
- Add the proclamation_groups table (id, name, sort_order) and a
proclamations.group_id column.
- Drop parent_id from the proclamation_categories DDL so fresh databases get a
flat table.
- runMigrations() creates the new table/column, then runs a one-time
transactional v1->v2 migration keyed on PRAGMA user_version: every legacy
sub-category becomes a group (its id is preserved), proclamations that
pointed at a sub-category are remapped to (parent category, new group), and
the now-stale sub-category rows are deleted. selected flags are never
touched, so user choices survive. No network is needed, so offline kiosks
migrate at startup; re-running is a no-op.
- Add replaceGroups() and getAllGroups(); stop reading/writing parent_id.
API sync:
- Add PATH_GROUPS ("/groups") and parseGroupsJson().
- parseProclamationsJson() now also reads groupId.
- syncProclamationsFromApi() fetches /proclamations, /categories and /groups,
leaves the database untouched if any request or parse fails, then replaces
categories, replaces groups and upserts proclamations.
Proclamation Options page:
- FlatItem is now Category / Group / Proclamation.
- Each category lists only the groups that have at least one member in that
category, so impossible pairings (e.g. Physical/Prayers) never render.
- Proclamations with no group, or with a group the portal has removed, sit
directly under the category. Groups are collapsible and use a distinct color.
Tests:
- test_db: groups round-trip plus a legacy->v2 migration test asserting the
group is created, proclamations are remapped, selection is preserved and a
second initialize() is a no-op.
- test_proclamation_sync / test_api_client: parse groupId, parse groups, and
the live smoke test now also fetches /groups.
Docs: README database table and AGENTS notes updated for groups.
This commit is contained in:
+100
-4
@@ -185,23 +185,119 @@ TEST(DatabaseManagerTest, ReplaceAndReadCategories) {
|
||||
DbFixture fx("test_rw_db_cats.db");
|
||||
|
||||
std::vector<ProclamationCategoryRecord> cats;
|
||||
cats.push_back({3, "Root", 0, 1});
|
||||
cats.push_back({7, "Child", 3, 2});
|
||||
cats.push_back({3, "Spiritual", 1});
|
||||
cats.push_back({7, "Physical", 2});
|
||||
|
||||
ASSERT_TRUE(fx.db.replaceCategories(cats));
|
||||
|
||||
auto all = fx.db.getAllCategories();
|
||||
ASSERT_EQ(all.size(), 2u);
|
||||
EXPECT_EQ(all[0].id, 3);
|
||||
EXPECT_EQ(all[0].parent_id, 0);
|
||||
EXPECT_EQ(all[0].name, "Spiritual");
|
||||
EXPECT_EQ(all[0].sort_order, 1);
|
||||
EXPECT_EQ(all[1].id, 7);
|
||||
EXPECT_EQ(all[1].parent_id, 3);
|
||||
EXPECT_EQ(all[1].name, "Physical");
|
||||
EXPECT_EQ(all[1].sort_order, 2);
|
||||
|
||||
// Replacing wipes previous categories.
|
||||
ASSERT_TRUE(fx.db.replaceCategories({}));
|
||||
EXPECT_EQ(fx.db.getAllCategories().size(), 0u);
|
||||
}
|
||||
|
||||
TEST(DatabaseManagerTest, ReplaceAndReadGroups) {
|
||||
DbFixture fx("test_rw_db_groups.db");
|
||||
|
||||
std::vector<ProclamationGroupRecord> groups;
|
||||
groups.push_back({10, "Prayers", 2});
|
||||
groups.push_back({4, "Affirmations", 1});
|
||||
|
||||
ASSERT_TRUE(fx.db.replaceGroups(groups));
|
||||
|
||||
auto all = fx.db.getAllGroups();
|
||||
ASSERT_EQ(all.size(), 2u);
|
||||
// Ordered by sort_order, not by id.
|
||||
EXPECT_EQ(all[0].id, 4);
|
||||
EXPECT_EQ(all[0].name, "Affirmations");
|
||||
EXPECT_EQ(all[1].id, 10);
|
||||
EXPECT_EQ(all[1].name, "Prayers");
|
||||
|
||||
ASSERT_TRUE(fx.db.replaceGroups({}));
|
||||
EXPECT_EQ(fx.db.getAllGroups().size(), 0u);
|
||||
}
|
||||
|
||||
TEST(DatabaseManagerTest, MigratesLegacySubCategoriesToGroups) {
|
||||
const std::string path =
|
||||
(std::filesystem::temp_directory_path() / "test_rw_db_migrate_v1.db").string();
|
||||
if (std::filesystem::exists(path)) {
|
||||
std::filesystem::remove(path);
|
||||
}
|
||||
|
||||
// Build a pre-v2 database by hand: a two-level category tree and a
|
||||
// proclamation selected inside a sub-category.
|
||||
{
|
||||
sqlite3* raw = nullptr;
|
||||
ASSERT_EQ(sqlite3_open(path.c_str(), &raw), SQLITE_OK);
|
||||
const char* legacy =
|
||||
"CREATE TABLE proclamations ("
|
||||
" id TEXT PRIMARY KEY, title TEXT NOT NULL, content TEXT NOT NULL,"
|
||||
" solfeggio_freq_hz REAL DEFAULT 528.0, category TEXT DEFAULT 'general',"
|
||||
" is_active INTEGER DEFAULT 1, selected INTEGER DEFAULT 0,"
|
||||
" category_id INTEGER DEFAULT 0, solfeggio_frequency_id INTEGER DEFAULT 0,"
|
||||
" created_at DATETIME DEFAULT CURRENT_TIMESTAMP);"
|
||||
"CREATE TABLE proclamation_categories ("
|
||||
" id INTEGER PRIMARY KEY, name TEXT NOT NULL,"
|
||||
" parent_id INTEGER DEFAULT 0, sort_order INTEGER DEFAULT 0);"
|
||||
"INSERT INTO proclamation_categories (id, name, parent_id, sort_order)"
|
||||
" VALUES (3,'Spiritual',0,1),(7,'Inner',3,2);"
|
||||
"INSERT INTO proclamations (id,title,content,category_id,solfeggio_frequency_id,selected)"
|
||||
" VALUES ('p1','Peace','x',7,2,1),('p2','Root-level','y',3,5,0);";
|
||||
char* err = nullptr;
|
||||
int rc = sqlite3_exec(raw, legacy, nullptr, nullptr, &err);
|
||||
if (err) sqlite3_free(err);
|
||||
sqlite3_close(raw);
|
||||
ASSERT_EQ(rc, SQLITE_OK);
|
||||
}
|
||||
|
||||
DatabaseManager db;
|
||||
ASSERT_TRUE(db.initialize(path));
|
||||
|
||||
// Each former sub-category becomes a group; only the root remains a category.
|
||||
auto groups = db.getAllGroups();
|
||||
ASSERT_EQ(groups.size(), 1u);
|
||||
EXPECT_EQ(groups[0].id, 7);
|
||||
EXPECT_EQ(groups[0].name, "Inner");
|
||||
|
||||
auto cats = db.getAllCategories();
|
||||
ASSERT_EQ(cats.size(), 1u);
|
||||
EXPECT_EQ(cats[0].id, 3);
|
||||
EXPECT_EQ(cats[0].name, "Spiritual");
|
||||
|
||||
// Proclamations pointing at the old sub-category are remapped to the root
|
||||
// category + the new group; selection is preserved.
|
||||
auto procs = db.getAllProclamations();
|
||||
ASSERT_EQ(procs.size(), 2u);
|
||||
for (const auto& p : procs) {
|
||||
EXPECT_EQ(p.category_id, 3) << "proclamation " << p.id;
|
||||
if (p.id == "p1") {
|
||||
EXPECT_EQ(p.group_id, 7);
|
||||
EXPECT_TRUE(p.selected);
|
||||
} else if (p.id == "p2") {
|
||||
EXPECT_EQ(p.group_id, 0);
|
||||
EXPECT_FALSE(p.selected);
|
||||
}
|
||||
}
|
||||
|
||||
// Re-running the migration is a no-op (user_version gate + idempotent SQL).
|
||||
db.close();
|
||||
ASSERT_TRUE(db.initialize(path));
|
||||
EXPECT_EQ(db.getAllGroups().size(), 1u);
|
||||
EXPECT_EQ(db.getAllCategories().size(), 1u);
|
||||
EXPECT_EQ(db.getAllProclamations().size(), 2u);
|
||||
|
||||
db.close();
|
||||
std::filesystem::remove(path);
|
||||
}
|
||||
|
||||
TEST(DatabaseManagerTest, SyncAudioFilesUpsertsAndDeletesMissing) {
|
||||
DbFixture fx("test_rw_db_audio.db");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user