Commit 7f67108a authored by Douwe Maan's avatar Douwe Maan

Add project_mirror_data columns at the appropriate times

parent c3a8d277
...@@ -4,8 +4,11 @@ class CreateProjectMirrorData < ActiveRecord::Migration ...@@ -4,8 +4,11 @@ class CreateProjectMirrorData < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
def up def up
return if table_exists?(:project_mirror_data) if table_exists?(:project_mirror_data)
add_column :project_mirror_data, :status, :string
add_column :project_mirror_data, :jid, :string
add_column :project_mirror_data, :last_error, :text
else
create_table :project_mirror_data do |t| create_table :project_mirror_data do |t|
t.references :project, index: true, foreign_key: { on_delete: :cascade } t.references :project, index: true, foreign_key: { on_delete: :cascade }
t.string :status t.string :status
...@@ -13,8 +16,13 @@ class CreateProjectMirrorData < ActiveRecord::Migration ...@@ -13,8 +16,13 @@ class CreateProjectMirrorData < ActiveRecord::Migration
t.text :last_error t.text :last_error
end end
end end
end
def down def down
drop_table(:project_mirror_data) if table_exists?(:project_mirror_data) remove_column :project_mirror_data, :status
remove_column :project_mirror_data, :jid
remove_column :project_mirror_data, :last_error
# ee/db/migrate/20170509153720_create_project_mirror_data_ee.rb will remove the table.
end end
end end
...@@ -7,9 +7,13 @@ class CreateProjectMirrorDataEE < ActiveRecord::Migration ...@@ -7,9 +7,13 @@ class CreateProjectMirrorDataEE < ActiveRecord::Migration
def up def up
# When moving from CE to EE, project_mirror_data may already exist, but will # When moving from CE to EE, project_mirror_data may already exist, but will
# not have all the required columns. These are added in AddMissingColumnsToProjectMirrorData. # not have all the required columns.
return if table_exists?(:project_mirror_data) if table_exists?(:project_mirror_data)
add_column_with_default :project_mirror_data, :retry_count, :integer, default: 0, allow_null: false
add_column :project_mirror_data, :last_update_started_at, :datetime_with_timezone
add_column :project_mirror_data, :last_update_scheduled_at, :datetime_with_timezone
add_column :project_mirror_data, :next_execution_timestamp, :datetime_with_timezone
else
execute <<-SQL execute <<-SQL
CREATE TABLE project_mirror_data CREATE TABLE project_mirror_data
AS ( AS (
...@@ -31,6 +35,7 @@ class CreateProjectMirrorDataEE < ActiveRecord::Migration ...@@ -31,6 +35,7 @@ class CreateProjectMirrorDataEE < ActiveRecord::Migration
add_concurrent_foreign_key :project_mirror_data, :projects, column: :project_id add_concurrent_foreign_key :project_mirror_data, :projects, column: :project_id
add_concurrent_index :project_mirror_data, [:project_id], unique: true add_concurrent_index :project_mirror_data, [:project_id], unique: true
end end
end
def down def down
drop_table :project_mirror_data if table_exists?(:project_mirror_data) drop_table :project_mirror_data if table_exists?(:project_mirror_data)
......
...@@ -10,38 +10,12 @@ class AddMissingColumnsToProjectMirrorData < ActiveRecord::Migration ...@@ -10,38 +10,12 @@ class AddMissingColumnsToProjectMirrorData < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
def up def up
# Columns missing when a CE instance is upgraded to EE
unless column_exists? :project_mirror_data, :retry_count
add_column_with_default :project_mirror_data, :retry_count, :integer, default: 0, allow_null: false
add_column :project_mirror_data, :last_update_started_at, :datetime
add_column :project_mirror_data, :last_update_scheduled_at, :datetime
add_column :project_mirror_data, :next_execution_timestamp, :datetime
end
# Columns missing on an EE instance
unless column_exists? :project_mirror_data, :status
add_column :project_mirror_data, :status, :string
add_column :project_mirror_data, :jid, :string
add_column :project_mirror_data, :last_update_at, :datetime_with_timezone add_column :project_mirror_data, :last_update_at, :datetime_with_timezone
add_column :project_mirror_data, :last_successful_update_at, :datetime_with_timezone add_column :project_mirror_data, :last_successful_update_at, :datetime_with_timezone
add_column :project_mirror_data, :last_error, :text
end
end end
def down def down
if column_exists? :project_mirror_data, :retry_count
remove_column :project_mirror_data, :retry_count
remove_column :project_mirror_data, :last_update_started_at
remove_column :project_mirror_data, :last_update_scheduled_at
remove_column :project_mirror_data, :next_execution_timestamp
end
if column_exists? :project_mirror_data, :status
remove_column :project_mirror_data, :status
remove_column :project_mirror_data, :jid
remove_column :project_mirror_data, :last_update_at remove_column :project_mirror_data, :last_update_at
remove_column :project_mirror_data, :last_successful_update_at remove_column :project_mirror_data, :last_successful_update_at
remove_column :project_mirror_data, :last_error
end
end end
end end
require 'spec_helper' require 'spec_helper'
require Rails.root.join('ee', 'db', 'post_migrate', '20180430180136_migrate_mirror_attributes_data_from_projects_to_import_state.rb') require Rails.root.join('ee', 'db', 'post_migrate', '20180502130136_migrate_mirror_attributes_data_from_projects_to_import_state.rb')
describe MigrateMirrorAttributesDataFromProjectsToImportState, :migration do describe MigrateMirrorAttributesDataFromProjectsToImportState, :migration do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment