Make migrations independent of globalize

There are two reasons for this change:

1. Past migrations depending on models will not work once a model is
removed, and they won't work if we remove Globalize either
2. We were getting a conflict in the schema file; when run under Rails
5.0, these migrations were generating a different schema than in Rails
5.1, due to the way the `create_translation_table!` method handles the
`id: :serial` attribute.
This commit is contained in:
Javi Martín
2020-04-16 13:52:26 +02:00
parent 37361a6f3d
commit 688aa88366
21 changed files with 257 additions and 257 deletions

View File

@@ -1,27 +1,27 @@
class MakeInvestmentMilestonesPolymorphic < ActiveRecord::Migration[4.2] class MakeInvestmentMilestonesPolymorphic < ActiveRecord::Migration[4.2]
def change def change
create_table :milestones do |t| create_table :milestones, id: :serial do |t|
t.references :milestoneable, polymorphic: true t.string :milestoneable_type
t.integer :milestoneable_id
t.string "title", limit: 80 t.string "title", limit: 80
t.text "description" t.text "description"
t.datetime "publication_date" t.datetime "publication_date"
t.references :status, index: true t.integer :status_id, index: true
t.timestamps null: false t.timestamps null: false
end end
reversible do |change| create_table :milestone_translations do |t|
change.up do t.integer :milestone_id, null: false
Milestone.create_translation_table!({ t.string :locale, null: false
title: :string, t.timestamps null: false
description: :text
})
end
change.down do t.string :title
Milestone.drop_translation_table! t.text :description
end
t.index :locale
t.index :milestone_id
end end
end end
end end

View File

@@ -1,20 +1,18 @@
class CreateI18nContentTranslations < ActiveRecord::Migration[4.2] class CreateI18nContentTranslations < ActiveRecord::Migration[4.2]
def change def change
create_table :i18n_contents do |t| create_table :i18n_contents, id: :serial do |t|
t.string :key t.string :key
end end
reversible do |dir| create_table :i18n_content_translations do |t|
dir.up do t.integer :i18n_content_id, null: false
I18nContent.create_translation_table!( t.string :locale, null: false
{ value: :text }, t.timestamps null: false
{ migrate_data: true }
)
end
dir.down do t.text :value
I18nContent.drop_translation_table!
end t.index :i18n_content_id
t.index :locale
end end
end end
end end

View File

@@ -1,15 +1,15 @@
class AddBannerTranslations < ActiveRecord::Migration[4.2] class AddBannerTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Banner.create_translation_table!( create_table :banner_translations do |t|
{ t.integer :banner_id, null: false
title: :string, t.string :locale, null: false
description: :text t.timestamps null: false
},
{ migrate_data: true }
)
end
def self.down t.string :title
Banner.drop_translation_table! t.text :description
t.index :banner_id
t.index :locale
end
end end
end end

View File

@@ -1,17 +1,17 @@
class AddHomepageContentTranslations < ActiveRecord::Migration[4.2] class AddHomepageContentTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Widget::Card.create_translation_table!( create_table :widget_card_translations do |t|
{ t.integer :widget_card_id, null: false
label: :string, t.string :locale, null: false
title: :string, t.timestamps null: false
description: :text,
link_text: :string
},
{ migrate_data: true }
)
end
def self.down t.string :label
Widget::Card.drop_translation_table! t.string :title
t.text :description
t.string :link_text
t.index :locale
t.index :widget_card_id
end
end end
end end

View File

@@ -1,16 +1,16 @@
class AddPollTranslations < ActiveRecord::Migration[4.2] class AddPollTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Poll.create_translation_table!( create_table :poll_translations do |t|
{ t.integer :poll_id, null: false
name: :string, t.string :locale, null: false
summary: :text, t.timestamps null: false
description: :text
},
{ migrate_data: true }
)
end
def self.down t.string :name
Poll.drop_translation_table! t.text :summary
t.text :description
t.index :locale
t.index :poll_id
end
end end
end end

View File

@@ -1,15 +1,15 @@
class AddAdminNotificationTranslations < ActiveRecord::Migration[4.2] class AddAdminNotificationTranslations < ActiveRecord::Migration[4.2]
def self.up def change
AdminNotification.create_translation_table!( create_table :admin_notification_translations do |t|
{ t.integer :admin_notification_id, null: false
title: :string, t.string :locale, null: false
body: :text t.timestamps null: false
},
{ migrate_data: true }
)
end
def self.down t.string :title
AdminNotification.drop_translation_table! t.text :body
t.index :admin_notification_id
t.index :locale
end
end end
end end

View File

@@ -1,12 +1,14 @@
class AddPollQuestionTranslations < ActiveRecord::Migration[4.2] class AddPollQuestionTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Poll::Question.create_translation_table!( create_table :poll_question_translations do |t|
{ title: :string }, t.integer :poll_question_id, null: false
{ migrate_data: true } t.string :locale, null: false
) t.timestamps null: false
end
def self.down t.string :title
Poll::Question.drop_translation_table!
t.index :locale
t.index :poll_question_id
end
end end
end end

View File

