Forum: Ruby on Rails migrations still

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-15 08:12
(Received via mailing list)
I think I am pissing into the wind to make migrations work at this
point.

Looking at
http://wiki.rubyonrails.org/rails/pages/Understand...

it appears that the problem that I am having is that postgresql can't do
the drop_table part because of the foreign_key keys (constraints) which
requires 'cascade' as an option to drop some of the tables that have
other tables which include a column from the table I am attempting to
drop which would leave things in a mess.

I thought I would ask anyway...

Am I supposed to have each table migration in a separate file or should
they all be in the same file?

  db/migration/0001_add_a_new_table
  def self_up
    create_table 'foo', :force => true do |t|
      t.column ...
    end
    create_table 'foo2', :force => true do |t|
      t.column ...
    end
  end
  def self_down
     drop_table :foo
     drop_table :foo2
  end

or multiple files?

 db/migration/0001_add_foo
  def self_up
    create_table 'foo', :force => true do |t|
      t.column ...
    end
  end
  def self_down
     drop_table :foo
  end

 db/migration/0002_add_foo2
  def self_up
    create_table 'foo2', :force => true do |t|
      t.column ...
    end
  end
  def self_down
     drop_table :foo2
  end

Craig
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Mikkel Bruun (Guest)
on 2006-02-15 09:31
(Received via mailing list)
>
>Am I supposed to have each table migration in a separate file or should
>they all be in the same file?

There are no *rules* for this...but every logical change should occur in
one migration.

A migration can involve modifications to several tables, creating,
dropping whatever...

A migration should be considere atomic...

Foreign key constraints giving you problems?? Change the order of your
drops...or drop the constraints (in the database)


Mikkel Bruun

www.strongside.dk    - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-15 10:25
(Received via mailing list)
On Wed, 2006-02-15 at 08:29 +0000, Mikkel Bruun wrote:
> A migration should be considere atomic...
>
> Foreign key constraints giving you problems?? Change the order of your
> drops...or drop the constraints (in the database)
>
----
duh...of course - that may be difficult (the order) as there are a few
foreign keys already and I'm somewhat loathe to drop the foreign keys as
it's entirely possible that this isn't just for rails.

I'll have to work on that but at least I know now that keeping the
various tables in one migration file does make sense - though there
isn't any significant information in 'rake migration' --trace or
--verbose options and it took me quite some time to figure out that this
was a cascade thingy.

Thanks

Craig
This topic is locked and can not be replied to.