relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::migrations::cli Namespace Reference

Classes

struct  CommandLineArgs
 Command-line argument parsing result. More...
 

Typedefs

using MigrationGenerator = std::function< MigrationResult< Migration >(const std::string &, const std::string &)>
 Type alias for a function that generates a migration between two versions.
 
using CreateMigrationGenerator = std::function< MigrationResult< Migration >(const std::string &)>
 Type alias for a function that generates a create table migration.
 
using DropMigrationGenerator = std::function< MigrationResult< Migration >(const std::string &)>
 Type alias for a function that generates a drop table migration.
 

Functions

void print_usage (const char *program_name, const std::vector< std::string > &supported_versions={})
 Print usage information for a migration command-line tool.
 
void print_usage (const char *program_name, const std::vector< std::string > &supported_versions, bool create_available, bool drop_available)
 Print usage information for a migration command-line tool with customizable options.
 
void write_migration_to_file (const Migration &migration, const std::string &filename, bool include_rollback=true)
 Write a migration to a SQL file with proper formatting.
 
void print_migration (const Migration &migration)
 Print a migration to the console with formatting.
 
CommandLineArgs parse_args (const std::vector< std::string > &args)
 Parse command-line arguments for migration tools.
 
int run_migration_tool (int argc, char *argv[], const std::vector< std::string > &supported_versions, MigrationGenerator migration_generator, std::optional< CreateMigrationGenerator > create_generator=std::nullopt, std::optional< DropMigrationGenerator > drop_generator=std::nullopt)
 Run a complete migration command-line tool.
 

Typedef Documentation

◆ CreateMigrationGenerator

using relx::migrations::cli::CreateMigrationGenerator = typedef std::function<MigrationResult<Migration>(const std::string&)>

Type alias for a function that generates a create table migration.

Parameters
versionThe version to create
Returns
Migration object containing the create table operation

Definition at line 65 of file command_line_tools.hpp.

◆ DropMigrationGenerator

using relx::migrations::cli::DropMigrationGenerator = typedef std::function<MigrationResult<Migration>(const std::string&)>

Type alias for a function that generates a drop table migration.

Parameters
versionThe version to drop
Returns
Migration object containing the drop table operation

Definition at line 70 of file command_line_tools.hpp.

◆ MigrationGenerator

using relx::migrations::cli::MigrationGenerator = typedef std::function<MigrationResult<Migration>(const std::string&, const std::string&)>

Type alias for a function that generates a migration between two versions.

Parameters
from_versionThe starting version
to_versionThe target version
Returns
Migration object containing the necessary operations

Definition at line 59 of file command_line_tools.hpp.

Function Documentation

◆ parse_args()

CommandLineArgs relx::migrations::cli::parse_args ( const std::vector< std::string > &  args)

Parse command-line arguments for migration tools.

Parameters
argsCommand-line arguments (excluding program name)
Returns
Parsed arguments structure

◆ print_migration()

void relx::migrations::cli::print_migration ( const Migration migration)

Print a migration to the console with formatting.

Parameters
migrationThe migration to print

◆ print_usage() [1/2]

void relx::migrations::cli::print_usage ( const char *  program_name,
const std::vector< std::string > &  supported_versions,
bool  create_available,
bool  drop_available 
)

Print usage information for a migration command-line tool with customizable options.

Parameters
program_nameThe name of the program executable
supported_versionsList of supported version strings (e.g., {"v1", "v2", "v3"})
create_availableWhether CREATE table functionality is available
drop_availableWhether DROP table functionality is available

◆ print_usage() [2/2]

void relx::migrations::cli::print_usage ( const char *  program_name,
const std::vector< std::string > &  supported_versions = {} 
)

Print usage information for a migration command-line tool.

Parameters
program_nameThe name of the program executable
supported_versionsList of supported version strings (e.g., {"v1", "v2", "v3"})

◆ run_migration_tool()

int relx::migrations::cli::run_migration_tool ( int  argc,
char *  argv[],
const std::vector< std::string > &  supported_versions,
MigrationGenerator  migration_generator,
std::optional< CreateMigrationGenerator create_generator = std::nullopt,
std::optional< DropMigrationGenerator drop_generator = std::nullopt 
)

Run a complete migration command-line tool.

Parameters
argcCommand-line argument count
argvCommand-line argument values
supported_versionsList of supported version strings
migration_generatorFunction to generate migrations between versions
create_generatorOptional function to generate create table migrations
drop_generatorOptional function to generate drop table migrations
Returns
Exit code (0 for success, 1 for error)

◆ write_migration_to_file()

void relx::migrations::cli::write_migration_to_file ( const Migration migration,
const std::string &  filename,
bool  include_rollback = true 
)

Write a migration to a SQL file with proper formatting.

Parameters
migrationThe migration to write
filenameThe output filename
include_rollbackWhether to include rollback SQL as comments (default: true)