Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[Patch] Rails schema_format :sql should behave like schema_format :ruby

#5412

When ActiveRecord::Base.schema_format is set to :sql it should mimic the behavior of :ruby (db/schema.rb).

I've created a patch that maintains all the existing rake targets (like db:reset, db:migrate, db:setup, etc.) and toggles between the tasks appropriately.

I also added a db:structure:load task so that it could be toggled with db:schema:load.

I've attached the patch. I tried to keep with the conventions found in the existing file.

Note that there are a few other tickets similar to this one. However, the only ticket of those with a patch creates extra and differently named rails tasks, which does not accomplish the goal I attained here. The other tickets are merely feature requests.

-Nick Gauthier

Reported by Nick Gauthier · August 19th, 2010 @ 07:44 PM

State: new
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Nick Gauthier
    Nick Gauthier
    • Title changed from Rails schema_format :sql should behave like schema_format :ruby to [Patch] Rails schema_format :sql should behave like schema_format :ruby

    August 19th, 2010 @ 08:11 PM

  2. Dave Hoover
    Dave Hoover

    This seems like exactly what I need (since we switched to schema_format = :sql) but I'm wondering why you switched to structure.sql from {env}_structure.sql.

    September 15th, 2010 @ 08:58 PM

  3. Nick Gauthier
    Nick Gauthier

    Because if I migrate the dev db, then run the tests, if I left it with env_structure if would do this:

    1) Run db/migrate
    => updated dev_structure.sql 2) Run tests
    => load from test_structure.sql (FILE MISSING)

    But if you just use structure.sql (like schema.rb), then they can use the same structure file.

    The main reason can be summarize to: I want to mimic schema dumping and loading as closely as possible.

    -Nick Gauthier

    September 15th, 2010 @ 09:02 PM

  4. Dave Hoover
    Dave Hoover

    Thanks Nick.

    And BTW, great job on your talk at Windy City Rails. I couldn't be there, but I heard it was one of the better talks of the day. :)

    September 15th, 2010 @ 09:15 PM

  5. Gaius Centus Novus
  6. Xavier Shay
    Xavier Shay

    Good. I support this patch.

    November 1st, 2010 @ 12:50 AM

  7. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:52 AM

  8. Gabriel Sobrinho
    Gabriel Sobrinho

    Waiting for this patch too.

    This patch apply for rails 3?

    January 24th, 2011 @ 08:02 PM

  9. Gravis
    Gravis

    +1 for this patch/feature thanks

    February 14th, 2011 @ 06:51 PM

  10. Brad Langhorst
  11. William Denniss
    William Denniss

    +1 I would really like to see the sql option become a first class citizen, especially since it is presented that way in the docs ( http://guides.rubyonrails.org/migrations.html#types-of-schema-dumps )

    February 18th, 2011 @ 05:41 AM

  12. Tyler Hunt
  13. Ed Schmalzle
  14. Chris Cahoon
  15. George Anderson
  16. Flip Sasser
  17. Andreas Korth
  18. Brian Morearty
  19. Brad Langhorst
    Brad Langhorst

    updated the patch so that it uses the logic in test:clone_structure for db:structure:load instead of executing the lines in the structure file. test:clone_structure now uses db:structure:load just like test:clone does to db:schema:load

    fixed things so that setup loads the environment before trying to use it where necessary (db:reset and db:setup)

    added respect for the PGUSER environment variable, eliminating the -U from dump and load statements (needed for trust and ident authentication)

    patch is diffed against rails 2.3.11.

    April 6th, 2011 @ 04:33 PM

  20. Paul O'Keeffe
  21. oleg dashevskii
  22. Greg Hazel
  23. Mike Bohlander