Open rockrep opened 11 years ago
Geez, can I admit I didn't know about Posgresql table inheritance? Luckily, it looks like a straightforward addition to support it in the dependency ordering. Most principled way to support it would be, i think:
AbstractAdapter#parent_tables(table)
that by default returns an empty arraypg_inherits
catalog as per http://www.postgresql.org/docs/9.0/interactive/catalog-pg-inherits.html and http://dba.stackexchange.com/questions/3115/postgresql-displaying-inheritance-relationship and returns an array of table namesschema_dumper.rb
right after it sets dependencies = @inline_fks[table]...
add a line dependencies += @conection.parent_tables(table)
and unless there's something I'm not thinking of, that should take care of it.
Let me know if I can help
Would you be able to take a crack at the above (or some variant of it)? Along with corresponding specs of course. Unfortunately I don't have the time to dive into it right now.
Could also be cool to add an option `create_table "all2012_facts", :inherits => 'facts'``
Thanks Ronen. I have to admit I didn't know about Postgresql table inheritance until recently either. I'll give the above suggestions a try and see if I can provide a patch.
Ronen, I submitted a pull request (#79) to fix this issue per your suggestions. I also had to fix an issue with :drop_table to pass a :cascade option on to Postgresql in order to get 'rake db:schema:load' to drop the inherited table successfully. Please let me know your feedback.
I didn't have time yet to add an :inherits option for :create_table, but I think it's needed to ensure a database loaded with db:schema:load is properly configured. As it stands now, I'm limited to using db:migrate. I'd need to also specify the check constraints as well, otherwise the create table call will fail. SchemaDumper would also have to support writing out the check constraints to schema.rb. I could use some suggestions for how you think it's best to approach this. I'm also partly thinking that this support should belong in activerecord itself, but I'd like to hear what your take is on that.
see Gist
I have a partitioned Postgres table that has an alphabetical ordering before the table it inherits. The schema_dumper orders this table prior to it's parent table in schema.rb which prevents rake db:test:prepare from successfully completing due to a "Relation 'facts_id_seq' does not exist" error.
Looks like the tsort() methods need to be enhanced to handle this type of dependency. Let me know if I can help.
using activerecord 3.2.8 and schema_plus 0.4.1