mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-04 23:24:49 -04:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
25
db/migrate/20251128200506_add_description_to_crops.rb
Normal file
25
db/migrate/20251128200506_add_description_to_crops.rb
Normal 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
|
||||
Reference in New Issue
Block a user