mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-08-07 05:13:37 -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:
1 parent
d9ba4fabe7
commit
8f6738eefa
4 files changed
+27
-4
No files matched your search
@@ -192,6 +192,7 @@ class CropsController < ApplicationController
|
|||||||
:parent_id, :perennial,
|
:parent_id, :perennial,
|
||||||
:request_notes, :reason_for_rejection,
|
:request_notes, :reason_for_rejection,
|
||||||
:rejection_notes,
|
:rejection_notes,
|
||||||
|
:description,
|
||||||
:row_spacing, :spread, :height,
|
:row_spacing, :spread, :height,
|
||||||
:sowing_method, :sun_requirements, :growing_degree_days,
|
:sowing_method, :sun_requirements, :growing_degree_days,
|
||||||
scientific_names_attributes: %i(scientific_name _destroy id)
|
scientific_names_attributes: %i(scientific_name _destroy id)
|
||||||
|
|||||||
@@ -19,10 +19,6 @@ module OpenFarmData
|
|||||||
fetch_attr('tags_array')
|
fetch_attr('tags_array')
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
|
||||||
fetch_attr('description')
|
|
||||||
end
|
|
||||||
|
|
||||||
def common_names
|
def common_names
|
||||||
fetch_attr('common_names')
|
fetch_attr('common_names')
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
%span.help-block Living more than two years
|
%span.help-block Living more than two years
|
||||||
|
|
||||||
%h2 OpenFarm Data
|
%h2 OpenFarm Data
|
||||||
|
= f.text_area :description, label: 'Description'
|
||||||
= f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0
|
= f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0
|
||||||
= f.number_field :spread, label: 'Spread (cm)', min: 0
|
= f.number_field :spread, label: 'Spread (cm)', min: 0
|
||||||
= f.number_field :height, label: 'Height (cm)', min: 0
|
= f.number_field :height, label: 'Height (cm)', min: 0
|
||||||
|
|||||||
@@ -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