canvas-lms/db/migrate/20130521181412_add_schema_m...

25 lines
960 B
Ruby

class AddSchemaMigrationsPrimaryKey < ActiveRecord::Migration
tag :postdeploy
def self.up
case connection.adapter_name
when 'PostgreSQL'
execute("ALTER TABLE schema_migrations ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY USING INDEX unique_schema_migrations")
when 'MySQL', 'Mysql2'
execute("ALTER TABLE schema_migrations ADD PRIMARY KEY (version)")
remove_index :schema_migrations, :name => 'unique_schema_migrations'
end
end
def self.down
case connection.adapter_name
when 'PostgreSQL'
execute("ALTER TABLE schema_migrations DROP CONSTRAINT schema_migrations_pkey")
add_index :schema_migrations, :version, :unique => true, :name => 'unique_schema_migrations'
when 'MySQL', 'Mysql2'
execute("ALTER TABLE schema_migrations DROP PRIMARY KEY")
add_index :schema_migrations, :version, :unique => true, :name => 'unique_schema_migrations'
end
end
end