damln/localtower

Crash After Deleted Table

Closed this issue · 1 comments

I encountered a bug in localtower.

Steps to crash:

  1. I created two separate models before using local tower (users and accounts).
  2. I used Localtower to create relationship (which added a table “account_users”)
  3. I realized that this isn’t what I wanted to do, so I tried dropping the tower in localtower.
  4. The drop didn’t work so well it seems… So I tried to do a db:rollback
  5. After I did db:rollback and deleted the migration that created the table account_users, my rails app works perfectly. However, if I go to localhost:3000/localtower/ I get an error message.

Error Message:

screen shot 2017-03-09 at 9 31 50 pm

Not sure of the cause, but I have a few ideas. One idea is that it might be related to loading the schema from a cache?

screen_shot_2017-03-09_at_9_37_35_pm

EDIT:: After messing around and doing some debugging around my app, I found the problem.

The Problem:
I still had a "models/account_user.rb" file after dropping the account_user table
After I deleted that file, it started to work perfectly again.

Suggestions:

I think you should change the way the schema-load algorithm works. Currently, localtower seems to depend itself on the user following convention in his models. This could be a huge problem for new users who haven't learned these conventions. What if, for example, a user creates a helper ruby file and saves it in the models folder?

Possible Solutions:

  • Make the schema load be dependent on searching through the text of "db/schema.rb", then afterwards, search for appropriate models, etc.
  • Load models and schema separately to be able to show a warning message to user indicating that there are models that exist without a corresponding db table.
  • After dropping a table, perhaps local tower can automatically move the file out of "models" folder and into a different folder (ex: "DeprecatedModels" folder) [this way if a user accidentally drops the table, he won't lose any code/methods written into the model.]
damln commented

Thanks for the feedback.

The schema loading is correct this way. We should enforce conventions and you don't have to have a helper in your app/models folder.

Let me know if any trouble.