Class: Mbeditor::SchemaService
- Inherits:
-
Object
- Object
- Mbeditor::SchemaService
- Defined in:
- app/services/mbeditor/schema_service.rb
Overview
Parses db/schema.rb or db/structure.sql to extract table definitions. Returns nil when the schema file is missing or the table is not found.
Return format:
{
table: "users",
model: "User",
columns: [{ name: "id", type: "integer" }, ...],
indexes: [{ name: "idx_users_on_email", columns: ["email"], unique: true }]
}
Constant Summary collapse
- SCHEMA_RB_PATH =
"db/schema.rb"- STRUCTURE_SQL_PATH =
"db/structure.sql"
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(model_name, workspace_root) ⇒ SchemaService
constructor
A new instance of SchemaService.
Constructor Details
#initialize(model_name, workspace_root) ⇒ SchemaService
Returns a new instance of SchemaService.
18 19 20 21 |
# File 'app/services/mbeditor/schema_service.rb', line 18 def initialize(model_name, workspace_root) @model_name = model_name.to_s.strip @workspace_root = workspace_root.to_s end |
Instance Method Details
#call ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/mbeditor/schema_service.rb', line 23 def call return nil if @model_name.empty? || @workspace_root.empty? table_name = derive_table_name(@model_name) # Try schema.rb first (Ruby format) result = try_schema_rb(table_name) return result if result # Try structure.sql (SQL format) result = try_structure_sql(table_name) return result if result Rails.logger.debug("SchemaService: table '#{table_name}' (from model '#{@model_name}') not found in db/schema.rb or db/structure.sql. Check if model has custom table_name.") nil end |