diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5e19b52..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: ruby -dist: bionic -cache: bundler -services: mongodb -rvm: - - 2.5.7 - - 2.6.5 - - 2.7.0 - - jruby-9.2.14.0 -gemfile: - - gemfiles/rails-5.0-mongoid-6.x - - gemfiles/rails-5.2-mongoid-7.x - - gemfiles/rails-6.0-mongoid-7.x -matrix: - include: - - rvm: 2.4.9 - gemfile: gemfiles/rails-4.2-mongoid-5.x - - rvm: 3.0.0 - gemfile: gemfiles/rails-edge diff --git a/README.md b/README.md index 6c0b65c..023e845 100644 --- a/README.md +++ b/README.md @@ -100,13 +100,18 @@ Global migrations can still be created with the `--no-shards` option. ## Unreleased +[Compare master with 1.6.0](https://github.com/adacosta/mongoid_rails_migrations/compare/v1.6.0...master) + +## 1.6.0 +_12/09/2024_ * Remove unnecessary purge, setup, reset, etc. rake tasks because they are already defined by Mongoid (#60) * Minor tests improvements * Rejects Mongoid 9.0 for the moment because it broke client override isolation: https://jira.mongodb.org/browse/MONGOID-5815 +* Setup Github Actions to replace Travis CI (because It could not be fixed without the maintainer, see #55) +* Remove some legacy comments and unreachable code ## 1.5.0 _26/03/2021_ -[Compare master with 1.5.0](https://github.com/adacosta/mongoid_rails_migrations/compare/v1.5.0...master) * Add support of multi databases * Shards migrations can now be stored in a `shards` subfolder inside the migration folder * All Rake tasks now support a custom client with the `MONGOID_CLIENT_NAME` environment variable diff --git a/lib/mongoid_rails_migrations/active_record_ext/migrations.rb b/lib/mongoid_rails_migrations/active_record_ext/migrations.rb index 2eb4eab..61ff99d 100644 --- a/lib/mongoid_rails_migrations/active_record_ext/migrations.rb +++ b/lib/mongoid_rails_migrations/active_record_ext/migrations.rb @@ -151,7 +151,6 @@ def suppress_messages end def connection - # ActiveRecord::Base.connection if ENV['MONGOID_CLIENT_NAME'] Mongoid.client(ENV['MONGOID_CLIENT_NAME']) else @@ -164,22 +163,20 @@ def connection # MigrationProxy is used to defer loading of the actual migration classes # until they are needed class MigrationProxy - attr_accessor :name, :version, :filename, :sharded delegate :migrate, :announce, :write, :to=>:migration private - def migration - @migration ||= load_migration - end - - def load_migration - require(File.expand_path(filename)) - name.constantize - end + def migration + @migration ||= load_migration + end + def load_migration + require(File.expand_path(filename)) + name.constantize + end end class Migrator#:nodoc: @@ -234,35 +231,16 @@ def migrations_path @migrations_path ||= ['db/migrate'] end - # def schema_migrations_table_name - # # Base.table_name_prefix + 'schema_migrations' + Base.table_name_suffix - # 'data_migrations' - # end - def get_all_versions - # table = Arel::Table.new(schema_migrations_table_name) - # Base.connection.select_values(table.project(table['version']).to_sql).map(&:to_i).sort with_mongoid_client(ENV['MONGOID_CLIENT_NAME']) do DataMigration.all.map { |datamigration| datamigration.version.to_i }.sort end end def current_version - # sm_table = schema_migrations_table_name - # if Base.connection.table_exists?(sm_table) - # get_all_versions.max || 0 - # else - # 0 - # end get_all_versions.max || 0 end - def proper_table_name(name) - # Use the Active Record objects own table_name, or pre/suffix from ActiveRecord::Base if name is a symbol/string - # name.table_name rescue "#{ActiveRecord::Base.table_name_prefix}#{name}#{ActiveRecord::Base.table_name_suffix}" - name - end - def with_mongoid_client(mongoid_client_name, &block) previous_mongoid_client_name = Mongoid::Threaded.client_override Mongoid.override_client(mongoid_client_name) @@ -286,8 +264,6 @@ def move(direction, migrations_path, steps) end def initialize(direction, migrations_path, target_version = nil) - # raise StandardError.new("This database does not yet support migrations") unless Base.connection.supports_migrations? - # Base.connection.initialize_schema_migrations_table @direction, @migrations_path, @target_version = direction, migrations_path, target_version @mongoid_client_name = ENV["MONGOID_CLIENT_NAME"] @@ -304,7 +280,6 @@ def current_migration migrations.detect { |m| m.version == current_version } end - def run target = migrations.detect { |m| m.version == @target_version } raise UnknownMigrationVersionError.new(@target_version) if target.nil? @@ -332,15 +307,6 @@ def migrate next end - # begin - # ddl_transaction do - # migration.migrate(@direction) - # record_version_state_after_migrating(migration.version) - # end - # rescue => e - # canceled_msg = Base.connection.supports_ddl_transactions? ? "this and " : "" - # raise StandardError, "An error has occurred, #{canceled_msg}all later migrations canceled:\n\n#{e}", e.backtrace - # end begin migration.migrate(@direction) with_mongoid_client(@mongoid_client_name) do @@ -436,42 +402,24 @@ def migrated end private - def record_version_state_after_migrating(version) - # table = Arel::Table.new(self.class.schema_migrations_table_name) - - @migrated_versions ||= [] - # if down? - # @migrated_versions.delete(version) - # table.where(table["version"].eq(version.to_s)).delete - # else - # @migrated_versions.push(version).sort! - # table.insert table["version"] => version.to_s - # end - if down? - @migrated_versions.delete(version) - DataMigration.where(:version => version.to_s).destroy_all - else - @migrated_versions.push(version).sort! - DataMigration.find_or_create_by(:version => version.to_s) - end - end - def up? - @direction == :up + def record_version_state_after_migrating(version) + @migrated_versions ||= [] + if down? + @migrated_versions.delete(version) + DataMigration.where(:version => version.to_s).destroy_all + else + @migrated_versions.push(version).sort! + DataMigration.find_or_create_by(:version => version.to_s) end + end - def down? - @direction == :down - end + def up? + @direction == :up + end - # Wrap the migration in a transaction only if supported by the adapter. - def ddl_transaction(&block) - # if Base.connection.supports_ddl_transactions? - # Base.transaction { block.call } - # else - # block.call - # end - block.call - end + def down? + @direction == :down + end end end diff --git a/lib/mongoid_rails_migrations/version.rb b/lib/mongoid_rails_migrations/version.rb index b3bccb6..b04d3b8 100644 --- a/lib/mongoid_rails_migrations/version.rb +++ b/lib/mongoid_rails_migrations/version.rb @@ -1,3 +1,3 @@ module MongoidRailsMigrations #:nodoc: - VERSION = '1.5.0' + VERSION = '1.6.0' end