# Skip default\_scope when running migrations

**URL:** <https://www.ruby-forum.com/t/skip-default-scope-when-running-migrations/177455>\
**Category:** Rails\
**Created:** [October 17, 2009, 9:24pm UTC](https://www.ruby-forum.com/t/skip-default-scope-when-running-migrations/177455 "2009-10-17T21:24:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snow-templar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/977dab/32.png) [@snow-templar](https://www.ruby-forum.com/u/snow-templar)\
**Post date:** [October 17, 2009, 9:24pm UTC](https://www.ruby-forum.com/t/skip-default-scope-when-running-migrations/177455/1 "2009-10-17T21:24:22Z")

</div>

Hi,

I was wondering if there is a way to skip the application of a  
named\_scope to calls made in legacy migrations. I am working with some  
old migrations that include some data manipulation tasks, and my default  
scope is preventing those migrations from running. I’m trying to avoid  
editing those migration files with with\_exclusive\_scope.

Thanks,

-G

---

<div class="post-metadata">

**Author:** ![snow-templar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/977dab/32.png) [@snow-templar](https://www.ruby-forum.com/u/snow-templar)\
**Post date:** [October 17, 2009, 10:13pm UTC](https://www.ruby-forum.com/t/skip-default-scope-when-running-migrations/177455/2 "2009-10-17T22:13:50Z")

</div>

Greg Christopher wrote:

> Hi,
> 
> I was wondering if there is a way to skip the application of a  
> named\_scope to calls made in legacy migrations. I am working with some  
> old migrations that include some data manipulation tasks, and my default  
> scope is preventing those migrations from running. I’m trying to avoid  
> editing those migration files with with\_exclusive\_scope.

Generally speaking, you shouldn’t be running very old migrations – for  
existing installations, the migrations get run one at a time, and for  
new installations, you should just use rake db:schema:load . You’ve  
found out a reason for this the hard way. 🙂 What exactly are you  
trying to do?

> Thanks,
> 
> -G

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![snow-templar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/977dab/32.png) [@snow-templar](https://www.ruby-forum.com/u/snow-templar)\
**Post date:** [October 18, 2009, 12:53am UTC](https://www.ruby-forum.com/t/skip-default-scope-when-running-migrations/177455/3 "2009-10-18T00:53:21Z")

</div>

On Oct 17, 8:24 pm, Greg Christopher \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> Hi,
> 
> I was wondering if there is a way to skip the application of a  
> named\_scope to calls made in legacy migrations. I am working with some  
> old migrations that include some data manipulation tasks, and my default  
> scope is preventing those migrations from running. I’m trying to avoid  
> editing those migration files with with\_exclusive\_scope.

Using your application’s models in migrations can get you in trouble,  
and often in a way that you only notice when deploying in production  
(since in development you probably run them one at a time but in  
production you’ll run all those that were part of the release you are  
deploying. If all you need is basic activerecord CRUD type  
functionality you can do

class SomeMigration \< …

class MyModel \< ActiveRecord::Base; end

def self.up  
MyModel.create(…)  
end  
end

i.e. you basically have a class that is only used by the migration and  
won’t depend on any of the changes you may make to the application’s  
MyModel class.

Fred