@@ -1,15 +1,15 @@
class AddPollQuestionAnswerTranslations < ActiveRecord::Migration[4.2] class AddPollQuestionAnswerTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Poll::Question::Answer.create_translation_table!( create_table :poll_question_answer_translations do |t|
{ t.integer :poll_question_answer_id, null: false
title: :string, t.string :locale, null: false
description: :text t.timestamps null: false
},
{ migrate_data: true }
)
end
def self.down t.string :title
Poll::Question::Answer.drop_translation_table! t.text :description
t.index :locale
t.index :poll_question_answer_id, name: "index_85270fa85f62081a3a227186b4c95fe4f7fa94b9"
end
end end
end end

View File

@@ -1,42 +1,54 @@
class AddCollaborativeLegislationTranslations < ActiveRecord::Migration[4.2] class AddCollaborativeLegislationTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Legislation::Process.create_translation_table!( create_table :legislation_process_translations do |t|
{ t.integer :legislation_process_id, null: false
title: :string, t.string :locale, null: false
summary: :text, t.timestamps null: false
description: :text,
additional_info: :text
},
{ migrate_data: true }
)
Legislation::Question.create_translation_table!( t.string :title
{ title: :text }, t.text :summary
{ migrate_data: true } t.text :description
) t.text :additional_info
Legislation::DraftVersion.create_translation_table!( t.index :legislation_process_id, name: "index_199e5fed0aca73302243f6a1fca885ce10cdbb55"
{ t.index :locale
title: :string,
changelog: :text,
body: :text
},
{ migrate_data: true }
)
add_column :legislation_draft_version_translations, :body_html, :text
add_column :legislation_draft_version_translations, :toc_html, :text
Legislation::QuestionOption.create_translation_table!(
{ value: :string },
{ migrate_data: true }
)
end end
def self.down create_table :legislation_question_translations do |t|
Legislation::Process.drop_translation_table! t.integer :legislation_question_id, null: false
Legislation::DraftVersion.drop_translation_table! t.string :locale, null: false
Legislation::Question.drop_translation_table! t.timestamps null: false
Legislation::QuestionOption.drop_translation_table!
t.text :title
t.index :legislation_question_id, name: "index_d34cc1e1fe6d5162210c41ce56533c5afabcdbd3"
t.index :locale
end
create_table :legislation_draft_version_translations do |t|
t.integer :legislation_draft_version_id, null: false
t.string :locale, null: false
t.timestamps null: false
t.string :title
t.text :changelog
t.text :body
t.text :body_html
t.text :toc_html
t.index :legislation_draft_version_id, name: "index_900e5ba94457606e69e89193db426e8ddff809bc"
t.index :locale
end
create_table :legislation_question_option_translations do |t|
t.integer :legislation_question_option_id, null: false
t.string :locale, null: false
t.timestamps null: false
t.string :value
t.index :legislation_question_option_id, name: "index_61bcec8729110b7f8e1e9e5ce08780878597a209"
t.index :locale
end
end end
end end

View File

@@ -1,19 +1,18 @@
class AddTranslatePages < ActiveRecord::Migration[4.2] class AddTranslatePages < ActiveRecord::Migration[4.2]
def self.up def change
SiteCustomization::Page.create_translation_table!( create_table :site_customization_page_translations do |t|
{ t.integer :site_customization_page_id, null: false
title: :string, t.string :locale, null: false
subtitle: :string, t.timestamps null: false
content: :text
},
{ migrate_data: true }
)
change_column :site_customization_pages, :title, :string, null: true t.string :title
t.string :subtitle
t.text :content
t.index :locale
t.index :site_customization_page_id, name: "index_7fa0f9505738cb31a31f11fb2f4c4531fed7178b"
end end
def self.down change_column_null :site_customization_pages, :title, from: false, to: true
SiteCustomization::Page.drop_translation_table!
change_column :site_customization_pages, :title, :string, null: false
end end
end end

View File

@@ -1,17 +1,17 @@
class AddProposalsTranslations < ActiveRecord::Migration[4.2] class AddProposalsTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Proposal.create_translation_table!( create_table :proposal_translations do |t|
{ t.integer :proposal_id, null: false
title: :string, t.string :locale, null: false
description: :text, t.timestamps null: false
summary: :text,
retired_explanation: :text
},
{ migrate_data: true }
)
end
def self.down t.string :title
Proposal.drop_translation_table! t.text :description
t.text :summary
t.text :retired_explanation
t.index :locale
t.index :proposal_id
end
end end
end end

View File

@@ -1,15 +1,15 @@
class AddDebatesTranslations < ActiveRecord::Migration[4.2] class AddDebatesTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Debate.create_translation_table!( create_table :debate_translations do |t|
{ t.integer :debate_id, null: false
title: :string, t.string :locale, null: false
description: :text t.timestamps null: false
},
{ migrate_data: true }
)
end
def self.down t.string :title
Debate.drop_translation_table! t.text :description
t.index :debate_id
t.index :locale
end
end end
end end

View File

