鉴于我有以下迁移:
Sequel.migration do
up do
alter_table :users do
add_column :is_admin, :default => false
end
# Sequel runs a DESCRIBE table statement, when the model is loaded.
# At this point, it does not know that users have a is_admin flag.
# So it fails.
@user = User.find(:email => "admin@fancy-startup.example")
@user.is_admin = true
@user.save!
end
end
然后 sequel 不会自动重新加载表结构(见内联注释)。
我正在使用这个丑陋的黑客来解决它:
# deep magic begins here. If you remove a single line, it will
# break the migration.
User.db.schema("users", :reload => true)
User.instance_variable_set(:@db_schema, nil)
User.columns
User.new.respond_to?(:is_admin=)
sleep 1
有没有更好的办法?