Sha256: 2b6ded9f7410c837530fa9664ab5287a57cd937d692626f403edd6c82cd54910

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

module DoorkeeperSequel
  module MigrationActions
    extend ::ActiveSupport::Concern

    protected

    def create_migration(template_name)
      copy_file template_name, migration_filename_for(template_name)
    end

    def migration_template
      File.expand_path('../templates/migration.rb', __FILE__)
    end

    private

    def migration_filename_for(template_name)
      "db/migrate/#{new_migration_number}_#{template_name}"
    end

    def new_migration_number
      current_number = current_migration_number('db/migrate')

      # possible numeric migration
      if current_number && current_number.start_with?('0')
        # generate the same name as used by the developer
        "%.#{current_number.length}d" % (current_number.to_i + 1)
      else
        Time.now.utc.strftime('%Y%m%d%H%M%S')
      end
    end

    def current_migration_number(dirname)
      migration_lookup_at(dirname).collect do |file|
        File.basename(file).split('_').first
      end.max
    end

    def migration_lookup_at(dirname)
      Dir.glob("#{dirname}/[0-9]*_*.rb")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
doorkeeper-sequel-2.0.0 lib/doorkeeper-sequel/generators/concerns/migration_actions.rb
doorkeeper-sequel-1.5.0 lib/doorkeeper-sequel/generators/concerns/migration_actions.rb
doorkeeper-sequel-1.4.0 lib/doorkeeper-sequel/generators/concerns/migration_actions.rb
doorkeeper-sequel-1.3.1 lib/doorkeeper-sequel/generators/concerns/migration_actions.rb
doorkeeper-sequel-1.3.0 lib/doorkeeper-sequel/generators/concerns/migration_actions.rb