Add a list of languages and fix a few issues with the schema. Also get
[rails.git] / db / migrate / 034_create_languages.rb
1 require 'lib/migrate'
2
3 class CreateLanguages < ActiveRecord::Migration
4   def self.up
5     create_table :languages, innodb_table do |t|
6       t.string :code, :null => false
7       t.string :english_name, :null => false
8       t.string :native_name
9     end
10
11     add_primary_key :languages, [:code]
12
13     YAML.load(File.read(RAILS_ROOT + "/config/languages.yml")).each do |k,v|
14       Language.create do |l|
15         l.code = k
16         l.english_name = v["english"]
17         l.native_name = v["native"]
18       end
19     end
20
21     add_foreign_key :users, [:locale], :languages, [:code]
22     add_foreign_key :diary_entries, [:language], :languages, [:code]    
23   end
24
25   def self.down
26     raise IrreversibleMigration.new
27   end
28 end
29