Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate data when seed an excluded model #188

Closed
thiagogsr opened this issue Dec 17, 2014 · 5 comments
Closed

Duplicate data when seed an excluded model #188

thiagogsr opened this issue Dec 17, 2014 · 5 comments

Comments

@thiagogsr
Copy link

Hi guys

When I try run a seed to create data to an excluded model, it is created N times in public schema, where N is equals to tenants count.

Anyone has suggestions?

I tried run with bin/rake apartment:seed, but it created N-1 times in public schema. With bin/rake db:seed it created N times in public schema.

@thiagogsr
Copy link
Author

I already solve using if Apartment::Tenant.current_tenant == 'public' conditional, but is it the better way?

@bradrobertson
Copy link
Contributor

Seeds are basically your responsibility to maintain data integrity, there's no better way than what you're doing. We essentially do the same thing to make sure seeds are idempotent

@thiagogsr
Copy link
Author

Let me show an example for sure that you understood

There are two tentants + public. When I create a seed with these lines:

Foo.create(name: 'bar')

Foo.create(name: 'bar2')

Foo.create(name: 'bar3')

and For is an excluded model, the seed is creating 9 records in "foos" table, 3 for each create, understand? Therefore I written this conditional :)

@bradrobertson
Copy link
Contributor

That's exactly what I would expect. Since Foo is excluded, it's all working on the same (public) schema. If you run a seed, it will run it for every tenant plus public (in your case 3 times). Therefore, with your setup, I'd expect 9 entries in the Foo table. So you conditional makes sense.

@thiagogsr
Copy link
Author

Nice :)

gmhawash pushed a commit to downhome/apartment that referenced this issue Jul 19, 2022
**Implemented enhancements:**

- Increase errors visibility by showing more information on the underlying error rather than a generic error 'Apartment::TenantNotFound' (influitive#176)
- Resolved influitive#177 - Added rails 7 support (influitive#178)

**Fixed bugs:**

- Fixing tenant_presence_check config in the README (influitive#180)
- Resolved influitive#161 and influitive#81 - Fixed sequence name (influitive#187)

**Closed issues:**

- Resolved influitive#151 - removed reloader and console overwrite of reload method (influitive#174)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants