diff --git a/schema/schema.cc b/schema/schema.cc index b3433a118d..6becae632c 100644 --- a/schema/schema.cc +++ b/schema/schema.cc @@ -1002,6 +1002,24 @@ std::ostream& schema::schema_properties(replica::database& db, std::ostream& os) return os; } +std::ostream& schema::describe_alter_with_properties(replica::database& db, std::ostream& os) const { + os << "ALTER "; + if (is_view()) { + if (is_index(db, view_info()->base_id(), *this)) { + on_internal_error(dblog, "ALTER statement is not supported for index"); + } + + os << "MATERIALIZED VIEW "; + } else { + os << "TABLE "; + } + os << cql3::util::maybe_quote(ks_name()) << "." << cql3::util::maybe_quote(cf_name()) << " WITH "; + schema_properties(db, os); + os << ";\n"; + + return os; +} + const sstring& column_definition::name_as_text() const { return column_specification->name->text(); diff --git a/schema/schema.hh b/schema/schema.hh index 82970c7968..0b9d297865 100644 --- a/schema/schema.hh +++ b/schema/schema.hh @@ -934,6 +934,9 @@ public: * (and `ALTER ADD` if the column has been re-added) to the description. */ virtual std::ostream& describe(replica::database& db, std::ostream& os, bool with_internals) const override; + // Generate ALTER TABLE/MATERIALIZED VIEW statement containing all properties with current values. + // The method cannot be used on index, as indexes don't support alter statement. + std::ostream& describe_alter_with_properties(replica::database& db, std::ostream& os) const; friend bool operator==(const schema&, const schema&); const column_mapping& get_column_mapping() const; friend class schema_registry_entry;