| @@ -1,17 +1,17 @@ | |||||
| class CreateProjectCategories < ActiveRecord::Migration[5.2] | class CreateProjectCategories < ActiveRecord::Migration[5.2] | ||||
| def change | |||||
| # create_table :project_categories do |t| | |||||
| # t.string :name | |||||
| # t.integer :position | |||||
| # t.integer :projects_count, :default => 0 | |||||
| # | |||||
| # t.timestamps | |||||
| # end | |||||
| # def change | |||||
| # # create_table :project_categories do |t| | |||||
| # # t.string :name | |||||
| # # t.integer :position | |||||
| # # t.integer :projects_count, :default => 0 | |||||
| # # | |||||
| # # t.timestamps | |||||
| # # end | |||||
| names = %w(大数据 机器学习 深度学习 人工智能 量子计算 智慧医疗 自动驾驶 其他) | |||||
| names.each do |name| | |||||
| ProjectCategory.find_or_create_by!(name: name) | |||||
| end | |||||
| # names = %w(大数据 机器学习 深度学习 人工智能 量子计算 智慧医疗 自动驾驶 其他) | |||||
| # names.each do |name| | |||||
| # ProjectCategory.find_or_create_by!(name: name) | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,7 +1,7 @@ | |||||
| class SortToProjectCategoriesWithPosition < ActiveRecord::Migration[5.2] | class SortToProjectCategoriesWithPosition < ActiveRecord::Migration[5.2] | ||||
| def change | |||||
| ProjectCategory.order(:updated_at).each.with_index(1) do |pc, index| | |||||
| pc.update_column :position, index | |||||
| end | |||||
| end | |||||
| # def change | |||||
| # ProjectCategory.order(:updated_at).each.with_index(1) do |pc, index| | |||||
| # pc.update_column :position, index | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| @@ -1,17 +1,17 @@ | |||||
| class CreateProjectLanguages < ActiveRecord::Migration[5.2] | class CreateProjectLanguages < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :project_languages do |t| | |||||
| t.string :name | |||||
| t.integer :position | |||||
| t.integer :projects_count, :default => 0 | |||||
| # create_table :project_languages do |t| | |||||
| # t.string :name | |||||
| # t.integer :position | |||||
| # t.integer :projects_count, :default => 0 | |||||
| t.timestamps | |||||
| end | |||||
| # t.timestamps | |||||
| # end | |||||
| names = %w(Ruby C C# C++ HTML Haml CSS JavaScript Python PHP Java JSON JSX Lex Shell Objective-C Cycript Clojure Go Grace Gradle GraphQL Dart Elixir Erlang Perl R Reason Sass Slice SVG) | |||||
| names.each do |name| | |||||
| ProjectLanguage.find_or_create_by!(name: name) | |||||
| end | |||||
| # names = %w(Ruby C C# C++ HTML Haml CSS JavaScript Python PHP Java JSON JSX Lex Shell Objective-C Cycript Clojure Go Grace Gradle GraphQL Dart Elixir Erlang Perl R Reason Sass Slice SVG) | |||||
| # names.each do |name| | |||||
| # ProjectLanguage.find_or_create_by!(name: name) | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,14 +1,14 @@ | |||||
| class CreateLicenses < ActiveRecord::Migration[5.2] | class CreateLicenses < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :licenses do |t| | |||||
| t.string :name | |||||
| t.text :content | |||||
| # create_table :licenses do |t| | |||||
| # t.string :name | |||||
| # t.text :content | |||||
| t.timestamps | |||||
| end | |||||
| # t.timestamps | |||||
| # end | |||||
| dir_url = File.join(Rails.root, "public", "options", "license") | |||||
| GenerateDbService.call(dir_url, 'license') | |||||
| # dir_url = File.join(Rails.root, "public", "options", "license") | |||||
| # GenerateDbService.call(dir_url, 'license') | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,14 +1,14 @@ | |||||
| class CreateIgnores < ActiveRecord::Migration[5.2] | class CreateIgnores < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :ignores do |t| | |||||
| t.string :name | |||||
| t.text :content | |||||
| # create_table :ignores do |t| | |||||
| # t.string :name | |||||
| # t.text :content | |||||
| t.timestamps | |||||
| end | |||||
| # t.timestamps | |||||
| # end | |||||
| dir_url = File.join(Rails.root, "public", "options", "gitignore") | |||||
| GenerateDbService.call(dir_url, 'ignore') | |||||
| # dir_url = File.join(Rails.root, "public", "options", "gitignore") | |||||
| # GenerateDbService.call(dir_url, 'ignore') | |||||
| end | end | ||||
| end | end | ||||
| @@ -3,8 +3,8 @@ class AddUserRefToRepository < ActiveRecord::Migration[5.2] | |||||
| # add_column :repositories, :user_id, :integer | # add_column :repositories, :user_id, :integer | ||||
| # add_index :repositories, :user_id | # add_index :repositories, :user_id | ||||
| Project.joins(:repository).find_each do |project| | |||||
| project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank? | |||||
| end | |||||
| # Project.joins(:repository).find_each do |project| | |||||
| # project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank? | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,11 +1,11 @@ | |||||
| class ChangeForkedCountDefaultFromProjects < ActiveRecord::Migration[5.2] | class ChangeForkedCountDefaultFromProjects < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| change_column_default :projects, :forked_count, { from: nil, to: 0 } | |||||
| change_column_default :projects, :project_type, { from: nil, to: 0 } | |||||
| # change_column_default :projects, :forked_count, { from: nil, to: 0 } | |||||
| # change_column_default :projects, :project_type, { from: nil, to: 0 } | |||||
| Project.find_each do |project| | |||||
| project.update_column('forked_count', 0) if project.forked_count.nil? | |||||
| project.update_column('project_type', 0) if project.project_type.nil? | |||||
| end | |||||
| # Project.find_each do |project| | |||||
| # project.update_column('forked_count', 0) if project.forked_count.nil? | |||||
| # project.update_column('project_type', 0) if project.project_type.nil? | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,18 +1,18 @@ | |||||
| class AddIssuePriorityToModel < ActiveRecord::Migration[5.2] | class AddIssuePriorityToModel < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| unless ActiveRecord::Base.connection.table_exists? 'IssuePriority' | |||||
| create_table :issue_priorities do |t| | |||||
| t.string :name | |||||
| t.integer :position | |||||
| t.timestamps | |||||
| end | |||||
| # unless ActiveRecord::Base.connection.table_exists? 'IssuePriority' | |||||
| # create_table :issue_priorities do |t| | |||||
| # t.string :name | |||||
| # t.integer :position | |||||
| # t.timestamps | |||||
| # end | |||||
| add_index :issue_priorities, [:name] | |||||
| # add_index :issue_priorities, [:name] | |||||
| pr_values = %w(低 正常 高 紧急 立刻) | |||||
| pr_values.each_with_index do |v, index| | |||||
| IssuePriority.create!(name: v, position: index+1) | |||||
| end | |||||
| end | |||||
| # pr_values = %w(低 正常 高 紧急 立刻) | |||||
| # pr_values.each_with_index do |v, index| | |||||
| # IssuePriority.create!(name: v, position: index+1) | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,12 +1,12 @@ | |||||
| class CreateIssueDepends < ActiveRecord::Migration[5.2] | class CreateIssueDepends < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :issue_depends do |t| | |||||
| t.integer :user_id | |||||
| t.integer :issue_id | |||||
| t.integer :depend_issue_id | |||||
| t.timestamps | |||||
| end | |||||
| # create_table :issue_depends do |t| | |||||
| # t.integer :user_id | |||||
| # t.integer :issue_id | |||||
| # t.integer :depend_issue_id | |||||
| # t.timestamps | |||||
| # end | |||||
| add_index :issue_depends, [:user_id, :issue_id, :depend_issue_id] | |||||
| # add_index :issue_depends, [:user_id, :issue_id, :depend_issue_id] | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,12 +1,12 @@ | |||||
| class CreateProjectTrends < ActiveRecord::Migration[5.2] | class CreateProjectTrends < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :project_trends do |t| | |||||
| t.integer :user_id | |||||
| t.integer :project_id | |||||
| t.references :trend, polymorphic: true, index: true | |||||
| t.string :action_type | |||||
| t.timestamps | |||||
| end | |||||
| add_index :project_trends, [:user_id, :project_id] | |||||
| # create_table :project_trends do |t| | |||||
| # t.integer :user_id | |||||
| # t.integer :project_id | |||||
| # t.references :trend, polymorphic: true, index: true | |||||
| # t.string :action_type | |||||
| # t.timestamps | |||||
| # end | |||||
| # add_index :project_trends, [:user_id, :project_id] | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,7 +1,7 @@ | |||||
| class MigrateDefalutToTiding < ActiveRecord::Migration[5.2] | class MigrateDefalutToTiding < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| change_column_default :tidings, :status, from: nil, to: 0 | |||||
| # change_column_default :tidings, :status, from: nil, to: 0 | |||||
| Tiding.where(status: nil).update_all(status: 0) | |||||
| # Tiding.where(status: nil).update_all(status: 0) | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,9 +1,9 @@ | |||||
| class MigrateTidingStatus < ActiveRecord::Migration[5.2] | class MigrateTidingStatus < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding| | |||||
| unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists? | |||||
| tiding.update!(status: 1) | |||||
| end | |||||
| end | |||||
| # Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding| | |||||
| # unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists? | |||||
| # tiding.update!(status: 1) | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,17 +1,17 @@ | |||||
| class AddValuesToIssueTagsAndTrackers < ActiveRecord::Migration[5.2] | class AddValuesToIssueTagsAndTrackers < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| issue_status = %w(新增 正在解决 已解决 反馈 关闭 拒绝) | |||||
| trackers = %w(缺陷 功能 支持 任务 周报) | |||||
| issue_status.each_with_index do |s, index| | |||||
| unless IssueStatus.exists?(name: s) | |||||
| IssueStatus.create!(name: s, is_closed: (index == 4) , is_default: (index == 0), position: index+1) | |||||
| end | |||||
| end | |||||
| # issue_status = %w(新增 正在解决 已解决 反馈 关闭 拒绝) | |||||
| # trackers = %w(缺陷 功能 支持 任务 周报) | |||||
| # issue_status.each_with_index do |s, index| | |||||
| # unless IssueStatus.exists?(name: s) | |||||
| # IssueStatus.create!(name: s, is_closed: (index == 4) , is_default: (index == 0), position: index+1) | |||||
| # end | |||||
| # end | |||||
| trackers.each_with_index do |s, index| | |||||
| unless Tracker.exists?(name: s) | |||||
| Tracker.create!(name: s, is_in_chlog: (index == 0 || index == 1) , is_in_roadmap: (index != 0 || index != 2), position: index+1) | |||||
| end | |||||
| end | |||||
| # trackers.each_with_index do |s, index| | |||||
| # unless Tracker.exists?(name: s) | |||||
| # Tracker.create!(name: s, is_in_chlog: (index == 0 || index == 1) , is_in_roadmap: (index != 0 || index != 2), position: index+1) | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,11 +1,11 @@ | |||||
| class MigrateUserLocation < ActiveRecord::Migration[5.2] | class MigrateUserLocation < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| UserExtension.where("location like '%省'").each do |ue| | |||||
| ue.update_column("location", ue.location.chop) | |||||
| end | |||||
| # UserExtension.where("location like '%省'").each do |ue| | |||||
| # ue.update_column("location", ue.location.chop) | |||||
| # end | |||||
| UserExtension.where("location_city like '%市'").each do |ue| | |||||
| ue.update_column("location_city", ue.location_city.chop) | |||||
| end | |||||
| # UserExtension.where("location_city like '%市'").each do |ue| | |||||
| # ue.update_column("location_city", ue.location_city.chop) | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,6 +1,6 @@ | |||||
| class ChangeVersionsDescriptions < ActiveRecord::Migration[5.2] | class ChangeVersionsDescriptions < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| change_column_default :versions, :description, nil | |||||
| change_column :versions, :description, :text | |||||
| # change_column_default :versions, :description, nil | |||||
| # change_column :versions, :description, :text | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class AddLanguageToProjects < ActiveRecord::Migration[5.2] | class AddLanguageToProjects < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :projects, :language, :string | |||||
| # add_column :projects, :language, :string | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,6 +1,6 @@ | |||||
| # TODO 该字段用于trusite用户登录时,同步用户密码到gitea平台, 默认为未同步 | # TODO 该字段用于trusite用户登录时,同步用户密码到gitea平台, 默认为未同步 | ||||
| class AddIsSyncPwdToUsers < ActiveRecord::Migration[5.2] | class AddIsSyncPwdToUsers < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :users, :is_sync_pwd, :boolean, :default => true | |||||
| # add_column :users, :is_sync_pwd, :boolean, :default => true | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,69 +1,69 @@ | |||||
| class ChangeQuillToMd < ActiveRecord::Migration[5.2] | class ChangeQuillToMd < ActiveRecord::Migration[5.2] | ||||
| #迁移quill编辑器的内容为md | #迁移quill编辑器的内容为md | ||||
| def change | def change | ||||
| migrate_time = Time.current - 20.days | |||||
| # migrate_time = Time.current - 20.days | |||||
| all_issues = Issue.where("updated_on > ?", migrate_time) | |||||
| pros = PullRequest.where("updated_at > ?", migrate_time) | |||||
| journals = Journal.where("created_on > ?", migrate_time) | |||||
| # all_issues = Issue.where("updated_on > ?", migrate_time) | |||||
| # pros = PullRequest.where("updated_at > ?", migrate_time) | |||||
| # journals = Journal.where("created_on > ?", migrate_time) | |||||
| Issue.transaction do | |||||
| if all_issues.size > 0 | |||||
| all_issues.each do |i| | |||||
| description = i.description | |||||
| if description.present? && description.include?("insert") | |||||
| new_content = change_content(description) | |||||
| i.update_attribute(:description, new_content) | |||||
| end | |||||
| puts "__update_issue_content_____id:#{i.id}__" | |||||
| end | |||||
| end | |||||
| end | |||||
| # Issue.transaction do | |||||
| # if all_issues.size > 0 | |||||
| # all_issues.each do |i| | |||||
| # description = i.description | |||||
| # if description.present? && description.include?("insert") | |||||
| # new_content = change_content(description) | |||||
| # i.update_attribute(:description, new_content) | |||||
| # end | |||||
| # puts "__update_issue_content_____id:#{i.id}__" | |||||
| # end | |||||
| # end | |||||
| # end | |||||
| Journal.transaction do | |||||
| if journals.size > 0 | |||||
| journals.each do |j| | |||||
| description = j.notes | |||||
| if description.present? && description.include?("insert") | |||||
| new_content = change_content(description) | |||||
| j.update_attribute(:notes, new_content) | |||||
| end | |||||
| puts "__update_journal_content_____id:#{j.id}__" | |||||
| end | |||||
| end | |||||
| # Journal.transaction do | |||||
| # if journals.size > 0 | |||||
| # journals.each do |j| | |||||
| # description = j.notes | |||||
| # if description.present? && description.include?("insert") | |||||
| # new_content = change_content(description) | |||||
| # j.update_attribute(:notes, new_content) | |||||
| # end | |||||
| # puts "__update_journal_content_____id:#{j.id}__" | |||||
| # end | |||||
| # end | |||||
| end | |||||
| # end | |||||
| PullRequest.transaction do | |||||
| if pros.size > 0 | |||||
| pros.each do |p| | |||||
| description = p.body | |||||
| if description.present? && description.include?("insert") | |||||
| new_content = change_content(description) | |||||
| p.update_attribute(:body, new_content) | |||||
| end | |||||
| puts "__update_pull_request_content_____id:#{p.id}__" | |||||
| end | |||||
| end | |||||
| end | |||||
| # PullRequest.transaction do | |||||
| # if pros.size > 0 | |||||
| # pros.each do |p| | |||||
| # description = p.body | |||||
| # if description.present? && description.include?("insert") | |||||
| # new_content = change_content(description) | |||||
| # p.update_attribute(:body, new_content) | |||||
| # end | |||||
| # puts "__update_pull_request_content_____id:#{p.id}__" | |||||
| # end | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| def change_content(content) | def change_content(content) | ||||
| puts "####________content_____######{content}" | |||||
| new_content = "" | |||||
| return "" if content.blank? | |||||
| desc = JSON.parse(content)["ops"] | |||||
| if desc.length > 0 | |||||
| desc.each do |d| | |||||
| image = d["insert"]["image"] | |||||
| if image.present? | |||||
| new_content += "![#{image['alt']}](#{image['url']})" | |||||
| else | |||||
| new_content += d["insert"].gsub("\n", "") | |||||
| end | |||||
| end | |||||
| end | |||||
| new_content | |||||
| # puts "####________content_____######{content}" | |||||
| # new_content = "" | |||||
| # return "" if content.blank? | |||||
| # desc = JSON.parse(content)["ops"] | |||||
| # if desc.length > 0 | |||||
| # desc.each do |d| | |||||
| # image = d["insert"]["image"] | |||||
| # if image.present? | |||||
| # new_content += "![#{image['alt']}](#{image['url']})" | |||||
| # else | |||||
| # new_content += d["insert"].gsub("\n", "") | |||||
| # end | |||||
| # end | |||||
| # end | |||||
| # new_content | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,20 +1,20 @@ | |||||
| class AddSomeCountsToProject < ActiveRecord::Migration[5.2] | class AddSomeCountsToProject < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :projects, :versions_count, :integer, default: 0 #里程碑 | |||||
| add_column :repositories, :version_releases_count, :integer, default: 0 #版本发布d | |||||
| add_column :projects, :issue_tags_count, :integer, default: 0 #标签的数量 | |||||
| # add_column :projects, :versions_count, :integer, default: 0 #里程碑 | |||||
| # add_column :repositories, :version_releases_count, :integer, default: 0 #版本发布d | |||||
| # add_column :projects, :issue_tags_count, :integer, default: 0 #标签的数量 | |||||
| Project.includes(:versions, :issue_tags, repository: :version_releases).find_each do |p| | |||||
| puts "###____change_p.id____######{p.id}" | |||||
| r = p&.repository | |||||
| Project.reset_counters p.id, :versions | |||||
| Project.reset_counters p.id, :issue_tags | |||||
| # Project.includes(:versions, :issue_tags, repository: :version_releases).find_each do |p| | |||||
| # puts "###____change_p.id____######{p.id}" | |||||
| # r = p&.repository | |||||
| # Project.reset_counters p.id, :versions | |||||
| # Project.reset_counters p.id, :issue_tags | |||||
| if r.present? | |||||
| puts "###____change_p.id____######{r.id}" | |||||
| Repository.reset_counters r.id, :version_releases | |||||
| end | |||||
| # if r.present? | |||||
| # puts "###____change_p.id____######{r.id}" | |||||
| # Repository.reset_counters r.id, :version_releases | |||||
| # end | |||||
| end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class AddForkUrlToRepositories < ActiveRecord::Migration[5.2] | class AddForkUrlToRepositories < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :repositories, :fork_url, :string, default: nil | |||||
| # add_column :repositories, :fork_url, :string, default: nil | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,6 +1,6 @@ | |||||
| class AddCreatedAtToWatcher < ActiveRecord::Migration[5.2] | class AddCreatedAtToWatcher < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :watchers, :created_at, :datetime | |||||
| Watcher.update_all(created_at: Time.current) | |||||
| # add_column :watchers, :created_at, :datetime | |||||
| # Watcher.update_all(created_at: Time.current) | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,17 +1,17 @@ | |||||
| class CreateForkUsers < ActiveRecord::Migration[5.2] | class CreateForkUsers < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :fork_users do |t| | |||||
| t.integer :project_id #原始项目id | |||||
| t.integer :fork_project_id #fork后的项目id | |||||
| t.integer :user_id #fork用户的id | |||||
| t.timestamps | |||||
| end | |||||
| add_index :fork_users, :project_id | |||||
| add_index :fork_users, :user_id | |||||
| # create_table :fork_users do |t| | |||||
| # t.integer :project_id #原始项目id | |||||
| # t.integer :fork_project_id #fork后的项目id | |||||
| # t.integer :user_id #fork用户的id | |||||
| # t.timestamps | |||||
| # end | |||||
| # add_index :fork_users, :project_id | |||||
| # add_index :fork_users, :user_id | |||||
| projects = Project.where("forked_from_project_id is not null") | |||||
| projects.each do |p| | |||||
| ForkUser.create(project_id: p.forked_from_project_id, fork_project_id: p.id, user_id: p.user_id) | |||||
| end | |||||
| # projects = Project.where("forked_from_project_id is not null") | |||||
| # projects.each do |p| | |||||
| # ForkUser.create(project_id: p.forked_from_project_id, fork_project_id: p.id, user_id: p.user_id) | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class AddWatchersCountToUser < ActiveRecord::Migration[5.2] | class AddWatchersCountToUser < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :users, :watchers_count, :integer, default: 0 | |||||
| # add_column :users, :watchers_count, :integer, default: 0 | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,12 +1,12 @@ | |||||
| class CreateMirrors < ActiveRecord::Migration[5.2] | class CreateMirrors < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| create_table :mirrors do |t| | |||||
| t.integer :repo_id, foreign_key: true | |||||
| t.integer :status, default: 0, null: false, comment: "0 - succeeded, 1 - waiting, 2 - failed" | |||||
| t.integer :interval, comment: "mirror interval with unix time" | |||||
| t.datetime :next_update_time, comment: "next update mirror time, for datetime" | |||||
| # create_table :mirrors do |t| | |||||
| # t.integer :repo_id, foreign_key: true | |||||
| # t.integer :status, default: 0, null: false, comment: "0 - succeeded, 1 - waiting, 2 - failed" | |||||
| # t.integer :interval, comment: "mirror interval with unix time" | |||||
| # t.datetime :next_update_time, comment: "next update mirror time, for datetime" | |||||
| t.timestamps | |||||
| end | |||||
| # t.timestamps | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class AddIsMirrorToRepositories < ActiveRecord::Migration[5.2] | class AddIsMirrorToRepositories < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :repositories, :is_mirror, :boolean, default: false | |||||
| # add_column :repositories, :is_mirror, :boolean, default: false | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,13 +1,13 @@ | |||||
| class ChangeProjectWatchersCount < ActiveRecord::Migration[5.2] | class ChangeProjectWatchersCount < ActiveRecord::Migration[5.2] | ||||
| #修改project的watchers_count 不正确的问题 | #修改project的watchers_count 不正确的问题 | ||||
| def change | def change | ||||
| watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq | |||||
| watcher_ids.each do |i| | |||||
| puts "#######____update_project_watchers_id____##############{i}" | |||||
| p = Project.includes(:watchers).select(:id, :watchers_count).find_by(id:i) | |||||
| if p.present? | |||||
| Project.reset_counters(i, :watchers) | |||||
| end | |||||
| end | |||||
| # watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq | |||||
| # watcher_ids.each do |i| | |||||
| # puts "#######____update_project_watchers_id____##############{i}" | |||||
| # p = Project.includes(:watchers).select(:id, :watchers_count).find_by(id:i) | |||||
| # if p.present? | |||||
| # Project.reset_counters(i, :watchers) | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,11 +1,11 @@ | |||||
| class AddClosedIssuesCountToProjects < ActiveRecord::Migration[5.2] | class AddClosedIssuesCountToProjects < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :projects, :closed_issues_count, :integer, default: 0 | |||||
| # add_column :projects, :closed_issues_count, :integer, default: 0 | |||||
| projects = Project.joins(:issues).where('status_id = 5').select("projects.id, count('issues.id') as closed_issues_count").group("projects.id") | |||||
| projects.each do |pro| | |||||
| project = Project.find pro.id | |||||
| project.update_column(:closed_issues_count, pro.closed_issues_count) if project.closed_issues_count == 0 | |||||
| end | |||||
| # projects = Project.joins(:issues).where('status_id = 5').select("projects.id, count('issues.id') as closed_issues_count").group("projects.id") | |||||
| # projects.each do |pro| | |||||
| # project = Project.find pro.id | |||||
| # project.update_column(:closed_issues_count, pro.closed_issues_count) if project.closed_issues_count == 0 | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,12 +1,12 @@ | |||||
| class ChangeRepositoryReleasesCount < ActiveRecord::Migration[5.2] | class ChangeRepositoryReleasesCount < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| release_ids = VersionRelease.select(:id,:repository_id).pluck(:repository_id).uniq | |||||
| release_ids.each do |i| | |||||
| puts "#######____update_repository_releases_id____##############{i}" | |||||
| p = Repository.includes(:version_releases).select(:id, :version_releases_count).find_by(id:i) | |||||
| if p.present? | |||||
| Repository.reset_counters(i, :version_releases) | |||||
| end | |||||
| end | |||||
| # release_ids = VersionRelease.select(:id,:repository_id).pluck(:repository_id).uniq | |||||
| # release_ids.each do |i| | |||||
| # puts "#######____update_repository_releases_id____##############{i}" | |||||
| # p = Repository.includes(:version_releases).select(:id, :version_releases_count).find_by(id:i) | |||||
| # if p.present? | |||||
| # Repository.reset_counters(i, :version_releases) | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,21 +1,21 @@ | |||||
| class AddIndexForProjectLanguageAndCategory < ActiveRecord::Migration[5.2] | class AddIndexForProjectLanguageAndCategory < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| change_column :project_categories, :id, :integer, null: false | |||||
| change_column :project_languages, :id, :integer, null: false | |||||
| # change_column :project_categories, :id, :integer, null: false | |||||
| # change_column :project_languages, :id, :integer, null: false | |||||
| ProjectCategory.update_all(projects_count:0) | |||||
| ProjectLanguage.update_all(projects_count:0) | |||||
| # ProjectCategory.update_all(projects_count:0) | |||||
| # ProjectLanguage.update_all(projects_count:0) | |||||
| project_categories = Project.joins(:project_category).group("project_categories.id").size | |||||
| project_categories.each do |k,v| | |||||
| puts "#######____update_project_category_id____##############{k}" | |||||
| ProjectCategory.update_counters(k, projects_count: v) | |||||
| end | |||||
| # project_categories = Project.joins(:project_category).group("project_categories.id").size | |||||
| # project_categories.each do |k,v| | |||||
| # puts "#######____update_project_category_id____##############{k}" | |||||
| # ProjectCategory.update_counters(k, projects_count: v) | |||||
| # end | |||||
| project_languages = Project.joins(:project_language).group("project_languages.id").size | |||||
| project_languages.each do |k,v| | |||||
| puts "#######____update_project_language_id____##############{k}" | |||||
| ProjectLanguage.update_counters(k, projects_count: v) | |||||
| end | |||||
| # project_languages = Project.joins(:project_language).group("project_languages.id").size | |||||
| # project_languages.each do |k,v| | |||||
| # puts "#######____update_project_language_id____##############{k}" | |||||
| # ProjectLanguage.update_counters(k, projects_count: v) | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,6 +1,6 @@ | |||||
| class ChangeProjectCategoryLanguageIdDefault < ActiveRecord::Migration[5.2] | class ChangeProjectCategoryLanguageIdDefault < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| execute "ALTER TABLE project_languages MODIFY COLUMN id INT AUTO_INCREMENT;" | |||||
| execute "ALTER TABLE project_categories MODIFY COLUMN id INT AUTO_INCREMENT;" | |||||
| # execute "ALTER TABLE project_languages MODIFY COLUMN id INT AUTO_INCREMENT;" | |||||
| # execute "ALTER TABLE project_categories MODIFY COLUMN id INT AUTO_INCREMENT;" | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class RemoveIssuesLockVersionColumn < ActiveRecord::Migration[5.2] | class RemoveIssuesLockVersionColumn < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| remove_column :issues, :lock_version | |||||
| # remove_column :issues, :lock_version | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class AddSyncNumToMirrors < ActiveRecord::Migration[5.2] | class AddSyncNumToMirrors < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :mirrors, :sync_num, :integer, default: 1 | |||||
| # add_column :mirrors, :sync_num, :integer, default: 1 | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,6 +1,6 @@ | |||||
| class AddOriginProjectIdToPullRequest < ActiveRecord::Migration[5.2] | class AddOriginProjectIdToPullRequest < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| add_column :pull_requests, :fork_project_id, :integer | |||||
| add_column :pull_requests, :is_original, :boolean, default: false | |||||
| # add_column :pull_requests, :fork_project_id, :integer | |||||
| # add_column :pull_requests, :is_original, :boolean, default: false | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,5 +1,5 @@ | |||||
| class ChangeDescriptionLimtFromIssues < ActiveRecord::Migration[5.2] | class ChangeDescriptionLimtFromIssues < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| change_column :issues, :description, :longtext | |||||
| # change_column :issues, :description, :longtext | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,13 +1,13 @@ | |||||
| class ChangeProjectsDefaultCount < ActiveRecord::Migration[5.2] | class ChangeProjectsDefaultCount < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| projects = Project.select(:id, :issues_count,:pull_requests_count,:versions_count,:praises_count,:watchers_count).all | |||||
| projects.each do |p| | |||||
| puts p.id | |||||
| # Project.reset_counters( p.id, :issues_count, touch: false ) | |||||
| Project.reset_counters( p.id, :pull_requests_count, touch: false ) | |||||
| Project.reset_counters( p.id, :versions_count, touch: false ) | |||||
| # Project.reset_counters( p.id, :praises_count, touch: false ) | |||||
| Project.reset_counters( p.id, :watchers_count, touch: false ) | |||||
| end | |||||
| # projects = Project.select(:id, :issues_count,:pull_requests_count,:versions_count,:praises_count,:watchers_count).all | |||||
| # projects.each do |p| | |||||
| # puts p.id | |||||
| # # Project.reset_counters( p.id, :issues_count, touch: false ) | |||||
| # Project.reset_counters( p.id, :pull_requests_count, touch: false ) | |||||
| # Project.reset_counters( p.id, :versions_count, touch: false ) | |||||
| # # Project.reset_counters( p.id, :praises_count, touch: false ) | |||||
| # Project.reset_counters( p.id, :watchers_count, touch: false ) | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||
| @@ -1,15 +1,15 @@ | |||||
| class ChangeVersionsIssuesCount < ActiveRecord::Migration[5.2] | class ChangeVersionsIssuesCount < ActiveRecord::Migration[5.2] | ||||
| def change | def change | ||||
| versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count) | |||||
| versions.each do |v| | |||||
| closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size | |||||
| unless v.closed_issues_count.to_i == closed_issues | |||||
| puts v.id | |||||
| percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i) | |||||
| v.closed_issues_count = closed_issues | |||||
| v.percent = percent | |||||
| v.save | |||||
| end | |||||
| end | |||||
| # versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count) | |||||
| # versions.each do |v| | |||||
| # closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size | |||||
| # unless v.closed_issues_count.to_i == closed_issues | |||||
| # puts v.id | |||||
| # percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i) | |||||
| # v.closed_issues_count = closed_issues | |||||
| # v.percent = percent | |||||
| # v.save | |||||
| # end | |||||
| # end | |||||
| end | end | ||||
| end | end | ||||