Merge remote-tracking branch 'fsmanuel/master' into master.
Updated migration date to today. Conflicts: db/schema.rb
This commit is contained in:
commit
74bfc85562
21 changed files with 269 additions and 88 deletions
17
db/migrate/20130718183100_create_settings.rb
Normal file
17
db/migrate/20130718183100_create_settings.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class CreateSettings < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :settings do |t|
|
||||
t.string :var, null: false
|
||||
t.text :value, null: true
|
||||
t.integer :thing_id, null: true
|
||||
t.string :thing_type, limit: 30, null: true
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :settings, [ :thing_type, :thing_id, :var ], unique: true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :settings
|
||||
end
|
||||
end
|
||||
34
db/migrate/20130718183101_migrate_user_settings.rb
Normal file
34
db/migrate/20130718183101_migrate_user_settings.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class MigrateUserSettings < ActiveRecord::Migration
|
||||
def up
|
||||
old_settings = ConfigurableSetting.all
|
||||
|
||||
old_settings.each do |old_setting|
|
||||
# get target (user)
|
||||
type = old_setting.configurable_type
|
||||
id = old_setting.configurable_id
|
||||
user = type.constantize.find(id)
|
||||
|
||||
# get the data (settings)
|
||||
name = old_setting.name
|
||||
namespace = name.split('.')[0]
|
||||
key = name.split('.')[1].underscore # Camelcase to underscore
|
||||
|
||||
# prepare value
|
||||
value = YAML.load(old_setting.value)
|
||||
value = value.nil? ? false : value
|
||||
|
||||
# set the settings_attributes (thanks to settings.merge! we can set them one by one)
|
||||
user.settings_attributes = {
|
||||
"#{namespace}" => {
|
||||
"#{key}" => value
|
||||
}
|
||||
}
|
||||
|
||||
# save the user to apply after_save callback
|
||||
user.save
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
||||
13
db/schema.rb
13
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130624085246) do
|
||||
ActiveRecord::Schema.define(:version => 20130718183101) do
|
||||
|
||||
create_table "article_categories", :force => true do |t|
|
||||
t.string "name", :default => "", :null => false
|
||||
|
|
@ -268,6 +268,17 @@ ActiveRecord::Schema.define(:version => 20130624085246) do
|
|||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "settings", :force => true do |t|
|
||||
t.string "var", :null => false
|
||||
t.text "value"
|
||||
t.integer "thing_id"
|
||||
t.string "thing_type", :limit => 30
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "settings", ["thing_type", "thing_id", "var"], :name => "index_settings_on_thing_type_and_thing_id_and_var", :unique => true
|
||||
|
||||
create_table "stock_changes", :force => true do |t|
|
||||
t.integer "delivery_id"
|
||||
t.integer "order_id"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue