diff --git a/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb b/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb index 26b99b61424..c48f1c938d0 100644 --- a/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb +++ b/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb @@ -20,7 +20,7 @@ class CleanupMoveSystemUploadFolderSymlink < ActiveRecord::Migration def down if File.directory?(new_directory) say "Symlinking #{old_directory} -> #{new_directory}" - FileUtils.ln_s(new_directory, old_directory) + FileUtils.ln_s(new_directory, old_directory) unless File.exist?(old_directory) else say "#{new_directory} doesn't exist, skipping." end diff --git a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb index 8590522f3ef..fb3f29ff4c9 100644 --- a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb @@ -1,6 +1,11 @@ require 'spec_helper' -describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :sidekiq do +# This migration is using UploadService, which sets uploads.secret that is only +# added to the DB schema in 20180129193323. Since the test isn't isolated, we +# just use the latest schema when testing this migration. +# Ideally, the test should not use factories nor UploadService, and rely on the +# `table` helper instead. +describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :sidekiq, :migration, schema: 20180129193323 do include TrackUntrackedUploadsHelpers subject { described_class.new } diff --git a/spec/migrations/rename_reserved_project_names_spec.rb b/spec/migrations/rename_reserved_project_names_spec.rb index e6555b1fe6b..34336d705b1 100644 --- a/spec/migrations/rename_reserved_project_names_spec.rb +++ b/spec/migrations/rename_reserved_project_names_spec.rb @@ -3,10 +3,14 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20161221153951_rename_reserved_project_names.rb') -# This migration uses multiple threads, and thus different transactions. This -# means data created in this spec may not be visible to some threads. To work -# around this we use the DELETE cleaning strategy. -describe RenameReservedProjectNames, :delete do +# This migration is using factories, which set fields that don't actually +# exist in the DB schema previous to 20161221153951. Thus we just use the +# latest schema when testing this migration. +# This is ok-ish because: +# 1. This migration is a data migration +# 2. It only relies on very stable DB fields: routes.id, routes.path, namespaces.id, projects.namespace_id +# Ideally, the test should not use factories and rely on the `table` helper instead. +describe RenameReservedProjectNames, :migration, schema: :latest do let(:migration) { described_class.new } let!(:project) { create(:project) } diff --git a/spec/support/migrations_helpers.rb b/spec/support/migrations_helpers.rb index 06322aa0586..6bf976a2cf9 100644 --- a/spec/support/migrations_helpers.rb +++ b/spec/support/migrations_helpers.rb @@ -45,7 +45,13 @@ module MigrationsHelpers end def migration_schema_version - self.class.metadata[:schema] || previous_migration.version + metadata_schema = self.class.metadata[:schema] + + if metadata_schema == :latest + migrations.last.version + else + metadata_schema || previous_migration.version + end end def schema_migrate_down! @@ -58,6 +64,8 @@ module MigrationsHelpers end def schema_migrate_up! + reset_column_in_all_models + disable_migrations_output do ActiveRecord::Migrator.migrate(migrations_paths) end