feat: Migrate crop description to a dedicated column

This change migrates the crop description from the `openfarm_data` JSONB field to a new, dedicated `description` text column in the `crops` table.

A data migration is included to move the existing description data to the new column. The `OpenFarmData` concern is updated to remove the now-redundant `description` method.
This commit is contained in:
google-labs-jules[bot]
2025-11-29 04:07:25 +00:00
parent d9ba4fabe7
commit 8f6738eefa
4 changed files with 27 additions and 4 deletions

View File

@@ -192,6 +192,7 @@ class CropsController < ApplicationController
:parent_id, :perennial,
:request_notes, :reason_for_rejection,
:rejection_notes,
:description,
:row_spacing, :spread, :height,
:sowing_method, :sun_requirements, :growing_degree_days,
scientific_names_attributes: %i(scientific_name _destroy id)

View File

@@ -19,10 +19,6 @@ module OpenFarmData
fetch_attr('tags_array')
end
def description
fetch_attr('description')
end
def common_names
fetch_attr('common_names')
end

View File

@@ -42,6 +42,7 @@
%span.help-block Living more than two years
%h2 OpenFarm Data
= f.text_area :description, label: 'Description'
= f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0
= f.number_field :spread, label: 'Spread (cm)', min: 0
= f.number_field :height, label: 'Height (cm)', min: 0

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: true
class AddDescriptionToCrops < ActiveRecord::Migration[7.2]
# Temporary model to avoid validation issues
class Crop < ApplicationRecord
end
def up
add_column :crops, :description, :text
# Ensure the new column is available to the temporary model
Crop.reset_column_information
Crop.find_each do |crop|
next if crop.openfarm_data.blank?
description = crop.openfarm_data.dig('attributes', 'description')
crop.update_column(:description, description) if description.present?
end
end
def down
remove_column :crops, :description
end
end