Crash After Deleted Table
Closed this issue · 1 comments
I encountered a bug in localtower.
Steps to crash:
- I created two separate models before using local tower (users and accounts).
- I used Localtower to create relationship (which added a table “account_users”)
- I realized that this isn’t what I wanted to do, so I tried dropping the tower in localtower.
- The drop didn’t work so well it seems… So I tried to do a db:rollback
- 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:
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?
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.]
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.