Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Lightweight::SqlMigration::MigrationBase Class Referenceabstract

#include <SqlMigration.hpp>

Inherited by Lightweight::SqlMigration::Migration< TsValue >.

Public Member Functions

 MigrationBase (MigrationBase const &)=default
 Default copy constructor.
 
 MigrationBase (MigrationBase &&)=delete
 
MigrationBase & operator= (MigrationBase const &)=default
 Default copy assignment operator.
 
MigrationBase & operator= (MigrationBase &&)=delete
 
 MigrationBase (MigrationTimestamp timestamp, std::string_view title)
 Constructs a migration with the given timestamp and title.
 
virtual ~MigrationBase ()
 
virtual void Up (SqlMigrationQueryBuilder &plan) const =0
 
virtual void Down (SqlMigrationQueryBuilder &plan) const
 
virtual bool HasDownImplementation () const noexcept
 
virtual std::vector< MigrationTimestamp > GetDependencies () const
 
virtual std::string_view GetAuthor () const noexcept
 
virtual std::string_view GetDescription () const noexcept
 
MigrationTimestamp GetTimestamp () const noexcept
 
std::string_view GetTitle () const noexcept
 
LIGHTWEIGHT_API std::string ComputeChecksum (SqlQueryFormatter const &formatter) const
 

Detailed Description

Represents a single unique SQL migration.

Definition at line 822 of file SqlMigration.hpp.

Constructor & Destructor Documentation

◆ MigrationBase()

Lightweight::SqlMigration::MigrationBase::MigrationBase ( MigrationTimestamp  timestamp,
std::string_view  title 
)
inline

Constructs a migration with the given timestamp and title.

Definition at line 832 of file SqlMigration.hpp.

References Lightweight::SqlMigration::MigrationManager::AddMigration(), and Lightweight::SqlMigration::MigrationManager::GetInstance().

◆ ~MigrationBase()

virtual Lightweight::SqlMigration::MigrationBase::~MigrationBase ( )
inlinevirtual

Unregisters this migration from the singleton manager the constructor registered it with.

Registration is a side effect of construction, so deregistration has to be one of destruction: otherwise the manager keeps a pointer to a dead object, and its duplicate-timestamp lookup dereferences it. A later migration reusing that storage is then reported as a duplicate of itself.

Definition at line 845 of file SqlMigration.hpp.

References Lightweight::SqlMigration::MigrationManager::GetInstance(), and Lightweight::SqlMigration::MigrationManager::RemoveMigration().

Member Function Documentation

◆ Up()

virtual void Lightweight::SqlMigration::MigrationBase::Up ( SqlMigrationQueryBuilder &  plan) const
pure virtual

Apply the migration.

Parameters
planQuery builder to use for building the migration plan.

◆ Down()

virtual void Lightweight::SqlMigration::MigrationBase::Down ( SqlMigrationQueryBuilder &  plan) const
inlinevirtual

Revert the migration.

Parameters
planQuery builder to use for building the migration plan.

Definition at line 858 of file SqlMigration.hpp.

◆ HasDownImplementation()

virtual bool Lightweight::SqlMigration::MigrationBase::HasDownImplementation ( ) const
inlinevirtualnoexcept

Check if this migration has a Down() implementation for rollback.

This method determines whether the migration can be safely reverted. The default implementation returns false. Derived classes that implement Down() should override this to return true.

Returns
true if Down() is implemented and can revert this migration.

Definition at line 870 of file SqlMigration.hpp.

◆ GetDependencies()

virtual std::vector< MigrationTimestamp > Lightweight::SqlMigration::MigrationBase::GetDependencies ( ) const
inlinevirtual

Get the timestamps of migrations that this migration depends on.

Dependencies are enforced at apply time: each declared dependency must be registered and applied (or pending in the same run, in dependency order) before this migration will run. The default implementation returns no dependencies, preserving timestamp-ordered apply behavior.

Returns
Vector of dependency timestamps. Empty if this migration has none.

Definition at line 883 of file SqlMigration.hpp.

◆ GetAuthor()

virtual std::string_view Lightweight::SqlMigration::MigrationBase::GetAuthor ( ) const
inlinevirtualnoexcept

Get the author of the migration, if any.

Returns
Author string, empty if not set.

Definition at line 891 of file SqlMigration.hpp.

◆ GetDescription()

virtual std::string_view Lightweight::SqlMigration::MigrationBase::GetDescription ( ) const
inlinevirtualnoexcept

Get the long-form description of the migration, if any.

This is a multi-line description in addition to the short title.

Returns
Description string, empty if not set.

Definition at line 901 of file SqlMigration.hpp.

◆ GetTimestamp()

MigrationTimestamp Lightweight::SqlMigration::MigrationBase::GetTimestamp ( ) const
inlinenoexcept

Get the timestamp of the migration.

Returns
Timestamp of the migration.

Definition at line 909 of file SqlMigration.hpp.

◆ GetTitle()

std::string_view Lightweight::SqlMigration::MigrationBase::GetTitle ( ) const
inlinenoexcept

Get the title of the migration.

Returns
Title of the migration.

Definition at line 917 of file SqlMigration.hpp.

◆ ComputeChecksum()

LIGHTWEIGHT_API std::string Lightweight::SqlMigration::MigrationBase::ComputeChecksum ( SqlQueryFormatter const &  formatter) const

Compute SHA-256 checksum of migration's Up() SQL statements.

The checksum is computed from the SQL statements that would be executed by this migration. This allows detecting if a migration has been modified after it was applied.

Parameters
formatterThe SQL query formatter to use for generating SQL.
Returns
SHA-256 hex string (64 characters).

The documentation for this class was generated from the following file: