Class: AddMagicLocales

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/magic_locales/templates/magic_logales_migration.rb

Instance Method Summary collapse

Instance Method Details

#downObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/magic_locales/templates/magic_logales_migration.rb', line 39

def down
  
  ## Addresses
  remove_index  :mgclang_locales, :iso_code
  drop_table    :mgclang_locales
  MagicAddresses::Address.drop_translation_table!
  
  
  remove_index  :mgclang_languages, :locale_id
  remove_index  :mgclang_languages, [:owner_type, :owner_id]
  drop_table    :mgclang_languages
  
end

#upObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/magic_locales/templates/magic_logales_migration.rb', line 3

def up
  
  #
  ## Locales
  create_table :mgclang_locales do |t|
    # t.string      :name
    t.string      :natural_name
    t.string      :iso_code
    t.string      :locale_state,    default: "inactive"
    t.timestamps
  end
  
  add_index :mgclang_locales, :iso_code, unique: true
  
  MagicLocales::Locale.create_translation_table! :name => :string
  
  
  #
  ## (spoken) Languages
  create_table :mgclang_languages do |t|
    t.string        :level
    t.references    :owner,      polymorphic: true
    t.references    :locale
    t.timestamps
  end
  
  add_index :mgclang_languages, [:owner_type, :owner_id]
  add_index :mgclang_languages, :locale_id
  
  
  #
  ## seed default Locales
  load "#{ Rails.root }/db/seeds/locales.rb"
  
  
end