Player12
An open source football management simulator
Loading...
Searching...
No Matches
migrations.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <sqlite3.h>
12
13#include <span>
14#include <string>
15#include <string_view>
16#include <vector>
17
19#include "global/build_info.h"
20
22
24namespace SaveFormat
25{
26inline constexpr std::string_view FORMAT_ID = "open-football-career";
27inline const std::string_view GAME_VERSION = BuildInfo::version();
28inline constexpr std::string_view ENGINE_VERSION = "1.0.0-player12.1";
29inline constexpr std::string_view RULES_EDITION = "2026-27";
30inline constexpr int RNG_VERSION = 2; // 2: platform-independent distributions
31inline constexpr int SIM_VERSION = 1;
32} // namespace SaveFormat
33
43namespace Migrations
44{
47{
48 std::string_view table;
49 std::string_view column;
50 std::string_view definition;
51};
52
55{
56 sqlite3* db = nullptr;
58 bool fresh = false;
59};
60
62{
63 int number = 0;
64 std::string_view name;
66 std::span<const ColumnSpec> columns;
68 void (*apply)(const MigrationContext&) = nullptr;
69};
70
72std::span<const Migration> registry();
73
76
78std::string checksum(const Migration& migration);
79
85int readSchemaVersion(sqlite3* db);
86
89{
90 public:
92 int found;
94};
95
97{
98 int from_version = 0;
99 int to_version = 0;
100 bool fresh = false;
102 std::vector<int> applied;
107 std::vector<int> repaired;
108};
109
118 std::span<const Migration> migrations = registry());
119
121bool tableExists(sqlite3* db, std::string_view table);
122
124bool columnExists(sqlite3* db, std::string_view table, std::string_view column);
125
130int foreignKeyIssues(sqlite3* db);
131} // namespace Migrations
Manages the SQLite database connection and transaction lifecycle.
Definition database_connection.h:24
Exception thrown for database-related errors.
Definition database_exception.h:19
Definition migrations.h:89
int supported
Definition migrations.h:93
int found
Definition migrations.h:92
std::string_view version()
Definition build_info.cpp:32
Definition migrations.h:44
std::string checksum(const Migration &migration)
Definition migration_runner.cpp:193
bool columnExists(sqlite3 *db, std::string_view table, std::string_view column)
Definition migration_runner.cpp:174
int currentSchemaVersion()
Definition registry.cpp:249
int readSchemaVersion(sqlite3 *db)
Definition migration_runner.cpp:217
bool tableExists(sqlite3 *db, std::string_view table)
Definition migration_runner.cpp:157
MigrationReport migrate(const DatabaseConnection &connection, std::span< const Migration > migrations=registry())
Definition migration_runner.cpp:249
std::span< const Migration > registry()
Definition registry.cpp:244
int foreignKeyIssues(sqlite3 *db)
Definition migration_runner.cpp:229
Definition migrations.h:25
constexpr std::string_view FORMAT_ID
Definition migrations.h:26
constexpr std::string_view RULES_EDITION
Definition migrations.h:29
constexpr std::string_view ENGINE_VERSION
Definition migrations.h:28
constexpr int SIM_VERSION
Definition migrations.h:31
constexpr int RNG_VERSION
Definition migrations.h:30
const std::string_view GAME_VERSION
Definition migrations.h:27
std::string_view column
Definition runtime_editor_validation.cpp:45
std::string_view table
Definition runtime_editor_validation.cpp:44
Definition migrations.h:47
std::string_view column
Definition migrations.h:49
std::string_view definition
Type and constraints, e.g. "INTEGER".
Definition migrations.h:50
std::string_view table
Definition migrations.h:48
Definition migrations.h:55
sqlite3 * db
Definition migrations.h:56
bool fresh
Definition migrations.h:58
Definition migrations.h:97
std::vector< int > repaired
Definition migrations.h:107
int from_version
Definition migrations.h:98
bool fresh
Definition migrations.h:100
int to_version
Definition migrations.h:99
std::vector< int > applied
Definition migrations.h:102
Definition migrations.h:62
std::string_view name
Definition migrations.h:64
int number
Definition migrations.h:63
std::span< const ColumnSpec > columns
Definition migrations.h:66
void(* apply)(const MigrationContext &)
Definition migrations.h:68