UGUA | Weblog met thema's rond Beeldende Kunst, Design, Research & Developement, Marketing en meer.

Rails Migrations


Pragmatic SDP in modelling webapps


Published: 15-02-2008 Modified: 15-02-2008
post setup:

1. SDP in Rails  

2. Migrations 

3. handelingen die daarbij worden verrciht 

4. praktisch modelleren met de db

create, add, delete, modify, change the name, change the order of columns


Example of a simple migration:
  class AddSsl < ActiveRecord::Migration
    def self.up
      add_column :accounts, :ssl_enabled, :boolean, :default => 1
    end

    def self.down
      remove_column :accounts, :ssl_enabled
    end
  end
Example of a more complex migration that also needs to initialize data:
  class AddSystemSettings < ActiveRecord::Migration
    def self.up
      create_table :system_settings do |t|
        t.string  :name
        t.string  :label
        t.text  :value
        t.string  :type
        t.integer  :position
      end

      SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
    end

    def self.down
      drop_table :system_settings
    end
  end
See http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations

Rails Migrations

Relevante links:
  1. http://rubyonrails.org
  2. http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations



Digg! [Terug]



top | print | mail

Weblog met thema's rond Beeldende Kunst, Design, Research & Developement, Marketing en meer.

© UGUA 2007-2009, Some rights reserved. CC license.