Player12
An open source football management simulator
Loading...
Searching...
No Matches
Migrations Namespace Reference

Classes

struct  ColumnSpec
 
class  FutureVersionError
 
struct  Migration
 
struct  MigrationContext
 
struct  MigrationReport
 

Functions

std::span< const Migration > registry ()
 
int currentSchemaVersion ()
 
std::string checksum (const Migration &migration)
 
int readSchemaVersion (sqlite3 *db)
 
MigrationReport migrate (const DatabaseConnection &connection, std::span< const Migration > migrations=registry())
 
bool tableExists (sqlite3 *db, std::string_view table)
 
bool columnExists (sqlite3 *db, std::string_view table, std::string_view column)
 
int foreignKeyIssues (sqlite3 *db)
 

Detailed Description

Ordered, numbered and transactional schema migrations of a career save.

Every save records the migrations applied to it in schema_migrations and its schema version in save_meta. Opening a save applies the pending migrations in number order, each in one transaction together with its schema_migrations row. See src/database/migrations/README.md for the procedure to add one.

Function Documentation

◆ checksum()

std::string Migrations::checksum ( const Migration &  migration)

Checksum of a migration's declarative content (stored per save).

◆ columnExists()

bool Migrations::columnExists ( sqlite3 *  db,
std::string_view  table,
std::string_view  column 
)

True when table exists and has column.

◆ currentSchemaVersion()

int Migrations::currentSchemaVersion ( )

Highest migration number the game knows (the supported save version).

◆ foreignKeyIssues()

int Migrations::foreignKeyIssues ( sqlite3 *  db)

Foreign key violations, ignoring the free-agents pseudo club (league -1), which is a known sentinel until the sentinel repair migration lands.

◆ migrate()

Migrations::MigrationReport Migrations::migrate ( const DatabaseConnection &  connection,
std::span< const Migration >  migrations = registry() 
)

Brings a database to the current schema: rejects future versions before any write, creates missing tables from schema.sql, applies pending migrations in order (one transaction each) and repairs recorded ones whose columns are missing. A failing migration rolls back, leaves the database at the previous version and throws DatabaseException.

◆ readSchemaVersion()

int Migrations::readSchemaVersion ( sqlite3 *  db)

Schema version recorded in a database: save_meta.schema_version, or the highest schema_migrations number, or 0 for saves from before versioning. Read-only; works on connections opened with SQLITE_OPEN_READONLY.

◆ registry()

std::span< const Migrations::Migration > Migrations::registry ( )

Every migration of the game, ordered by number.

◆ tableExists()

bool Migrations::tableExists ( sqlite3 *  db,
std::string_view  table 
)

True when table exists.