Model regions break up rake db: migrate - rails 3.2.3 postgres 9.1.3

I had a problem running my migrations in a new rails application (3.2.3). We use postrgres 9.1.3 and - pg (0.13.2) -

When I run rake db: create, then rake db: migrate, I get β†’

1.9.3-p194 (master) rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
PG::Error: ERROR:  relation "roles" does not exist
LINE 4:              WHERE a.attrelid = '"roles"'::regclass
                                    ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
          FROM pg_attribute a LEFT JOIN pg_attrdef d
            ON a.attrelid = d.adrelid AND a.attnum = d.adnum
         WHERE a.attrelid = '"roles"'::regclass
           AND a.attnum > 0 AND NOT a.attisdropped
         ORDER BY a.attnum

I get this even without certain migrations, so I do not think that this is a problem with the migrations themselves. When I look at the stack trace, I see that the areas defined in my user model are triggered - when I comment on them, migrations work without problems.

scope :team_leaders, where(role_id: Role.where(name: 'Team Leader').first.try(:id))
scope :area_leaders, where(role_id: Role.where(name: 'Area Leader').first.try(:id))
scope :nation_leaders, where(role_id: Role.where(name: 'Nation Leader').first.try(:id))
scope :employees, where(role_id: Role.where(name: 'Employee').first.try(:id))

Is this a mistake in the rails, or am I doing something wrong? I am very grateful for the help - we can remove the use of these areas in the application, but we would like to avoid this.

- , , , ?

,

+5
3

. 2 , Carl Zulauf, .

, , , , .

. :

scope :team_leaders, lambda { where(role_id: Role.where(name: 'Team Leader').first.try(:id)) }

.

. ( ), lambda .

+16

find_ find_by_foo, rake db:migrate. .

+3

I actually had the same migration issue caused by the default scope, for example:

default_scope where(deleted: false)

The error is caused by such blocks of code:

ModelName.all.each_with_index do |m, i|
...
end

This problem is resolved with unscoping:

ModelName.unscoped.each_with_index do |m, i|
...
end
0
source

All Articles