schema: add a method to generate ALTER statement with all properties
In the describe statement, we need to generate `ALTER TABLE` statement with all schema's properties for some tables (cdc log tables). The method prints valid CQL statement with current values of the properties.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user