Rails schema_format :sql should behave like schema_format :ruby #715

Closed
lighthouse-import opened this Issue May 16, 2011 · 33 comments

Comments

Projects
None yet
10 participants

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/5412
Created by Nick Gauthier - 2011-02-18 10:10:47 UTC

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

Imported from Lighthouse.
Comment by Dave Hoover - 2010-09-15 19:58:07 UTC

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.

Imported from Lighthouse.
Comment by Nick Gauthier - 2010-09-15 20:02:30 UTC

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

Imported from Lighthouse.
Comment by Dave Hoover - 2010-09-15 20:15:12 UTC

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. :)

Imported from Lighthouse.
Comment by Gaius Centus Novus - 2010-10-29 18:13:47 UTC

See also #5889, which backports these changes to Rails 2.3

Imported from Lighthouse.
Comment by Xavier Shay - 2010-11-01 00:50:27 UTC

Good. I support this patch.

Imported from Lighthouse.
Comment by Jeff Kreeftmeijer - 2010-11-08 08:52:11 UTC

Automatic cleanup of spam.

Imported from Lighthouse.
Comment by Gabriel Sobrinho - 2011-01-24 20:02:54 UTC

Waiting for this patch too.

This patch apply for rails 3?

Imported from Lighthouse.
Comment by Gravis - 2011-02-14 18:51:12 UTC

+1 for this patch/feature
thanks

Imported from Lighthouse.
Comment by Brad Langhorst - 2011-02-16 17:59:42 UTC

+1

Imported from Lighthouse.
Comment by William Denniss - 2011-02-18 05:41:24 UTC

+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 )

Imported from Lighthouse.
Comment by Tyler Hunt - 2011-02-21 17:38:03 UTC

+1

Imported from Lighthouse.
Comment by Ed Schmalzle - 2011-02-25 17:25:07 UTC

+1

Imported from Lighthouse.
Comment by Chris Cahoon - 2011-02-25 17:28:45 UTC

+1

Imported from Lighthouse.
Comment by George Anderson - 2011-02-25 18:28:25 UTC

+1

Imported from Lighthouse.
Comment by Flip Sasser - 2011-02-28 14:48:08 UTC

+1

Imported from Lighthouse.
Comment by Andreas Korth - 2011-03-09 22:32:20 UTC

+1 fwiw

Imported from Lighthouse.
Comment by Brian Morearty - 2011-03-30 22:26:50 UTC

+1 woo hoo

Imported from Lighthouse.
Comment by Brad Langhorst - 2011-04-06 15:33:26 UTC

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.

Imported from Lighthouse.
Comment by Paul O'Keeffe - 2011-04-14 06:54:08 UTC

+1

Imported from Lighthouse.
Comment by oleg dashevskii - 2011-04-14 10:43:10 UTC

+1

Imported from Lighthouse.
Comment by Greg Hazel - 2011-04-26 10:15:04 UTC

+1

Attachments saved to Gist: http://gist.github.com/971699

I believe this is still an open issue. Please re-open!

Contributor

gjastrab commented May 23, 2011

+1

Contributor

bryanl commented May 23, 2011

+1 to re-opening it.

Contributor

elight commented May 23, 2011

+1

panggi commented May 24, 2011

+1

Contributor

atambo commented Jun 9, 2011

+1

Contributor

be9 commented Sep 8, 2011

+1

Contributor

atambo commented Sep 8, 2011

I submitted a pull request with the above diff's here:

#2948

Awesome thanks. I'd been meaning to do that. Figured it would have a better chance.

Contributor

codyrobbins commented Oct 1, 2011

+∞

atambo added a commit to atambo/rails that referenced this issue Nov 4, 2011

schema_format :sql should behave like schema_format :ruby
This commit adds a db:structure:load task that is run instead of
db:schema:load when schema_format is set to :sql. This patch also removes
the prefixing of the structure.sql files to mimic the use of a single
schema.rb file. The patch originates from github issue #715.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment