Class: Synthra::SchemaVersioning::Analyzer
- Inherits:
-
Object
- Object
- Synthra::SchemaVersioning::Analyzer
- Defined in:
- lib/synthra/schema_versioning.rb
Overview
Migration analyzer
Class Method Summary collapse
-
.analyze(old_schema, new_schema) ⇒ Hash
Detect breaking changes between two schemas.
- .generate_summary(removed, added, type_changes) ⇒ Object
Class Method Details
.analyze(old_schema, new_schema) ⇒ Hash
Detect breaking changes between two schemas
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/synthra/schema_versioning.rb', line 168 def self.analyze(old_schema, new_schema) old_fields = old_schema.fields.map(&:name) new_fields = new_schema.fields.map(&:name) removed_fields = old_fields - new_fields added_fields = new_fields - old_fields common_fields = old_fields & new_fields type_changes = [] common_fields.each do |name| old_field = old_schema.field(name) new_field = new_schema.field(name) if old_field.type_name != new_field.type_name type_changes << { field: name, from: old_field.type_name, to: new_field.type_name } end end { breaking: removed_fields.any? || type_changes.any?, removed_fields: removed_fields, added_fields: added_fields, type_changes: type_changes, summary: generate_summary(removed_fields, added_fields, type_changes) } end |
.generate_summary(removed, added, type_changes) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/synthra/schema_versioning.rb', line 201 def self.generate_summary(removed, added, type_changes) parts = [] parts << "Removed: #{removed.join(', ')}" if removed.any? parts << "Added: #{added.join(', ')}" if added.any? type_changes.each do |change| parts << "Changed #{change[:field]}: #{change[:from]} → #{change[:to]}" end parts.join("\n") end |