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

Add project_mirror_data columns at the appropriate times

parent c3a8d277
...@@ -4,17 +4,25 @@ class CreateProjectMirrorData < ActiveRecord::Migration ...@@ -4,17 +4,25 @@ 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
create_table :project_mirror_data do |t| add_column :project_mirror_data, :jid, :string
t.references :project, index: true, foreign_key: { on_delete: :cascade } add_column :project_mirror_data, :last_error, :text
t.string :status else
t.string :jid create_table :project_mirror_data do |t|
t.text :last_error t.references :project, index: true, foreign_key: { on_delete: :cascade }
t.string :status
t.string :jid
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,29 +7,34 @@ class CreateProjectMirrorDataEE < ActiveRecord::Migration ...@@ -7,29 +7,34 @@ 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
execute <<-SQL add_column :project_mirror_data, :last_update_started_at, :datetime_with_timezone
CREATE TABLE project_mirror_data add_column :project_mirror_data, :last_update_scheduled_at, :datetime_with_timezone
AS ( add_column :project_mirror_data, :next_execution_timestamp, :datetime_with_timezone
SELECT id AS project_id, else
0 AS retry_count, execute <<-SQL
CAST(NULL AS #{timestamp}) AS last_update_started_at, CREATE TABLE project_mirror_data
CAST(NULL AS #{timestamp}) AS last_update_scheduled_at, AS (
NOW() AS next_execution_timestamp, SELECT id AS project_id,
NOW() AS created_at, 0 AS retry_count,
NOW() AS updated_at CAST(NULL AS #{timestamp}) AS last_update_started_at,
FROM projects CAST(NULL AS #{timestamp}) AS last_update_scheduled_at,
WHERE mirror IS TRUE NOW() AS next_execution_timestamp,
); NOW() AS created_at,
SQL NOW() AS updated_at
FROM projects
add_column :project_mirror_data, :id, :primary_key WHERE mirror IS TRUE
change_column_default :project_mirror_data, :retry_count, 0 );
change_column_null :project_mirror_data, :retry_count, false SQL
add_concurrent_foreign_key :project_mirror_data, :projects, column: :project_id
add_concurrent_index :project_mirror_data, [:project_id], unique: true add_column :project_mirror_data, :id, :primary_key
change_column_default :project_mirror_data, :retry_count, 0
change_column_null :project_mirror_data, :retry_count, false
add_concurrent_foreign_key :project_mirror_data, :projects, column: :project_id
add_concurrent_index :project_mirror_data, [:project_id], unique: true
end
end end
def down def down
......
...@@ -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 add_column :project_mirror_data, :last_update_at, :datetime_with_timezone
unless column_exists? :project_mirror_data, :retry_count add_column :project_mirror_data, :last_successful_update_at, :datetime_with_timezone
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_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, :last_update_at
remove_column :project_mirror_data, :retry_count remove_column :project_mirror_data, :last_successful_update_at
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_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