Giter Club home page Giter Club logo

Comments (12)

Makimeishu avatar Makimeishu commented on May 27, 2024

If I run "rake db:migrate", it will successfully migrate to public schema. But fail when try: "rake apartment:migrate"

from apartment.

climbingblake avatar climbingblake commented on May 27, 2024

did you find an answer for this?
I am having a similar problem while running rake apartment:migrate
rake aborted!
Don't know how to build task 'apartment:migrate'

osx, apartment 0.21.1, .rvm/gems/ruby-1.9.3-p392@npdirector

It seems odd that it cant "find" the apartment rake task

from apartment.

bradrobertson avatar bradrobertson commented on May 27, 2024

are you using bundle exec rake apartment:migrate ??

Assuming you've added apartment to your Gemfile that is.

from apartment.

climbingblake avatar climbingblake commented on May 27, 2024

thanks brad, and yes. The gem seems to work as normal, except for running new migrations against the other databases.

from apartment.

bradrobertson avatar bradrobertson commented on May 27, 2024

can you expand on that a bit? You're saying you no longer get the don't know how to build task error?

In order for migrations to run on new databases, the new dbs need to be found when Apartment.database_names is called. You can set this in your config like so:

config.database_names = lambda{ Customer.pluck(:database_name) }

That's of course a made up example, but the gist of it is passing it a lambda that can be called dynamically to query for all existing pg schemas.

Each tenant (ie database, or postgresql schema) maintains its own migration state, so as long as Apartment knows about that db, the migrations will run using bundle exec rake apartment:migrate

from apartment.

climbingblake avatar climbingblake commented on May 27, 2024

sorry for the lack of info, and thank you again.

$ bundle exec rake apartment:migrate
rake aborted!
Don't know how to build task 'apartment:migrate'

Apartment.configure do |config|
    config.excluded_models = ["Account"]
    config.database_names = lambda{ Account.pluck(:subdomain) }
    config.persistent_schemas = ['public']
    config.persistent_schemas = ['hstore']
    config.use_postgres_schemas = true
end

Thanks again.

from apartment.

bradrobertson avatar bradrobertson commented on May 27, 2024

is it a public project that I can see the source of? As long as apartment is in your Gemfile, then the rake task should work. What version of Rake/Rubygems are you using?

from apartment.

climbingblake avatar climbingblake commented on May 27, 2024

no its not public (yet), but it was originally based around https://github.com/RailsApps/rails-stripe-membership-saas. And after getting rspec to fully run on Rails4, started to implement Apartment Gem to separate accounts (including users table, allowing completely separate users login)

again, rspec fully works creating and dropping schemas, as well as in development using
Apartment::Database.create(account.subdomain)
which to me is odd that *all other parts of Apartment seems to be working with my setup, other than not finding a simple rake task (which I confirmed is within my gem)

Rails 4.0.0.rc2
ruby 1.9.3p392

#database.yml
development:
  adapter: postgresql
  schema_search_path: "public,hstore"
  database: APPNAME
  host: localhost
  port: 5432
  username: MY_USERNAME

from apartment.

bradrobertson avatar bradrobertson commented on May 27, 2024

ah ok, haven't actually tried Rails 4 yet, but other user's haven't reported any problems.

When I have a chance I'll set up a new Rails 4 project and see if I have the same problem.

from apartment.

climbingblake avatar climbingblake commented on May 27, 2024

Thank you. Im sure its something small, expecially since everything else is working fine.
We're still evaluating to see if this is the solution for this project, but it is very promising (as it is really nicely done).

Just now trying to get it to create the Devise use in the newly created account schema on Account :create.

thanks again for an awesome Gem

from apartment.

bradrobertson avatar bradrobertson commented on May 27, 2024

ya we had a similar issue. We basically use an after_create that switches into the new schema to create the user.

You can't do any of the automated creation stuff if you're creating tenanted models with the public ones unfortunately.

So you can set, say, an instance variable of a new (unsaved) user, then in after_create you can switch to the schema and save the user.

from apartment.

thanikkal avatar thanikkal commented on May 27, 2024

Ran into this issue after I had added few rake tasks with a file named apartment.rake with the namespace apartment. Looks like rails/ruby doesnt consider multiple rake files/namepaces with the same name?

from apartment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.