@@ -1,14 +1,14 @@
class AddCommentsTranslations < ActiveRecord::Migration[4.2] class AddCommentsTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Comment.create_translation_table!( create_table :comment_translations do |t|
{ t.integer :comment_id, null: false
body: :text t.string :locale, null: false
}, t.timestamps null: false
{ migrate_data: true }
)
end
def self.down t.text :body
Comment.drop_translation_table!
t.index :comment_id
t.index :locale
end
end end
end end

View File

@@ -1,15 +1,6 @@
class AddHomePageToLegislationProcesses < ActiveRecord::Migration[4.2] class AddHomePageToLegislationProcesses < ActiveRecord::Migration[4.2]
def change def change
add_column :legislation_processes, :homepage_enabled, :boolean, default: false add_column :legislation_processes, :homepage_enabled, :boolean, default: false
add_column :legislation_process_translations, :homepage, :text
reversible do |dir|
dir.up do
Legislation::Process.add_translation_fields! homepage: :text
end
dir.down do
remove_column :legislation_process_translations, :homepage
end
end
end end
end end

View File

@@ -1,17 +1,15 @@
class AddBudgetInvestmentTranslations < ActiveRecord::Migration[4.2] class AddBudgetInvestmentTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Budget::Investment::Translation.without_auditing do create_table :budget_investment_translations do |t|
Budget::Investment.create_translation_table!( t.integer :budget_investment_id, null: false
{ t.string :locale, null: false
title: :string, t.timestamps null: false
description: :text
},
{ migrate_data: true }
)
end
end
def self.down t.string :title
Budget::Investment.drop_translation_table! t.text :description
t.index :budget_investment_id
t.index :locale
end
end end
end end

View File

@@ -1,23 +1,23 @@
class CreateProgressBars < ActiveRecord::Migration[4.2] class CreateProgressBars < ActiveRecord::Migration[4.2]
def change def change
create_table :progress_bars do |t| create_table :progress_bars, id: :serial do |t|
t.integer :kind t.integer :kind
t.integer :percentage t.integer :percentage
t.references :progressable, polymorphic: true t.string :progressable_type
t.integer :progressable_id
t.timestamps null: false t.timestamps null: false
end end
reversible do |change| create_table :progress_bar_translations do |t|
change.up do t.integer :progress_bar_id, null: false
ProgressBar.create_translation_table!({ t.string :locale, null: false
title: :string t.timestamps null: false
})
end
change.down do t.string :title
ProgressBar.drop_translation_table!
end t.index :locale
t.index :progress_bar_id
end end
end end
end end

View File

@@ -1,14 +1,14 @@
class AddActivePollsTranslations < ActiveRecord::Migration[4.2] class AddActivePollsTranslations < ActiveRecord::Migration[4.2]
def self.up def change
ActivePoll.create_translation_table!( create_table :active_poll_translations do |t|
{ t.integer :active_poll_id, null: false
description: :text t.string :locale, null: false
}, t.timestamps null: false
{ migrate_data: true }
)
end
def self.down t.text "description"
ActivePollPoll.drop_translation_table!
t.index :active_poll_id
t.index :locale
end
end end
end end

View File

@@ -1,14 +1,14 @@
class AddBudgetTranslations < ActiveRecord::Migration[4.2] class AddBudgetTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Budget.create_translation_table!( create_table :budget_translations do |t|
{ t.integer :budget_id, null: false
name: :string t.string :locale, null: false
}, t.timestamps null: false
{ migrate_data: true }
)
end
def self.down t.string :name
Budget.drop_translation_table!
t.index :budget_id
t.index :locale
end
end end
end end

View File

@@ -1,15 +1,15 @@
class AddBudgetPhaseTranslations < ActiveRecord::Migration[4.2] class AddBudgetPhaseTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Budget::Phase.create_translation_table!( create_table :budget_phase_translations do |t|
{ t.integer :budget_phase_id, null: false
description: :text, t.string :locale, null: false
summary: :text t.timestamps null: false
},
{ migrate_data: true }
)
end
def self.down t.text :description
Budget::Phase.drop_translation_table! t.text :summary
t.index :budget_phase_id
t.index :locale
end
end end
end end

View File

@@ -1,14 +1,14 @@
class AddBudgetGroupTranslations < ActiveRecord::Migration[4.2] class AddBudgetGroupTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Budget::Group.create_translation_table!( create_table :budget_group_translations do |t|
{ t.integer :budget_group_id, null: false
name: :string t.string :locale, null: false
}, t.timestamps null: false
{ migrate_data: true }
)
end
def self.down t.string :name
Budget::Group.drop_translation_table!
t.index :budget_group_id
t.index :locale
end
end end
end end

View File

@@ -1,14 +1,14 @@
class AddBudgetHeadingTranslations < ActiveRecord::Migration[4.2] class AddBudgetHeadingTranslations < ActiveRecord::Migration[4.2]
def self.up def change
Budget::Heading.create_translation_table!( create_table :budget_heading_translations do |t|
{ t.integer :budget_heading_id, null: false
name: :string t.string :locale, null: false
}, t.timestamps null: false
{ migrate_data: true }
)
end
def self.down t.string :name
Budget::Heading.drop_translation_table!
t.index :budget_heading_id
t.index :locale
end
end end
end end