Permalink
Browse files

created the only cleaned up migration for creating taxonomy tables, r…

…emoved counter_caches; updated fixtures etc
  • Loading branch information...
1 parent e7b099e commit ea58d553dc10892b74ac7afc0a702b7cc53723e6 @khustochka committed Jan 3, 2010
@@ -3,7 +3,7 @@ class Familia < Taxon
validates_format_of :name_la, :with => /^[A-Z][a-z]+dae$/
validates_uniqueness_of :sort, :scope => :ordo_id
- belongs_to :supertaxon, :class_name => "Ordo", :foreign_key => "ordo_id", :counter_cache => true
+ belongs_to :supertaxon, :class_name => "Ordo", :foreign_key => "ordo_id"
has_many :subtaxa, :class_name => "Species", :foreign_key => "familia_id", :order => "sort"
@@ -5,7 +5,7 @@ class Species < Taxon
validates_uniqueness_of :code
validates_uniqueness_of :sort, :scope => :familia_id
- belongs_to :supertaxon, :class_name => "Familia", :foreign_key => "familia_id", :counter_cache => true
+ belongs_to :supertaxon, :class_name => "Familia", :foreign_key => "familia_id"
attr_reader :url
@@ -1,20 +0,0 @@
-class CreateOrdines < ActiveRecord::Migration
- def self.up
- create_table :ordines do |t|
- t.string :name_la, :null => false, :limit => 128
- t.string :name_en, :limit => 128
- t.string :name_ru, :null => false, :limit => 128
- t.string :name_uk, :null => false, :limit => 128
- t.text :description
- t.string :synonims, :limit => 256
- t.integer :sort, :null => false
- end
- add_index "ordines", "name_la"
- add_index "ordines", "sort"
- end
-
- def self.down
- drop_table :ordines
- end
-end
-
@@ -1,22 +0,0 @@
-class CreateFamiliae < ActiveRecord::Migration
- def self.up
- create_table :familiae do |t|
- t.string "name_la", :limit => 128, :default => "", :null => false
- t.string "name_en", :limit => 128
- t.string "name_ru", :limit => 128, :default => "", :null => false
- t.string "name_uk", :limit => 128, :default => "", :null => false
- t.text "description"
- t.string "synonims", :limit => 256
- t.integer "sort", :null => false
- t.integer "ordo_id", :null => false
- end
-
- add_index "familiae", "name_la"
- add_index "familiae", "sort"
- add_index "familiae", "ordo_id"
- end
-
- def self.down
- drop_table :familiae
- end
-end
@@ -1,31 +0,0 @@
-class CreateSpecies < ActiveRecord::Migration
- def self.up
- create_table :species do |t|
- t.string "code", :limit => 6, :null => false
- t.string "name_la", :limit => 128, :default => "", :null => false
- t.string "authority", :limit => 128, :null => false
- t.string "name_en", :limit => 128, :default => "", :null => false
- t.string "name_ru", :limit => 128, :default => "", :null => false
- t.string "name_uk", :limit => 128, :default => "", :null => false
- t.text "description"
- t.text "my_description"
- t.string "synonims", :limit => 256
- t.integer "sort", :null => false
- t.integer "familia_id", :null => false
- t.integer "image_id"
- t.string "iucn_id", :limit => 2
- t.string "iucn_status"
- t.string "iucn_name_la"
-
- end
-
- add_index "species", "name_la"
- add_index "species", "code"
- add_index "species", "sort"
- add_index "species", "familia_id"
- end
-
- def self.down
- drop_table :species
- end
-end
@@ -1,21 +0,0 @@
-class ImproveIndices < ActiveRecord::Migration
- def self.up
- remove_index "familiae", "sort"
- remove_index "familiae", "ordo_id"
- add_index(:familiae, [:ordo_id, :sort])
-
- remove_index "species", "sort"
- remove_index "species", "familia_id"
- add_index(:species, [:familia_id, :sort])
- end
-
- def self.down
- remove_index(:familiae, [:ordo_id, :sort])
- add_index "familiae", "sort"
- add_index "familiae", "ordo_id"
-
- remove_index(:species, [:familia_id, :sort])
- add_index "species", "sort"
- add_index "species", "familia_id"
- end
-end
@@ -1,15 +0,0 @@
-class AddCounterCache < ActiveRecord::Migration
-
- def self.up
- add_column :ordines, :familiae_count, :integer, :null => false, :default => 0
- add_column :familiae, :species_count, :integer, :null => false, :default => 0
-
- execute "UPDATE ordines SET familiae_count = (SELECT COUNT(id) FROM familiae WHERE ordo_id = ordines.id)"
- execute "UPDATE familiae SET species_count = (SELECT COUNT(id) FROM species WHERE familia_id = familiae.id)"
- end
-
- def self.down
- remove_column :ordines, :familiae_count
- remove_column :familiae, :species_count
- end
-end
@@ -0,0 +1,59 @@
+class CreateTaxonomyClean < ActiveRecord::Migration
+ def self.up
+ create_table :ordines do |t|
+ t.string :name_la, :null => false, :limit => 128
+ t.string :name_en, :limit => 128
+ t.string :name_ru, :null => false, :limit => 128
+ t.string :name_uk, :null => false, :limit => 128
+ t.text :description
+ t.string :synonims, :limit => 256
+ t.integer :sort, :null => false
+ end
+
+ add_index :ordines, :name_la
+ add_index :ordines, :sort
+
+ create_table :familiae do |t|
+ t.string "name_la", :limit => 128, :default => "", :null => false
+ t.string "name_en", :limit => 128
+ t.string "name_ru", :limit => 128, :default => "", :null => false
+ t.string "name_uk", :limit => 128, :default => "", :null => false
+ t.text "description"
+ t.string "synonims", :limit => 256
+ t.integer "sort", :null => false
+ t.integer "ordo_id", :null => false
+ end
+
+ add_index :familiae, :name_la
+ add_index :familiae, [:ordo_id, :sort]
+
+ create_table :species do |t|
+ t.string "code", :limit => 6, :null => false
+ t.string "name_la", :limit => 128, :default => "", :null => false
+ t.string "authority", :limit => 128, :null => false
+ t.string "name_en", :limit => 128, :default => "", :null => false
+ t.string "name_ru", :limit => 128, :default => "", :null => false
+ t.string "name_uk", :limit => 128, :default => "", :null => false
+ t.text "description"
+ t.text "my_description"
+ t.string "synonims", :limit => 256
+ t.integer "sort", :null => false
+ t.integer "familia_id", :null => false
+ t.integer "image_id"
+ t.string "iucn_id"
+ t.string "iucn_status", :limit => 2
+ t.string "iucn_name_la"
+ end
+
+ add_index :species, :name_la
+ add_index :species, :code
+ add_index :species, :iucn_status
+ add_index :species, [:familia_id, :sort]
+ end
+
+ def self.down
+ drop_table :ordines
+ drop_table :familiae
+ drop_table :species
+ end
+end
View
@@ -9,32 +9,30 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20091228103624) do
+ActiveRecord::Schema.define(:version => 20100103001528) do
create_table "familiae", :force => true do |t|
- t.string "name_la", :limit => 128, :default => "", :null => false
- t.string "name_en", :limit => 128
- t.string "name_ru", :limit => 128, :default => "", :null => false
- t.string "name_uk", :limit => 128, :default => "", :null => false
+ t.string "name_la", :limit => 128, :default => "", :null => false
+ t.string "name_en", :limit => 128
+ t.string "name_ru", :limit => 128, :default => "", :null => false
+ t.string "name_uk", :limit => 128, :default => "", :null => false
t.text "description"
- t.string "synonims", :limit => 256
- t.integer "sort", :null => false
- t.integer "ordo_id", :null => false
- t.integer "species_count", :default => 0, :null => false
+ t.string "synonims", :limit => 256
+ t.integer "sort", :null => false
+ t.integer "ordo_id", :null => false
end
add_index "familiae", ["name_la"], :name => "index_familiae_on_name_la"
add_index "familiae", ["ordo_id", "sort"], :name => "index_familiae_on_ordo_id_and_sort"
create_table "ordines", :force => true do |t|
- t.string "name_la", :limit => 128, :null => false
- t.string "name_en", :limit => 128
- t.string "name_ru", :limit => 128, :null => false
- t.string "name_uk", :limit => 128, :null => false
+ t.string "name_la", :limit => 128, :null => false
+ t.string "name_en", :limit => 128
+ t.string "name_ru", :limit => 128, :null => false
+ t.string "name_uk", :limit => 128, :null => false
t.text "description"
- t.string "synonims", :limit => 256
- t.integer "sort", :null => false
- t.integer "familiae_count", :default => 0, :null => false
+ t.string "synonims", :limit => 256
+ t.integer "sort", :null => false
end
add_index "ordines", ["name_la"], :name => "index_ordines_on_name_la"
@@ -53,13 +51,14 @@
t.integer "sort", :null => false
t.integer "familia_id", :null => false
t.integer "image_id"
- t.string "iucn_id", :limit => 2
- t.string "iucn_status"
+ t.string "iucn_id"
+ t.string "iucn_status", :limit => 2
t.string "iucn_name_la"
end
add_index "species", ["code"], :name => "index_species_on_code"
add_index "species", ["familia_id", "sort"], :name => "index_species_on_familia_id_and_sort"
+ add_index "species", ["iucn_status"], :name => "index_species_on_iucn_status"
add_index "species", ["name_la"], :name => "index_species_on_name_la"
end
Oops, something went wrong.

0 comments on commit ea58d55

Please sign in to comment.