diff --git a/cql3/statements/alter_table_statement.cc b/cql3/statements/alter_table_statement.cc index 6432ec11f8..636b45ec2a 100644 --- a/cql3/statements/alter_table_statement.cc +++ b/cql3/statements/alter_table_statement.cc @@ -39,6 +39,7 @@ * along with Scylla. If not, see . */ +#include #include "cql3/statements/alter_table_statement.hh" #include "index/secondary_index_manager.hh" #include "prepared_statement.hh" @@ -411,21 +412,37 @@ std::pair> alter_table_statement::prepare_ return make_pair(std::move(cfm), std::move(view_updates)); } +future, std::vector>> +alter_table_statement::prepare_schema_mutations(query_processor& qp) const { + database& db = qp.db(); + auto& mm = qp.get_migration_manager(); + auto [cfm, view_updates] = prepare_schema_update(db); + auto m = co_await mm.prepare_column_family_update_announcement(cfm.build(), false, std::move(view_updates), std::nullopt); + + using namespace cql_transport; + auto ret = ::make_shared( + event::schema_change::change_type::UPDATED, + event::schema_change::target_type::TABLE, + keyspace(), + column_family()); + + co_return std::make_pair(std::move(ret), std::move(m)); +} + future> alter_table_statement::announce_migration(query_processor& qp) const { database& db = qp.db(); + auto& mm = qp.get_migration_manager(); auto [cfm, view_updates] = prepare_schema_update(db); + co_await mm.announce_column_family_update(cfm.build(), false, std::move(view_updates), std::nullopt); - return qp.get_migration_manager().announce_column_family_update(cfm.build(), false, std::move(view_updates), std::nullopt) - .then([this] { - using namespace cql_transport; - return ::make_shared( - event::schema_change::change_type::UPDATED, - event::schema_change::target_type::TABLE, - keyspace(), - column_family()); - }); + using namespace cql_transport; + co_return ::make_shared( + event::schema_change::change_type::UPDATED, + event::schema_change::target_type::TABLE, + keyspace(), + column_family()); } std::unique_ptr diff --git a/cql3/statements/alter_table_statement.hh b/cql3/statements/alter_table_statement.hh index 3689272ad8..c8e9f8dab7 100644 --- a/cql3/statements/alter_table_statement.hh +++ b/cql3/statements/alter_table_statement.hh @@ -86,6 +86,9 @@ public: virtual future> announce_migration(query_processor& qp) const override; virtual std::unique_ptr prepare(database& db, cql_stats& stats) override; virtual future<::shared_ptr> execute(query_processor& qp, service::query_state& state, const query_options& options) const override; + + future, std::vector>> prepare_schema_mutations(query_processor& qp) const override; + virtual bool has_prepare_schema_mutations() const override { return true; } private: void add_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const; void alter_column(const schema& schema, const table& cf, schema_builder& cfm, std::vector& view_updates, const column_identifier& column_name, const cql3_type validator, const column_definition* def, bool is_static) const;