Skip to content

Commit

Permalink
Cleanup comments + bump version to 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthod committed Sep 12, 2024
1 parent bd4a426 commit d9f18f9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 95 deletions.
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
96 changes: 22 additions & 74 deletions lib/mongoid_rails_migrations/active_record_ext/migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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"]
Expand All @@ -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?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/mongoid_rails_migrations/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MongoidRailsMigrations #:nodoc:
VERSION = '1.5.0'
VERSION = '1.6.0'
end

0 comments on commit d9f18f9

Please sign in to comment.