How to define seed file for Rails Apartment

让人想犯罪 __ 提交于 2019-12-03 20:20:42
rdubya

In your seeds.rb file, wrap your code in a check for the current tenant. I don't have anywhere to test this right now, but the following code should get you close:

unless Apartment::Tenant.current == 'public'
    #Insert seed data
end

If you want to seed a tenant manually you should be able to run Apartment::Tenant.seed

To get the seeds.rb file to run when a tenant is created add:

config.seed_after_create = true

to your apartment initializer file.

For your example:

Apartment.configure do |config|

  config.excluded_models = ["Admin","Contractor", "ContractorPackage","ContractorTransaction","Country","Currency","Faq","FaqCategory","Language","Package","Page","PaymentType","Setting","TempTransaction","Testimonial","Timezone","Tutorial"]

  # use postgres schemas?
  config.use_schemas = true

  config.tenant_names = lambda{ Contractor.pluck("CONCAT('contractor_',id)") }

  config.seed_after_create = true
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!