Seeding data with Apartment gem for new schemas?

How can I seed a new tenant in a multi-tenant app that uses the Apartment gem for scoping?

I added the following to seeds.rb but it doesn’t seem to work with apartment:

tenants = Tenant.create([
{
  name: 'User1',
  domain: 'user1'
},
{
  name: 'User2',
  domain: 'user2'
}
])

Even is the database is blank, seeds.rb tries to create the schema twice and fails with this error when I do rake db:seed:

Apartment::TenantExists: The schema user1 already exists.

Any help would be greatly appreciated!


Source: ruby

Leave a Reply