#include #include "csp/db/sqlite_db.h" #include namespace { int CountTable(sqlite3* db, const char* table_name) { sqlite3_stmt* stmt = nullptr; const char* sql = "SELECT COUNT(1) FROM sqlite_master WHERE type='table' AND name=?"; REQUIRE(sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr) == SQLITE_OK); REQUIRE(sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT) == SQLITE_OK); REQUIRE(sqlite3_step(stmt) == SQLITE_ROW); const int v = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); return v; } } // namespace TEST_CASE("migrations create core tables") { auto db = csp::db::SqliteDb::OpenMemory(); csp::db::ApplyMigrations(db); REQUIRE(CountTable(db.raw(), "users") == 1); REQUIRE(CountTable(db.raw(), "sessions") == 1); REQUIRE(CountTable(db.raw(), "user_experience") == 1); REQUIRE(CountTable(db.raw(), "user_experience_logs") == 1); REQUIRE(CountTable(db.raw(), "problems") == 1); REQUIRE(CountTable(db.raw(), "problem_tags") == 1); REQUIRE(CountTable(db.raw(), "submissions") == 1); REQUIRE(CountTable(db.raw(), "wrong_book") == 1); REQUIRE(CountTable(db.raw(), "contests") == 1); REQUIRE(CountTable(db.raw(), "contest_problems") == 1); REQUIRE(CountTable(db.raw(), "contest_registrations") == 1); REQUIRE(CountTable(db.raw(), "contest_modifiers") == 1); REQUIRE(CountTable(db.raw(), "seasons") == 1); REQUIRE(CountTable(db.raw(), "season_reward_tracks") == 1); REQUIRE(CountTable(db.raw(), "season_user_progress") == 1); REQUIRE(CountTable(db.raw(), "season_reward_claims") == 1); REQUIRE(CountTable(db.raw(), "loot_drop_logs") == 1); REQUIRE(CountTable(db.raw(), "kb_articles") == 1); REQUIRE(CountTable(db.raw(), "kb_article_links") == 1); REQUIRE(CountTable(db.raw(), "kb_knowledge_claims") == 1); REQUIRE(CountTable(db.raw(), "kb_weekly_tasks") == 1); REQUIRE(CountTable(db.raw(), "kb_weekly_bonus_logs") == 1); REQUIRE(CountTable(db.raw(), "import_jobs") == 1); REQUIRE(CountTable(db.raw(), "import_job_items") == 1); REQUIRE(CountTable(db.raw(), "problem_drafts") == 1); REQUIRE(CountTable(db.raw(), "problem_solution_jobs") == 1); REQUIRE(CountTable(db.raw(), "problem_solutions") == 1); REQUIRE(CountTable(db.raw(), "source_crystal_settings") == 1); REQUIRE(CountTable(db.raw(), "source_crystal_accounts") == 1); REQUIRE(CountTable(db.raw(), "source_crystal_transactions") == 1); REQUIRE(CountTable(db.raw(), "user_achievement_milestones") == 1); }