From c30fdae6987fbeb23a8d97369f6ace5150eb573b Mon Sep 17 00:00:00 2001 From: "TAKAHASHI,Toru" Date: Sun, 20 Oct 2019 18:33:22 +0900 Subject: [PATCH] [phase-21]Make it possible to migrate from previous version of glossary plugin --- app/models/glossary_term.rb | 1 + db/migrate/001_create_glossary_terms.rb | 10 ------ db/migrate/001_create_terms.rb | 34 +++++++++++++++++++ db/migrate/002_create_glossary_categories.rb | 7 ---- db/migrate/002_create_glossary_styles.rb | 24 +++++++++++++ .../003_add_category_to_glossary_terms.rb | 5 --- db/migrate/003_terms_add_columns.rb | 14 ++++++++ ...004_add_project_to_terms_and_categories.rb | 6 ---- .../004_rename_glossary_terms_from_terms.rb | 10 ++++++ .../005_add_columns_to_glossary_terms.rb | 9 ----- ...lossary_categories_from_term_categories.rb | 5 +++ ...006_add_position_to_glossary_categories.rb | 6 ---- ...sary_view_settings_from_glossary_styles.rb | 5 +++ 13 files changed, 93 insertions(+), 43 deletions(-) delete mode 100644 db/migrate/001_create_glossary_terms.rb create mode 100644 db/migrate/001_create_terms.rb delete mode 100644 db/migrate/002_create_glossary_categories.rb create mode 100644 db/migrate/002_create_glossary_styles.rb delete mode 100644 db/migrate/003_add_category_to_glossary_terms.rb create mode 100644 db/migrate/003_terms_add_columns.rb delete mode 100644 db/migrate/004_add_project_to_terms_and_categories.rb create mode 100644 db/migrate/004_rename_glossary_terms_from_terms.rb delete mode 100644 db/migrate/005_add_columns_to_glossary_terms.rb create mode 100644 db/migrate/005_rename_glossary_categories_from_term_categories.rb delete mode 100644 db/migrate/006_add_position_to_glossary_categories.rb create mode 100644 db/migrate/006_rename_glossary_view_settings_from_glossary_styles.rb diff --git a/app/models/glossary_term.rb b/app/models/glossary_term.rb index d5526e2..7baf75b 100644 --- a/app/models/glossary_term.rb +++ b/app/models/glossary_term.rb @@ -1,6 +1,7 @@ class GlossaryTerm < ActiveRecord::Base belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id' belongs_to :project + belongs_to :author, class_name: 'User', foreign_key: 'author_id' # class method from Redmine::Acts::Attachable::ClassMethods acts_as_attachable view_permission: :view_glossary, edit_permission: :manage_glossary, delete_permission: :manage_glossary diff --git a/db/migrate/001_create_glossary_terms.rb b/db/migrate/001_create_glossary_terms.rb deleted file mode 100644 index 58968a9..0000000 --- a/db/migrate/001_create_glossary_terms.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateGlossaryTerms < ActiveRecord::Migration[5.1] - def change - create_table :glossary_terms do |t| - t.string :name, null: false - t.text :description - - t.timestamps null: false - end - end -end diff --git a/db/migrate/001_create_terms.rb b/db/migrate/001_create_terms.rb new file mode 100644 index 0000000..9f9995a --- /dev/null +++ b/db/migrate/001_create_terms.rb @@ -0,0 +1,34 @@ +class CreateTerms < ActiveRecord::Migration[4.2] + def self.up + # CreateTermCategories + create_table :term_categories, :force => true do |t| + t.column :project_id, :integer, :default => 0, :null => false + t.column :name, :string, :default => '', :null => false + t.column :position, :integer, :default => 1 + end + + add_index "term_categories", ["project_id"], :name => "categories_project_id" + + create_table :terms, :force => true do |t| + t.column :project_id, :integer, :default => 0, :null => false + t.column :category_id, :integer + t.column :author_id, :integer, :default => 0, :null => false + t.column :updater_id, :integer + t.column :name, :string, :default => '', :null => false + t.column :name_en, :string, :default => '' + t.column :datatype, :string, :default => '' + t.column :codename, :string, :default => '' + t.column :description, :text + t.column :created_on, :timestamp + t.column :updated_on, :timestamp + end + + add_index "terms", ["project_id"], :name => "terms_project_id" + + end + + def self.down + drop_table :term_categories + drop_table :terms + end +end diff --git a/db/migrate/002_create_glossary_categories.rb b/db/migrate/002_create_glossary_categories.rb deleted file mode 100644 index 7e67a73..0000000 --- a/db/migrate/002_create_glossary_categories.rb +++ /dev/null @@ -1,7 +0,0 @@ -class CreateGlossaryCategories < ActiveRecord::Migration[5.1] - def change - create_table :glossary_categories do |t| - t.string :name - end - end -end diff --git a/db/migrate/002_create_glossary_styles.rb b/db/migrate/002_create_glossary_styles.rb new file mode 100644 index 0000000..863c9df --- /dev/null +++ b/db/migrate/002_create_glossary_styles.rb @@ -0,0 +1,24 @@ +class CreateGlossaryStyles < ActiveRecord::Migration[4.2] + def self.up + create_table :glossary_styles do |t| + t.column :show_desc, :boolean, :default => false + t.column :groupby, :integer, :default => 1 + t.column :project_scope, :integer, :default => 0 + t.column :sort_item_0, :string, :default => '' + t.column :sort_item_1, :string, :default => '' + t.column :sort_item_2, :string, :default => '' + t.column :user_id, :integer, :default => 0 + end + + add_column :terms, :rubi, :string, :default => '' + add_column :terms, :abbr_whole, :string, :default => '' + + end + + + def self.down + drop_table :glossary_styles + remove_column :terms, :abbr_whole + remove_column :terms, :rubi + end +end diff --git a/db/migrate/003_add_category_to_glossary_terms.rb b/db/migrate/003_add_category_to_glossary_terms.rb deleted file mode 100644 index 8084512..0000000 --- a/db/migrate/003_add_category_to_glossary_terms.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCategoryToGlossaryTerms < ActiveRecord::Migration[5.1] - def change - add_reference :glossary_terms, :category, foreign_key: true - end -end diff --git a/db/migrate/003_terms_add_columns.rb b/db/migrate/003_terms_add_columns.rb new file mode 100644 index 0000000..7d49345 --- /dev/null +++ b/db/migrate/003_terms_add_columns.rb @@ -0,0 +1,14 @@ +class TermsAddColumns < ActiveRecord::Migration[4.2] + def self.up + add_column :terms, :tech_en, :string, :default => '' + add_column :terms, :name_cn, :string, :default => '' + add_column :terms, :name_fr, :string, :default => '' + end + + + def self.down + remove_column :terms, :tech_en + remove_column :terms, :name_cn + remove_column :terms, :name_fr + end +end diff --git a/db/migrate/004_add_project_to_terms_and_categories.rb b/db/migrate/004_add_project_to_terms_and_categories.rb deleted file mode 100644 index 295e2c5..0000000 --- a/db/migrate/004_add_project_to_terms_and_categories.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddProjectToTermsAndCategories < ActiveRecord::Migration[5.1] - def change - add_reference :glossary_terms, :project, foreign_key: true - add_reference :glossary_categories, :project, foreign_key: true - end -end diff --git a/db/migrate/004_rename_glossary_terms_from_terms.rb b/db/migrate/004_rename_glossary_terms_from_terms.rb new file mode 100644 index 0000000..29c0d9d --- /dev/null +++ b/db/migrate/004_rename_glossary_terms_from_terms.rb @@ -0,0 +1,10 @@ +class RenameGlossaryTermsFromTerms < ActiveRecord::Migration[5.2] + def change + remove_column :terms, :tech_en, :string + remove_column :terms, :name_cn, :string + remove_column :terms, :name_fr, :string + rename_column :terms, :created_on, :created_at + rename_column :terms, :updated_on, :updated_at + rename_table :terms, :glossary_terms + end +end diff --git a/db/migrate/005_add_columns_to_glossary_terms.rb b/db/migrate/005_add_columns_to_glossary_terms.rb deleted file mode 100644 index aaf41ae..0000000 --- a/db/migrate/005_add_columns_to_glossary_terms.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddColumnsToGlossaryTerms < ActiveRecord::Migration[5.1] - def change - add_column :glossary_terms, :name_en, :string, default: '' - add_column :glossary_terms, :rubi, :string, default: '' - add_column :glossary_terms, :abbr_whole, :string, default: '' - add_column :glossary_terms, :datatype, :string, default: '' - add_column :glossary_terms, :codename, :string, default: '' - end -end diff --git a/db/migrate/005_rename_glossary_categories_from_term_categories.rb b/db/migrate/005_rename_glossary_categories_from_term_categories.rb new file mode 100644 index 0000000..5265d22 --- /dev/null +++ b/db/migrate/005_rename_glossary_categories_from_term_categories.rb @@ -0,0 +1,5 @@ +class RenameGlossaryCategoriesFromTermCategories < ActiveRecord::Migration[5.2] + def change + rename_table :term_categories, :glossary_categories + end +end \ No newline at end of file diff --git a/db/migrate/006_add_position_to_glossary_categories.rb b/db/migrate/006_add_position_to_glossary_categories.rb deleted file mode 100644 index e006c64..0000000 --- a/db/migrate/006_add_position_to_glossary_categories.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddPositionToGlossaryCategories < ActiveRecord::Migration[5.2] - - def change - add_column :glossary_categories, :position, :integer, default: nil - end -end diff --git a/db/migrate/006_rename_glossary_view_settings_from_glossary_styles.rb b/db/migrate/006_rename_glossary_view_settings_from_glossary_styles.rb new file mode 100644 index 0000000..9da29d1 --- /dev/null +++ b/db/migrate/006_rename_glossary_view_settings_from_glossary_styles.rb @@ -0,0 +1,5 @@ +class RenameGlossaryViewSettingsFromGlossaryStyles < ActiveRecord::Migration[5.2] + def change + rename_table :glossary_styles, :glossary_view_settings + end +end \ No newline at end of file