Fixed #2333 - Object country already exists
by adding the corresponding country attribute to the existing country column
This commit is contained in:
parent
f711e1019e
commit
cd65dcdb40
3 changed files with 108 additions and 0 deletions
50
db/migrate/20181108123847_add_country_attribute_to_users.rb
Normal file
50
db/migrate/20181108123847_add_country_attribute_to_users.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Fixes issue #2333 - Object country already exists
|
||||
# The country column already exists in the database, but there is no corresponding ObjectManager::Attribute for it
|
||||
# This migration adds the User.country attribute if and only if it does not exist already
|
||||
class AddCountryAttributeToUsers < ActiveRecord::Migration[5.1]
|
||||
def up
|
||||
# return if it's a new setup
|
||||
return if !Setting.find_by(name: 'system_init_done')
|
||||
|
||||
# return if the country attribute already exists
|
||||
current_country_attribute = ObjectManager::Attribute.find_by(object_lookup_id: ObjectLookup.by_name('User'), name: 'country')
|
||||
return if current_country_attribute.present?
|
||||
|
||||
ObjectManager::Attribute.add(
|
||||
force: true,
|
||||
object: 'User',
|
||||
name: 'country',
|
||||
display: 'Country',
|
||||
data_type: 'input',
|
||||
data_option: {
|
||||
type: 'text',
|
||||
maxlength: 100,
|
||||
null: true,
|
||||
item_class: 'formGroup--halfSize',
|
||||
},
|
||||
editable: true,
|
||||
active: false,
|
||||
screens: {
|
||||
signup: {},
|
||||
invite_agent: {},
|
||||
invite_customer: {},
|
||||
edit: {
|
||||
'-all-' => {
|
||||
null: true,
|
||||
},
|
||||
},
|
||||
view: {
|
||||
'-all-' => {
|
||||
shown: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
to_create: false,
|
||||
to_migrate: false,
|
||||
to_delete: false,
|
||||
position: 1325,
|
||||
created_by_id: 1,
|
||||
updated_by_id: 1,
|
||||
)
|
||||
end
|
||||
end
|
|
@ -964,6 +964,41 @@ ObjectManager::Attribute.add(
|
|||
position: 1300,
|
||||
)
|
||||
|
||||
ObjectManager::Attribute.add(
|
||||
force: true,
|
||||
object: 'User',
|
||||
name: 'country',
|
||||
display: 'Country',
|
||||
data_type: 'input',
|
||||
data_option: {
|
||||
type: 'text',
|
||||
maxlength: 100,
|
||||
null: true,
|
||||
item_class: 'formGroup--halfSize',
|
||||
},
|
||||
editable: true,
|
||||
active: false,
|
||||
screens: {
|
||||
signup: {},
|
||||
invite_agent: {},
|
||||
invite_customer: {},
|
||||
edit: {
|
||||
'-all-' => {
|
||||
null: true,
|
||||
},
|
||||
},
|
||||
view: {
|
||||
'-all-' => {
|
||||
shown: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
to_create: false,
|
||||
to_migrate: false,
|
||||
to_delete: false,
|
||||
position: 1325,
|
||||
)
|
||||
|
||||
ObjectManager::Attribute.add(
|
||||
force: true,
|
||||
object: 'User',
|
||||
|
|
23
spec/db/migrate/issue_2333_object_country_already_exists.rb
Normal file
23
spec/db/migrate/issue_2333_object_country_already_exists.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AddCountryAttributeToUsers, type: :db_migration do
|
||||
|
||||
context 'AddCountryAttributeToUsers migration' do
|
||||
|
||||
def country_attribute
|
||||
ObjectManager::Attribute.find_by(object_lookup_id: ObjectLookup.by_name('User'), name: 'country')
|
||||
end
|
||||
|
||||
it 'preserves the existing country attribute' do
|
||||
expect { migrate }
|
||||
.not_to(change { country_attribute.present? })
|
||||
end
|
||||
|
||||
it 'adds the country attribute when it is not present' do
|
||||
country_attribute.delete
|
||||
expect { migrate }
|
||||
.to change { country_attribute.present? }
|
||||
.from( false ).to( true )
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue