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

Views should follow tables in schema.rb #14

Open
scarroll32 opened this issue Apr 24, 2016 · 3 comments
Open

Views should follow tables in schema.rb #14

scarroll32 opened this issue Apr 24, 2016 · 3 comments

Comments

@scarroll32
Copy link

This is a great gem, I use it all the time.

When schema.rb is created, the SQL view is inserted in alpha order. This means that if there is a later table in the schema.rb file which the view depends on, rake db:reset will fail as the dependent object is not created when the create_view is called.

The workaround is to manually edit the schema.rb file after any migrations are run, and move the views down.

Any suggestions on how to automate this? It could be further complicated if views depend on views, but if all the views we added to schema.rb after all the tables, it would solve 90% of the problems.

@ronen
Copy link
Member

ronen commented Apr 24, 2016

Thanks for the note.

If that's what's happening, there's a bug somewhere -- the schema_plus dumper does a topological sort to respect dependencies such as this; alphabetical order is secondary to the dependencies. Could you give a specific failing example?

TL; DR: This gem registers the dependencies /schema_plus/views/middleware.rb#L14 and schema_plus_core does the topological sort /schema_plus/core/schema_dump.rb#L32

@scarroll32
Copy link
Author

It's happening consistently, and doesn't seem to matter which underlying tables the view is based on. I will try to work out why.

    schema_monkey (2.1.3)
      activerecord (~> 4.2)
      its-it
      modware (~> 0.1)
    schema_plus_core (1.0.0)
      activerecord (~> 4.2)
      schema_monkey (~> 2.1)
    schema_plus_views (0.3.1)
      activerecord (~> 4.2)
      schema_plus_core (~> 1.0)

@ronen
Copy link
Member

ronen commented Apr 27, 2016

I will try to work out why.

Thanks! And/or if you can post, gist, or email me an example schema that fails, i can look into it.

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