Commit 533593e9 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'dz-squash-old-migrations' into 'master'

Squash migrations from 2013

See merge request gitlab-org/gitlab-ce!18547
parents 9e03f960 15fcd965
# rubocop:disable all
class RenameOwnerToCreatorForProject < ActiveRecord::Migration
def change
rename_column :projects, :owner_id, :creator_id
end
end
# rubocop:disable all
class AddPublicToProject < ActiveRecord::Migration
def change
add_column :projects, :public, :boolean, default: false, null: false
end
end
# rubocop:disable all
class AddIssuesTrackerToProject < ActiveRecord::Migration
def change
add_column :projects, :issues_tracker, :string, default: :gitlab, null: false
end
end
# rubocop:disable all
class AddUserPermissions < ActiveRecord::Migration
def up
add_column :users, :can_create_group, :boolean, default: true, null: false
add_column :users, :can_create_team, :boolean, default: true, null: false
end
def down
remove_column :users, :can_create_group
remove_column :users, :can_create_team
end
end
# rubocop:disable all
class RemovePrivateFlagFromProject < ActiveRecord::Migration
def up
remove_column :projects, :private_flag
end
def down
add_column :projects, :private_flag, :boolean, default: true, null: false
end
end
# rubocop:disable all
class AddDescriptionToNamsespace < ActiveRecord::Migration
def change
add_column :namespaces, :description, :string, default: '', null: false
end
end
# rubocop:disable all
class AddDescriptionToTeams < ActiveRecord::Migration
def change
add_column :user_teams, :description, :string, default: '', null: false
end
end
# rubocop:disable all
class AddIssuesTrackerIdToProject < ActiveRecord::Migration
def change
add_column :projects, :issues_tracker_id, :string
end
end
# rubocop:disable all
class RenameStateToMergeStatusInMilestone < ActiveRecord::Migration
def change
rename_column :merge_requests, :state, :merge_status
end
end
# rubocop:disable all
class AddStateToIssue < ActiveRecord::Migration
def change
add_column :issues, :state, :string
end
end
# rubocop:disable all
class AddStateToMergeRequest < ActiveRecord::Migration
def change
add_column :merge_requests, :state, :string
end
end
# rubocop:disable all
class AddStateToMilestone < ActiveRecord::Migration
def change
add_column :milestones, :state, :string
end
end
# rubocop:disable all
class ConvertClosedToStateInIssue < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
def up
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value}"
execute "UPDATE #{table_name} SET state = 'opened' WHERE closed = #{false_value}"
end
def down
execute "UPDATE #{table_name} SET closed = #{true_value} WHERE state = 'closed'"
end
private
def table_name
Issue.table_name
end
end
# rubocop:disable all
class ConvertClosedToStateInMergeRequest < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
def up
execute "UPDATE #{table_name} SET state = 'merged' WHERE closed = #{true_value} AND merged = #{true_value}"
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value} AND merged = #{false_value}"
execute "UPDATE #{table_name} SET state = 'opened' WHERE closed = #{false_value}"
end
def down
execute "UPDATE #{table_name} SET closed = #{true_value} WHERE state = 'closed'"
execute "UPDATE #{table_name} SET closed = #{true_value}, merged = #{true_value} WHERE state = 'merged'"
end
private
def table_name
MergeRequest.table_name
end
end
# rubocop:disable all
class ConvertClosedToStateInMilestone < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
def up
execute "UPDATE #{table_name} SET state = 'closed' WHERE closed = #{true_value}"
execute "UPDATE #{table_name} SET state = 'active' WHERE closed = #{false_value}"
end
def down
execute "UPDATE #{table_name} SET closed = #{true_value} WHERE state = 'cloesd'"
end
private
def table_name
Milestone.table_name
end
end
# rubocop:disable all
class RemoveMergedFromMergeRequest < ActiveRecord::Migration
def up
remove_column :merge_requests, :merged
end
def down
add_column :merge_requests, :merged, :boolean, default: true, null: false
end
end
# rubocop:disable all
class RemoveClosedFromIssue < ActiveRecord::Migration
def up
remove_column :issues, :closed
end
def down
add_column :issues, :closed, :boolean
end
end
# rubocop:disable all
class RemoveClosedFromMergeRequest < ActiveRecord::Migration
def up
remove_column :merge_requests, :closed
end
def down
add_column :merge_requests, :closed, :boolean
end
end
# rubocop:disable all
class RemoveClosedFromMilestone < ActiveRecord::Migration
def up
remove_column :milestones, :closed
end
def down
add_column :milestones, :closed, :boolean
end
end
# rubocop:disable all
class AddNewMergeStatusToMergeRequest < ActiveRecord::Migration
def change
add_column :merge_requests, :new_merge_status, :string
end
end
# rubocop:disable all
class ConvertMergeStatusInMergeRequest < ActiveRecord::Migration
def up
execute "UPDATE #{table_name} SET new_merge_status = 'unchecked' WHERE merge_status = 1"
execute "UPDATE #{table_name} SET new_merge_status = 'can_be_merged' WHERE merge_status = 2"
execute "UPDATE #{table_name} SET new_merge_status = 'cannot_be_merged' WHERE merge_status = 3"
end
def down
execute "UPDATE #{table_name} SET merge_status = 1 WHERE new_merge_status = 'unchecked'"
execute "UPDATE #{table_name} SET merge_status = 2 WHERE new_merge_status = 'can_be_merged'"
execute "UPDATE #{table_name} SET merge_status = 3 WHERE new_merge_status = 'cannot_be_merged'"
end
private
def table_name
MergeRequest.table_name
end
end
# rubocop:disable all
class RemoveMergeStatusFromMergeRequest < ActiveRecord::Migration
def up
remove_column :merge_requests, :merge_status
end
def down
add_column :merge_requests, :merge_status, :integer
end
end
# rubocop:disable all
class RenameNewMergeStatusToMergeStatusInMilestone < ActiveRecord::Migration
def change
rename_column :merge_requests, :new_merge_status, :merge_status
end
end
# rubocop:disable all
class AddStateToUser < ActiveRecord::Migration
def change
add_column :users, :state, :string
end
end
# rubocop:disable all
class ConvertBlockedToState < ActiveRecord::Migration
def up
User.transaction do
User.where(blocked: true).update_all(state: :blocked)
User.where(blocked: false).update_all(state: :active)
end
end
def down
User.transaction do
User.where(state: :blocked).update_all(blocked: :true)
end
end
end
# rubocop:disable all
class RemoveBlockedFromUser < ActiveRecord::Migration
def up
remove_column :users, :blocked
end
def down
add_column :users, :blocked, :boolean
end
end
# rubocop:disable all
class UserColorScheme < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
def up
add_column :users, :color_scheme_id, :integer, null: false, default: 1
execute("UPDATE users SET color_scheme_id = 2 WHERE dark_scheme = #{true_value}")
remove_column :users, :dark_scheme
end
def down
add_column :users, :dark_scheme, :boolean, null: false, default: false
remove_column :users, :color_scheme_id
end
end
# rubocop:disable all
class AddSnippetsToFeatures < ActiveRecord::Migration
def change
add_column :projects, :snippets_enabled, :boolean, null: false, default: true
end
end
# rubocop:disable all
class CreateForkedProjectLinks < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :forked_project_links do |t|
t.integer :forked_to_project_id, null: false
t.integer :forked_from_project_id, null: false
t.timestamps null: true
end
add_index :forked_project_links, :forked_to_project_id, unique: true
end
end
# rubocop:disable all
class AddPrivateToSnippets < ActiveRecord::Migration
def change
add_column :snippets, :private, :boolean, null: false, default: true
end
end
# rubocop:disable all
class AddTypeToSnippets < ActiveRecord::Migration
def change
add_column :snippets, :type, :string
end
end
# rubocop:disable all
class ChangeProjectIdToNullInSnipepts < ActiveRecord::Migration
def up
change_column :snippets, :project_id, :integer, :null => true
end
def down
change_column :snippets, :project_id, :integer, :null => false
end
end
# rubocop:disable all
class AddTypeValueForSnippets < ActiveRecord::Migration
def up
Snippet.where("project_id IS NOT NULL").update_all(type: 'ProjectSnippet')
end
def down
end
end
# rubocop:disable all
class AddNotificationLevelToUser < ActiveRecord::Migration
def change
add_column :users, :notification_level, :integer, null: false, default: 1
end
end
# rubocop:disable all
class AddIndexToUsersAuthenticationToken < ActiveRecord::Migration
def change
add_index :users, :authentication_token, unique: true
end
end
# rubocop:disable all
class AddLastActivityColumnIntoProject < ActiveRecord::Migration
def up
add_column :projects, :last_activity_at, :datetime
add_index :projects, :last_activity_at
select_all('SELECT id, updated_at FROM projects').each do |project|
project_id = project['id']
update_date = project['updated_at']
event = select_one("SELECT created_at FROM events WHERE project_id = #{project_id} ORDER BY created_at DESC LIMIT 1")
if event && event['created_at']
update_date = event['created_at']
end
execute("UPDATE projects SET last_activity_at = '#{update_date}' WHERE id = #{project_id}")
end
end
def down
remove_index :projects, :last_activity_at
remove_column :projects, :last_activity_at
end
end
# rubocop:disable all
class AddNotificationLevelToUserProject < ActiveRecord::Migration
def change
add_column :users_projects, :notification_level, :integer, null: false, default: 3
end
end
# rubocop:disable all
class RemoveWikiTable < ActiveRecord::Migration
def up
drop_table :wikis
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
# rubocop:disable all
class AllowMergesForForks < ActiveRecord::Migration
def self.up
add_column :merge_requests, :target_project_id, :integer, :null => true
execute "UPDATE #{table_name} SET target_project_id = project_id"
change_column :merge_requests, :target_project_id, :integer, :null => false
rename_column :merge_requests, :project_id, :source_project_id
end
def self.down
remove_column :merge_requests, :target_project_id
rename_column :merge_requests, :source_project_id,:project_id
end
private
def table_name
MergeRequest.table_name
end
end
# rubocop:disable all
class AddTypeToKey < ActiveRecord::Migration
def change
add_column :keys, :type, :string
end
end
# rubocop:disable all
class CreateDeployKeysProjects < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :deploy_keys_projects do |t|
t.integer :deploy_key_id, null: false
t.integer :project_id, null: false
t.timestamps null: true
end
end
end
# rubocop:disable all
class RemoveProjectIdFromKey < ActiveRecord::Migration
def up
puts 'Migrate deploy keys: '
Key.where('project_id IS NOT NULL').update_all(type: 'DeployKey')
DeployKey.all.each do |key|
project = Project.find_by(id: key.project_id)
if project
project.deploy_keys << key
print '.'
end
end
puts 'Done'
remove_column :keys, :project_id
end
def down
add_column :keys, :project_id, :integer
end
end
# rubocop:disable all
class AddMoreFieldsToService < ActiveRecord::Migration
def change
add_column :services, :subdomain, :string
add_column :services, :room, :string
end
end
# rubocop:disable all
class AddSystemToNotes < ActiveRecord::Migration
class Note < ActiveRecord::Base
end
def up
add_column :notes, :system, :boolean, default: false, null: false
Note.reset_column_information
Note.update_all(system: false)
Note.where("note like '_status changed to%'").update_all(system: true)
end
def down
remove_column :notes, :system
end
end
# rubocop:disable all
class IncreaseSnippetTextColumnSize < ActiveRecord::Migration
def up
# MYSQL LARGETEXT for snippet
change_column :snippets, :content, :text, :limit => 4294967295
end
def down
end
end
# rubocop:disable all
class AddPasswordExpiresAtToUsers < ActiveRecord::Migration
def change
add_column :users, :password_expires_at, :datetime
end
end
# rubocop:disable all
class AddCreatedByIdToUser < ActiveRecord::Migration
def change
add_column :users, :created_by_id, :integer
end
end
# rubocop:disable all
class AddImprotedToProject < ActiveRecord::Migration
def change
add_column :projects, :imported, :boolean, default: false, null: false
end
end
# rubocop:disable all
class CreateUsersGroups < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :users_groups do |t|
t.integer :group_access, null: false
t.integer :group_id, null: false
t.integer :user_id, null: false
t.timestamps null: true
end
end
end
# rubocop:disable all
class AddNotificationLevelToUserGroup < ActiveRecord::Migration
def change
add_column :users_groups, :notification_level, :integer, null: false, default: 3
end
end
# rubocop:disable all
class AddMoreDbIndex < ActiveRecord::Migration
def change
add_index :deploy_keys_projects, :project_id
add_index :web_hooks, :project_id
add_index :protected_branches, :project_id
add_index :users_groups, :user_id
add_index :snippets, :author_id
add_index :notes, :author_id
add_index :notes, [:noteable_id, :noteable_type]
end
end
# rubocop:disable all
class AddFingerprintToKey < ActiveRecord::Migration
def change
add_column :keys, :fingerprint, :string
remove_column :keys, :identifier