Skip to content

Commit

Permalink
Fixing bugs in database migration files
Browse files Browse the repository at this point in the history
Signed-off-by: Ramón Martínez Olvera <martinezo@udevelopper-viii.(none)>
  • Loading branch information
Deployer Unidad de Computo INB authored and Ramón Martínez Olvera committed Feb 22, 2012
1 parent 0db18fd commit a58e6e1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions db/migrate/20100823153816_upgrade_userstatus.rb
@@ -1,3 +1,4 @@
# encoding: utf-8
class UpgradeUserstatus < ActiveRecord::Migration
def self.up
{ 1 => 'Baja - por defunción', 2 => 'Activo', 3 => 'Baja - por renuncia',
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20101118190700_update_versions.rb
@@ -1,5 +1,13 @@
class UpdateVersions < ActiveRecord::Migration
def self.up
unless table_exists? :versions

create_table :versions do |t|
t.integer :versioned_id
t.string :versioned_type, :changes, :number
t.timestamp :created_at
end
end
remove_column :versions, :versioned_id
remove_column :versions, :versioned_type
remove_column :versions, :changes
Expand Down
@@ -1,6 +1,11 @@
class RenameUserStimulusesToUserStimuli < ActiveRecord::Migration

def self.up
rename_table :user_stimuluses, :user_stimuli
if table_exists? :user_stimuluses
rename_table :user_stimuluses, :user_stimuli
elsif table_exists? :user_stimulus
rename_table :user_stimulus, :user_stimuli
end
end

def self.down
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20101209194041_normalize_duplicated_id_in_people.rb
@@ -0,0 +1,14 @@
class NormalizeDuplicatedIdInPeople < ActiveRecord::Migration

def self.up
last_id = Person.unscoped.order("id DESC").first.id
Person.all.each do |record|
last_id += 1
execute "UPDATE people SET id = #{last_id} WHERE user_id = #{record.user_id}"
end

end

def self.down
end
end
Expand Up @@ -12,6 +12,10 @@ def up
associations = Institution.associations_to_move.collect { |association| association.name }

execute "ALTER TABLE institutioncareers DROP CONSTRAINT institutioncareers_institution_id_key"
execute "ALTER TABLE prizes DROP CONSTRAINT prizes_name_key"
execute "ALTER TABLE seminaries DROP CONSTRAINT seminaries_title_key"
execute "ALTER TABLE user_languages DROP CONSTRAINT user_languages_language_id_key"


sql = "SELECT UPPER(name) as name FROM institutions as i GROUP BY UPPER(name) HAVING ( COUNT(UPPER(name)) > 1)"
Institution.find_by_sql(sql).each do |record|
Expand All @@ -28,6 +32,12 @@ def up
end
end

# execute "ALTER TABLE institutioncareers ADD CONSTRAINT institutioncareers_institution_id_key UNIQUE (career_id, institution_id)"
# execute "ALTER TABLE prizes ADD CONSTRAINT prizes_name_key UNIQUE (name, institution_id)"
# execute "ALTER TABLE seminaries ADD CONSTRAINT seminaries_title_key UNIQUE (title, year, institution_id)"
# execute "ALTER TABLE user_languages ADD CONSTRAINT user_languages_language_id_key UNIQUE (language_id, institution_id, user_id)"


end

def down
Expand Down
@@ -1,6 +1,6 @@
class RemoveTriggerUserStatusUpdateOnUsers < ActiveRecord::Migration
def up
execute "DROP TRIGGER userstatus_update ON users"
execute "DROP TRIGGER IF EXISTS userstatus_update ON users"
end

def down
Expand Down

0 comments on commit a58e6e1

Please sign in to comment.