diff options
author | tiagonbotelho <tiagonbotelho@hotmail.com> | 2016-03-01 01:55:36 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-03-07 21:59:39 +0100 |
commit | a14b98f858cadf60c67db4cbd23aa10ae0d5213b (patch) | |
tree | d49c658b5babf33ef08eeedd96bb053688996910 /db/migrate/20160229193553_add_main_language_to_repository.rb | |
parent | d9e646a796795de43b23a27b74289f44255810e3 (diff) | |
download | gitlab-ce-a14b98f858cadf60c67db4cbd23aa10ae0d5213b.tar.gz |
implements project languages saving them onto the database
Diffstat (limited to 'db/migrate/20160229193553_add_main_language_to_repository.rb')
-rw-r--r-- | db/migrate/20160229193553_add_main_language_to_repository.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20160229193553_add_main_language_to_repository.rb b/db/migrate/20160229193553_add_main_language_to_repository.rb new file mode 100644 index 00000000000..da24abd2f04 --- /dev/null +++ b/db/migrate/20160229193553_add_main_language_to_repository.rb @@ -0,0 +1,21 @@ +class AddMainLanguageToRepository < ActiveRecord::Migration + require 'rugged' + require 'linguist' + + def up + add_column :projects, :main_language, :string, default: nil + + Project.all.each do |project| + unless project.repository.empty? + language = Linguist::Repository.new( + project.repository.rugged, + project.repository.rugged.head.target_id).language + project.update_attributes(main_language: language) + end + end + end + + def down + remove_column :projects, :main_language + end +end |