Skip to content

Commit

Permalink
Added uniqueness constraint to pfts table.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsrohde committed Jan 6, 2015
1 parent b70da07 commit 29b1ee5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions db/migrate/20141208165401_add_cultivars_pfts.rb
@@ -1,3 +1,5 @@
# Adds cultivars_pfts table, adds constraints and comments on it and on
# pfts_species, and adds uniqueness constraints to pfts table.
class AddCultivarsPfts < ActiveRecord::Migration

def self.up
Expand Down Expand Up @@ -70,6 +72,16 @@ def self.up
COMMENT ON CONSTRAINT species_exists ON pfts_species IS 'Ensure the referred-to species exists, block its deletion if it is used in a pft, and update the reference if the species id number changes.';
COMMENT ON CONSTRAINT no_conflicting_member ON pfts_species IS 'Ensure the pft_id does not refer to a pft having one or more cultivars as members; pfts referred to by this table con only contain other species.';
-- Finally, declare (name, modeltype_id) to be a key for pfts:
ALTER TABLE pfts
ALTER COLUMN name SET NOT NULL,
ADD CONSTRAINT unique_names_per_modeltype UNIQUE(name, modeltype_id);
COMMENT ON COLUMN pfts.name IS 'pft names are unique within a given model type.';
}

end
Expand All @@ -86,6 +98,14 @@ def self.down

execute %{
COMMENT ON COLUMN pfts.name IS 'unique identifier used by PEcAn.';
ALTER TABLE pfts
ALTER COLUMN name DROP NOT NULL,
DROP CONSTRAINT unique_names_per_modeltype;
ALTER TABLE pfts_species
DROP CONSTRAINT no_conflicting_member,
DROP CONSTRAINT species_exists,
Expand Down

0 comments on commit 29b1ee5

Please sign in to comment.