Lightweight 0.20260303.0
Loading...
Searching...
No Matches
SQL Migration

Classes and functions for SQL schema migrations. More...

Classes

struct  Lightweight::SqlMigration::MigrationTimestamp
 
struct  Lightweight::SqlMigration::ChecksumVerificationResult
 
struct  Lightweight::SqlMigration::RevertResult
 
struct  Lightweight::SqlMigration::MigrationStatus
 
struct  Lightweight::SqlMigration::MigrationRelease
 
class  Lightweight::SqlMigration::MigrationManager
 
class  Lightweight::SqlMigration::MigrationBase
 
struct  Lightweight::SqlMigration::MigrationMetadata
 
class  Lightweight::SqlMigration::MigrationLock
 

Macros

#define LIGHTWEIGHT_MIGRATION_PLUGIN()
 
#define LIGHTWEIGHT_MIGRATION_INSTANCE(timestamp)   migration_##timestamp
 Represents the C++ migration object for a given timestamped migration.
 
#define LIGHTWEIGHT_SQL_MIGRATION(timestamp, description)
 Creates a new migration.
 
#define LIGHTWEIGHT_SQL_RELEASE(version, highestTimestamp)
 Associates a software release (version string) with the highest migration timestamp present at the time of that release.
 

Detailed Description

Classes and functions for SQL schema migrations.

Macro Definition Documentation

◆ LIGHTWEIGHT_MIGRATION_PLUGIN

#define LIGHTWEIGHT_MIGRATION_PLUGIN ( )
Value:
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
extern "C" LIGHTWEIGHT_EXPORT Lightweight::SqlMigration::MigrationManager* AcquireMigrationManager() \
{ \
}
static LIGHTWEIGHT_API MigrationManager & GetInstance()

Requires the user to call LIGHTWEIGHT_MIGRATION_PLUGIN() in exactly one CPP file of the migration plugin.

Definition at line 395 of file SqlMigration.hpp.

◆ LIGHTWEIGHT_MIGRATION_INSTANCE

#define LIGHTWEIGHT_MIGRATION_INSTANCE (   timestamp)    migration_##timestamp

Represents the C++ migration object for a given timestamped migration.

Parameters
timestampTimestamp of the migration.

Definition at line 664 of file SqlMigration.hpp.

◆ LIGHTWEIGHT_SQL_MIGRATION

#define LIGHTWEIGHT_SQL_MIGRATION (   timestamp,
  description 
)
Value:
struct Migration_##timestamp: public Lightweight::SqlMigration::MigrationBase \
{ \
/** The migration's timestamp, exposed so @ref TimestampOf can extract it from the type. */ \
static constexpr Lightweight::SqlMigration::MigrationTimestamp TimeStamp { static_cast<uint64_t>(timestamp) }; \
explicit Migration_##timestamp(): \
Lightweight::SqlMigration::MigrationBase(TimeStamp, description) \
{ \
} \
\
void Up(Lightweight::SqlMigrationQueryBuilder& plan) const override; \
void Down(Lightweight::SqlMigrationQueryBuilder& /*plan*/) const override {} \
}; \
\
static Migration_##timestamp _LIGHTWEIGHT_CONCATENATE(migration_, timestamp); \
\
void Migration_##timestamp::Up(Lightweight::SqlMigrationQueryBuilder& plan) const
Query builder for building SQL migration queries.
Definition Migrate.hpp:469

Creates a new migration.

Parameters
timestampTimestamp of the migration.
descriptionDescription of the migration.
Note
The migration will be registered with the migration manager automatically.
#include <Lightweight/SqlMigration.hpp>
LIGHTWEIGHT_SQL_MIGRATION(20260117234120, "Create table 'MyTable'")
{
// Use 'plan' to define the migration steps, for example creating tables.
}
#define LIGHTWEIGHT_SQL_MIGRATION(timestamp, description)
Creates a new migration.
See also
Lightweight::SqlMigrationQueryBuilder

Definition at line 684 of file SqlMigration.hpp.

◆ LIGHTWEIGHT_SQL_RELEASE

#define LIGHTWEIGHT_SQL_RELEASE (   version,
  highestTimestamp 
)
Value:
static ::Lightweight::SqlMigration::detail::ReleaseRegistrar _LIGHTWEIGHT_CONCATENATE_INNER(_lw_release_, __COUNTER__) \
{ \
{ \
(highestTimestamp) \
} \
}

Associates a software release (version string) with the highest migration timestamp present at the time of that release.

Declare one LIGHTWEIGHT_SQL_RELEASE per cut release, alongside the migrations that belong to it. The macro registers with the migration manager at static-initialization time. Multiple releases may coexist in the same translation unit.

Parameters
versionA string literal, e.g. "6.7.0".
highestTimestampAn unsigned integer literal matching the timestamp format used by migrations.
LIGHTWEIGHT_SQL_MIGRATION(20260101120000, "Initial schema") { ... }
LIGHTWEIGHT_SQL_RELEASE("6.6.0", 20260101120000);
LIGHTWEIGHT_SQL_MIGRATION(20260501120000, "Add orders table") { ... }
LIGHTWEIGHT_SQL_RELEASE("6.7.0", 20260501120000);
#define LIGHTWEIGHT_SQL_RELEASE(version, highestTimestamp)
Associates a software release (version string) with the highest migration timestamp present at the ti...

Definition at line 721 of file SqlMigration.hpp.