mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 11:48:06 +01:00
Change how migrations duplicated between glitch and upstream are handled (#2878)
This commit is contained in:
parent
7033b3476e
commit
c574f5b53f
3 changed files with 15 additions and 63 deletions
|
@ -1,56 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
# Some migrations have been present in glitch-soc for a long time and have then
|
|
||||||
# been merged in upstream Mastodon, under a different version number.
|
|
||||||
#
|
|
||||||
# This puts us in an uneasy situation in which if we remove upstream's
|
|
||||||
# migration file, people migrating from upstream will end up having a conflict
|
|
||||||
# with their already-ran migration.
|
|
||||||
#
|
|
||||||
# On the other hand, if we keep upstream's migration and remove our own,
|
|
||||||
# any current glitch-soc user will have a conflict during migration.
|
|
||||||
#
|
|
||||||
# For lack of a better solution, as those migrations are indeed identical,
|
|
||||||
# we decided monkey-patching Rails' Migrator to completely ignore the duplicate,
|
|
||||||
# keeping only the one that has run, or an arbitrary one.
|
|
||||||
|
|
||||||
ALLOWED_DUPLICATES = [2018_04_10_220657, 2018_08_31_171112].freeze
|
|
||||||
|
|
||||||
module ActiveRecord
|
|
||||||
class Migrator
|
|
||||||
def self.new(direction, migrations, schema_migration, internal_metadata, target_version = nil)
|
|
||||||
migrated = Set.new(Base.connection.migration_context.get_all_versions)
|
|
||||||
|
|
||||||
migrations.group_by(&:name).each_value do |duplicates|
|
|
||||||
next unless duplicates.length > 1 && duplicates.all? { |m| ALLOWED_DUPLICATES.include?(m.version) }
|
|
||||||
|
|
||||||
# We have a set of allowed duplicates. Keep the migrated one, if any.
|
|
||||||
non_migrated = duplicates.reject { |m| migrated.include?(m.version.to_i) }
|
|
||||||
|
|
||||||
migrations = begin
|
|
||||||
if duplicates.length == non_migrated.length || non_migrated.empty?
|
|
||||||
# There weren't any migrated one, so we have to pick one “canonical” migration
|
|
||||||
migrations - duplicates[1..]
|
|
||||||
else
|
|
||||||
# Just reject every duplicate which hasn't been migrated yet
|
|
||||||
migrations - non_migrated
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class MigrationContext
|
|
||||||
def needs_migration?
|
|
||||||
# A set of duplicated migrations is considered migrated if at least one of
|
|
||||||
# them is migrated.
|
|
||||||
migrated = get_all_versions
|
|
||||||
migrations.group_by(&:name).each_value do |duplicates|
|
|
||||||
return true unless duplicates.any? { |m| migrated.include?(m.version.to_i) }
|
|
||||||
end
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,10 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# This migration is a duplicate of 20180831171112 and may get ignored, see
|
# This migration is a duplicate of 20180831171112
|
||||||
# config/initializers/0_duplicate_migrations.rb
|
|
||||||
|
class GlitchCreateBookmarks < ActiveRecord::Migration[5.1]
|
||||||
|
def up
|
||||||
|
return if table_exists?(:bookmarks)
|
||||||
|
|
||||||
class CreateBookmarks < ActiveRecord::Migration[5.1]
|
|
||||||
def change
|
|
||||||
create_table :bookmarks do |t|
|
create_table :bookmarks do |t|
|
||||||
t.references :account, null: false
|
t.references :account, null: false
|
||||||
t.references :status, null: false
|
t.references :status, null: false
|
||||||
|
@ -19,4 +20,6 @@ class CreateBookmarks < ActiveRecord::Migration[5.1]
|
||||||
|
|
||||||
add_index :bookmarks, [:account_id, :status_id], unique: true
|
add_index :bookmarks, [:account_id, :status_id], unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down; end
|
||||||
end
|
end
|
|
@ -1,10 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# This migration is a duplicate of 20180410220657 and may get ignored, see
|
# This migration is a duplicate of 20180410220657
|
||||||
# config/initializers/0_duplicate_migrations.rb
|
|
||||||
|
|
||||||
class CreateBookmarks < ActiveRecord::Migration[5.2]
|
class CreateBookmarks < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def up
|
||||||
|
return if table_exists?(:bookmarks)
|
||||||
|
|
||||||
create_table :bookmarks do |t|
|
create_table :bookmarks do |t|
|
||||||
t.references :account, null: false
|
t.references :account, null: false
|
||||||
t.references :status, null: false
|
t.references :status, null: false
|
||||||
|
@ -19,4 +20,8 @@ class CreateBookmarks < ActiveRecord::Migration[5.2]
|
||||||
|
|
||||||
add_index :bookmarks, [:account_id, :status_id], unique: true
|
add_index :bookmarks, [:account_id, :status_id], unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_table :bookmarks
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue