13 std::string table_name_;
18 : table_name_(
std::move(table_name)), constraint_(constraint) {}
24 table_name_ +
" constraint: " + constraint_.
name));
27 if (constraint_.
type ==
"INDEX") {
31 return "ALTER TABLE " + table_name_ +
" ADD " + constraint_.
sql_definition +
";";
36 if (constraint_.
name.empty()) {
38 "Constraint name cannot be empty for rollback",
42 if (constraint_.
type ==
"INDEX") {
43 return "DROP INDEX IF EXISTS " + constraint_.
name +
";";
44 }
else if (constraint_.
type ==
"PRIMARY_KEY") {
45 return "ALTER TABLE " + table_name_ +
" DROP PRIMARY KEY;";
47 return "ALTER TABLE " + table_name_ +
" DROP CONSTRAINT " + constraint_.
name +
";";
59 std::string table_name_;
64 : table_name_(
std::move(table_name)), constraint_(constraint) {}
67 if (constraint_.
name.empty()) {
69 "Constraint name cannot be empty", table_name_));
72 if (constraint_.
type ==
"INDEX") {
73 return "DROP INDEX IF EXISTS " + constraint_.
name +
";";
74 }
else if (constraint_.
type ==
"PRIMARY_KEY") {
75 return "ALTER TABLE " + table_name_ +
" DROP PRIMARY KEY;";
77 return "ALTER TABLE " + table_name_ +
" DROP CONSTRAINT " + constraint_.
name +
";";
83 return std::unexpected(
85 "Constraint SQL definition cannot be empty for rollback",
86 table_name_ +
" constraint: " + constraint_.
name));
89 if (constraint_.
type ==
"INDEX") {
92 return "ALTER TABLE " + table_name_ +
" ADD " + constraint_.
sql_definition +
";";
104 std::string table_name_;
111 : table_name_(
std::move(table_name)), old_column_(old_column), new_column_(new_column) {}
114 if (new_column_.
name.empty() || new_column_.
sql_type.empty()) {
116 "Column name and SQL type cannot be empty",
117 table_name_ +
"." + new_column_.
name));
121 return "ALTER TABLE " + table_name_ +
" ALTER COLUMN " + new_column_.
name +
" TYPE " +
126 if (old_column_.
name.empty() || old_column_.
sql_type.empty()) {
127 return std::unexpected(
129 "Original column name and SQL type cannot be empty",
130 table_name_ +
"." + old_column_.
name));
133 return "ALTER TABLE " + table_name_ +
" ALTER COLUMN " + old_column_.
name +
" TYPE " +
ADD CONSTRAINT migration operation.
MigrationResult< std::string > to_sql() const override
AddConstraintOperation(std::string table_name, const ConstraintMetadata &constraint)
MigrationResult< std::string > rollback_sql() const override
OperationType type() const override
DROP CONSTRAINT migration operation.
OperationType type() const override
MigrationResult< std::string > to_sql() const override
DropConstraintOperation(std::string table_name, const ConstraintMetadata &constraint)
MigrationResult< std::string > rollback_sql() const override
Base class for migration operations.
MODIFY COLUMN migration operation.
ModifyColumnOperation(std::string table_name, const ColumnMetadata &old_column, const ColumnMetadata &new_column)
OperationType type() const override
MigrationResult< std::string > to_sql() const override
MigrationResult< std::string > rollback_sql() const override
std::expected< T, MigrationError > MigrationResult
Result type for migration operations.
OperationType
Enum for migration operation types.
static MigrationError make(MigrationErrorType type, const std::string &message, const std::string &context="")
Create a MigrationError with automatic formatting.