Permalink
Browse files

Fixing bugs in database migration files

Signed-off-by: Ramón Martínez Olvera <martinezo@udevelopper-viii.(none)>
  • Loading branch information...
1 parent 0db18fd commit a58e6e108021bac738ecedeae34169b061c635f8 Deployer Unidad de Computo INB committed with Ramón Martínez Olvera Feb 22, 2012
@@ -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',
@@ -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
@@ -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
@@ -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
@@ -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|
@@ -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
@@ -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

0 comments on commit a58e6e1

Please sign in to comment.