#include <SqlMigration.hpp>
Main API to use for managing SQL migrations
This class is a singleton and can be accessed using the GetInstance() method.
Definition at line 81 of file SqlMigration.hpp.
◆ MigrationList
| using Lightweight::SqlMigration::MigrationManager::MigrationList = std::list<MigrationBase const*> |
◆ ExecuteCallback
| using Lightweight::SqlMigration::MigrationManager::ExecuteCallback = std::function<void(MigrationBase const& , size_t , size_t )> |
◆ GetInstance()
| static LIGHTWEIGHT_API MigrationManager & Lightweight::SqlMigration::MigrationManager::GetInstance |
( |
| ) |
|
|
static |
Get the singleton instance of the migration manager.
- Returns
- Reference to the migration manager. Get the singleton instance of the migration manager.
-
Reference to the migration manager.
◆ AddMigration()
| LIGHTWEIGHT_API void Lightweight::SqlMigration::MigrationManager::AddMigration |
( |
MigrationBase const * |
migration | ) |
|
Add a migration to the manager.
- Parameters
-
| migration | Pointer to the migration to add. |
◆ GetAllMigrations()
| LIGHTWEIGHT_API MigrationList const & Lightweight::SqlMigration::MigrationManager::GetAllMigrations |
( |
| ) |
const |
|
noexcept |
Get all migrations that have been added to the manager.
- Returns
- List of migrations.
◆ GetMigration()
Get a migration by timestamp.
- Parameters
-
| timestamp | Timestamp of the migration to get. |
- Returns
- Pointer to the migration if found, nullptr otherwise.
◆ RemoveAllMigrations()
| LIGHTWEIGHT_API void Lightweight::SqlMigration::MigrationManager::RemoveAllMigrations |
( |
| ) |
|
Remove all migrations from the manager.
This function is useful if the migration manager should be reset.
◆ GetPending()
| LIGHTWEIGHT_API std::list< MigrationBase const * > Lightweight::SqlMigration::MigrationManager::GetPending |
( |
| ) |
const |
|
noexcept |
Get all migrations that have not been applied yet.
- Returns
- List of pending migrations.
◆ ApplySingleMigration()
| LIGHTWEIGHT_API void Lightweight::SqlMigration::MigrationManager::ApplySingleMigration |
( |
MigrationBase const & |
migration | ) |
|
Apply a single migration from a migration object.
- Parameters
-
| migration | Pointer to the migration to apply. |
◆ RevertSingleMigration()
| LIGHTWEIGHT_API void Lightweight::SqlMigration::MigrationManager::RevertSingleMigration |
( |
MigrationBase const & |
migration | ) |
|
Revert a single migration from a migration object.
- Parameters
-
| migration | Pointer to the migration to revert. |
◆ ApplyPendingMigrations()
| LIGHTWEIGHT_API size_t Lightweight::SqlMigration::MigrationManager::ApplyPendingMigrations |
( |
ExecuteCallback const & |
feedbackCallback = {} | ) |
|
Apply all migrations that have not been applied yet.
- Parameters
-
| feedbackCallback | Callback to be called for each migration. |
- Returns
- Number of applied migrations.
◆ GetAppliedMigrationIds()
| LIGHTWEIGHT_API std::vector< MigrationTimestamp > Lightweight::SqlMigration::MigrationManager::GetAppliedMigrationIds |
( |
| ) |
const |
Get all applied migration IDs.
- Returns
- Vector of applied migration IDs.
◆ GetDataMapper()
| LIGHTWEIGHT_API DataMapper & Lightweight::SqlMigration::MigrationManager::GetDataMapper |
( |
| ) |
const |
|
inline |
◆ CloseDataMapper()
| LIGHTWEIGHT_API void Lightweight::SqlMigration::MigrationManager::CloseDataMapper |
( |
| ) |
|
Close the data mapper.
This function is useful if explicitly closing the connection is desired before the migration manager is destroyed.
◆ Transaction()
| LIGHTWEIGHT_API SqlTransaction Lightweight::SqlMigration::MigrationManager::Transaction |
( |
| ) |
|
Get a transaction for the data mapper.
- Returns
- Transaction.
◆ PreviewMigration()
| LIGHTWEIGHT_API std::vector< std::string > Lightweight::SqlMigration::MigrationManager::PreviewMigration |
( |
MigrationBase const & |
migration | ) |
const |
Preview SQL statements for a single migration without executing.
This is useful for dry-run mode to see what SQL would be executed.
- Parameters
-
| migration | The migration to preview. |
- Returns
- Vector of SQL statements that would be executed.
◆ PreviewPendingMigrations()
| LIGHTWEIGHT_API std::vector< std::string > Lightweight::SqlMigration::MigrationManager::PreviewPendingMigrations |
( |
ExecuteCallback const & |
feedbackCallback = {} | ) |
const |
Preview SQL statements for all pending migrations without executing.
This is useful for dry-run mode to see what SQL would be executed.
- Parameters
-
| feedbackCallback | Optional callback to be called for each migration. |
- Returns
- Vector of all SQL statements that would be executed.
◆ VerifyChecksums()
Verify checksums of all applied migrations.
Compares the stored checksums in the database with the computed checksums of the current migration definitions. This helps detect if migrations have been modified after they were applied.
- Returns
- Vector of verification results for migrations with mismatched or missing checksums.
◆ MarkMigrationAsApplied()
| LIGHTWEIGHT_API void Lightweight::SqlMigration::MigrationManager::MarkMigrationAsApplied |
( |
MigrationBase const & |
migration | ) |
|
Mark a migration as applied without executing its Up() method.
This is useful for:
- Baseline migrations when setting up an existing database
- Marking migrations that were applied manually or through other means
- Skipping migrations that are not applicable to a specific environment
- Parameters
-
| migration | The migration to mark as applied. |
- Exceptions
-
| std::runtime_error | if the migration is already applied. |
◆ RevertToMigration()
| LIGHTWEIGHT_API RevertResult Lightweight::SqlMigration::MigrationManager::RevertToMigration |
( |
MigrationTimestamp |
target, |
|
|
ExecuteCallback const & |
feedbackCallback = {} |
|
) |
| |
Revert all migrations applied after the target timestamp.
This method reverts migrations in reverse chronological order, rolling back from the most recent to just after the target. The target migration itself is NOT reverted.
- Parameters
-
| target | Target timestamp to revert to. Migrations > target are reverted. |
| feedbackCallback | Optional callback for progress updates. |
- Returns
- Result containing list of reverted timestamps or error information.
- Note
- Stops on first error. Previously reverted migrations in this call are NOT rolled back.
◆ GetMigrationStatus()
| LIGHTWEIGHT_API MigrationStatus Lightweight::SqlMigration::MigrationManager::GetMigrationStatus |
( |
| ) |
const |
Get a summary status of all migrations.
This method provides a quick overview of the migration state without needing to iterate through individual migrations.
- Returns
- Status struct with counts of applied, pending, and mismatched migrations.
The documentation for this class was generated from the following file: