New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.4.0 cleans the 'schema_migrations' #317

Closed
nepalez opened this Issue Jan 5, 2015 · 28 comments

Comments

Projects
None yet
@nepalez

nepalez commented Jan 5, 2015

It seems, in v1.4.0 the cleaner cleans the 'schema_migrations' table as well.

This causes the next db migration to break, because the migration task tries to duplicate old migrations from the very beginning.

@geoffharcourt

This comment has been minimized.

Show comment
Hide comment
@geoffharcourt

geoffharcourt Jan 5, 2015

I'm seeing the same behavior in my app in Rails 4.1.

I'm seeing the same behavior in my app in Rails 4.1.

@enthrops

This comment has been minimized.

Show comment
Hide comment
@enthrops

enthrops Jan 5, 2015

Confirming on Rails 4.2

enthrops commented Jan 5, 2015

Confirming on Rails 4.2

@bdarfler

This comment has been minimized.

Show comment
Hide comment
@bdarfler

bdarfler Jan 5, 2015

Confirmed on Postgres/ActiveRecord/Rails 4.1. It seems that the logic now requires the full database.table notation to work properly. A work around would be to add except: %w[public.schema_migrations] but obviously this should be fixed. It also impacts anyone trying to prevent spatial_ref_sys from being truncated.

bdarfler commented Jan 5, 2015

Confirmed on Postgres/ActiveRecord/Rails 4.1. It seems that the logic now requires the full database.table notation to work properly. A work around would be to add except: %w[public.schema_migrations] but obviously this should be fixed. It also impacts anyone trying to prevent spatial_ref_sys from being truncated.

@uno4ki

This comment has been minimized.

Show comment
Hide comment
@uno4ki

uno4ki Jan 6, 2015

Yeah, nasty bug.
Confirmed on 4.2 with postgres, public.* is a lifesaver

uno4ki commented Jan 6, 2015

Yeah, nasty bug.
Confirmed on 4.2 with postgres, public.* is a lifesaver

@allavena

This comment has been minimized.

Show comment
Hide comment
@allavena

allavena Jan 6, 2015

Unrelated to Rails. I can confirm on a Sinatra app with ActiveRecords 4.2

allavena commented Jan 6, 2015

Unrelated to Rails. I can confirm on a Sinatra app with ActiveRecords 4.2

@raphaelcosta

This comment has been minimized.

Show comment
Hide comment
@raphaelcosta

raphaelcosta Jan 7, 2015

Same here with Rails 4.2

Same here with Rails 4.2

@felipero

This comment has been minimized.

Show comment
Hide comment

felipero commented Jan 7, 2015

+1

@lilfaf

This comment has been minimized.

Show comment
Hide comment

lilfaf commented Jan 8, 2015

👍

@jonallured

This comment has been minimized.

Show comment
Hide comment
@jonallured

jonallured Jan 8, 2015

Contributor

I recently upgraded to Rails 4.2 and mistakenly thought that had something to do with my schema_migrations table was getting truncated after cucumber runs. I eventually found this issue and I tried the work around of using the except option, but that didn't work.

I ended up downgrading to v1.3.0 for the time being, but I also cloned down the project and ran the tests. Everything is passing and there is a spec for this behavior:

https://github.com/DatabaseCleaner/database_cleaner/blob/master/spec/database_cleaner/active_record/truncation_spec.rb#L36

Any thoughts on how to get a failing test on this? I couldn't help notice that the library runs against activerecord 3.0.0, so that can't be good...

Thanks!
Jon

Contributor

jonallured commented Jan 8, 2015

I recently upgraded to Rails 4.2 and mistakenly thought that had something to do with my schema_migrations table was getting truncated after cucumber runs. I eventually found this issue and I tried the work around of using the except option, but that didn't work.

I ended up downgrading to v1.3.0 for the time being, but I also cloned down the project and ran the tests. Everything is passing and there is a spec for this behavior:

https://github.com/DatabaseCleaner/database_cleaner/blob/master/spec/database_cleaner/active_record/truncation_spec.rb#L36

Any thoughts on how to get a failing test on this? I couldn't help notice that the library runs against activerecord 3.0.0, so that can't be good...

Thanks!
Jon

@jonallured

This comment has been minimized.

Show comment
Hide comment
@jonallured

jonallured Jan 9, 2015

Contributor

I'm new to the internals of this library, so I spent some time reading through things this afternoon and something that stood out to me was the lack of outer loop testing for truncation and the schema_migrations table. What I was looking for was a test that migrates the database, truncates and then asserts about the state of the schema_migrations table, but I couldn't find a test like that. If I've missed something, please let me know!

I took a stab at adding one - both on top of v1.4.0 and off of v1.3.0 in order to ensure that the test was actually proving something. Here are the commits:

  • jonallured/database_cleaner@04c263e - passing spec off of v1.3.0
  • jonallured/database_cleaner@0a8d1c0 - failing spec off of v1.4.0

The spec isn't great, I'm shelling out to run dropdb and it's probably in the wrong place, but I think this at least illustrates the problem - I hope so, anyway! :)

Contributor

jonallured commented Jan 9, 2015

I'm new to the internals of this library, so I spent some time reading through things this afternoon and something that stood out to me was the lack of outer loop testing for truncation and the schema_migrations table. What I was looking for was a test that migrates the database, truncates and then asserts about the state of the schema_migrations table, but I couldn't find a test like that. If I've missed something, please let me know!

I took a stab at adding one - both on top of v1.4.0 and off of v1.3.0 in order to ensure that the test was actually proving something. Here are the commits:

  • jonallured/database_cleaner@04c263e - passing spec off of v1.3.0
  • jonallured/database_cleaner@0a8d1c0 - failing spec off of v1.4.0

The spec isn't great, I'm shelling out to run dropdb and it's probably in the wrong place, but I think this at least illustrates the problem - I hope so, anyway! :)

@oniofchaos

This comment has been minimized.

Show comment
Hide comment
@oniofchaos

oniofchaos Jan 14, 2015

Confirming on Rails 4.2. Had the issue with v1.4.0, downgraded to v1.3.0 and it went away.

Confirming on Rails 4.2. Had the issue with v1.4.0, downgraded to v1.3.0 and it went away.

codekitchen added a commit to instructure/inst-jobs that referenced this issue Jan 14, 2015

lock some development dependencies
database_cleaner 1.4.0 has a bug that truncates schema_migrations in
some environments DatabaseCleaner/database_cleaner#317

Change-Id: I8454f340bcb36a687db028d03d1f3776142ebef8
@odigity

This comment has been minimized.

Show comment
Hide comment
@odigity

odigity Jan 18, 2015

Same here. (Rails 4.2, PostgreSQL 9.3)

Decided to fix it by using except:

DatabaseCleaner.strategy = :truncation, {except: %w[public.schema_migrations]}

Found out the hard way that 'schema_migrations' won't work without prefixing it with 'public.', so thanks for that tip, @bdarfler.

odigity commented Jan 18, 2015

Same here. (Rails 4.2, PostgreSQL 9.3)

Decided to fix it by using except:

DatabaseCleaner.strategy = :truncation, {except: %w[public.schema_migrations]}

Found out the hard way that 'schema_migrations' won't work without prefixing it with 'public.', so thanks for that tip, @bdarfler.

@daqo

This comment has been minimized.

Show comment
Hide comment
@daqo

daqo Jan 23, 2015

Same for me. Any fix?

daqo commented Jan 23, 2015

Same for me. Any fix?

@NafaaBout

This comment has been minimized.

Show comment
Hide comment
@NafaaBout

NafaaBout Jan 24, 2015

Same here.

Same here.

@NafaaBout

This comment has been minimized.

Show comment
Hide comment
@NafaaBout

NafaaBout Jan 24, 2015

@odigity I tried your fix but it does not work.

@odigity I tried your fix but it does not work.

@NafaaBout

This comment has been minimized.

Show comment
Hide comment
@NafaaBout

NafaaBout Jan 24, 2015

I just downgrade to 1.3.0. and it works.

I just downgrade to 1.3.0. and it works.

@odigity

This comment has been minimized.

Show comment
Hide comment
@odigity

odigity Jan 24, 2015

@NafaaBout Here are the exact contents of my lib/tasks/db.rake file:

namespace :db do
  desc 'deletes all data in all tables'
  task empty: :environment do
    DatabaseCleaner.strategy = :truncation, {except: %w[public.schema_migrations]}
    DatabaseCleaner.clean
  end
end

Which runs when I execute rake db:empty.

odigity commented Jan 24, 2015

@NafaaBout Here are the exact contents of my lib/tasks/db.rake file:

namespace :db do
  desc 'deletes all data in all tables'
  task empty: :environment do
    DatabaseCleaner.strategy = :truncation, {except: %w[public.schema_migrations]}
    DatabaseCleaner.clean
  end
end

Which runs when I execute rake db:empty.

@jonallured

This comment has been minimized.

Show comment
Hide comment
@jonallured

jonallured Jan 25, 2015

Contributor

Has anyone made any progress on this one? I should have some time this week to work on it, but didn't want to duplicate efforts.

Thanks!
Jon

/cc @etagwerker @bmabey @vrinek @JonRowe

Contributor

jonallured commented Jan 25, 2015

Has anyone made any progress on this one? I should have some time this week to work on it, but didn't want to duplicate efforts.

Thanks!
Jon

/cc @etagwerker @bmabey @vrinek @JonRowe

@daqo

This comment has been minimized.

Show comment
Hide comment
@daqo

daqo Jan 25, 2015

For now, just downgrade to version 1.3.


David Qorashi

On Sun, Jan 25, 2015 at 4:36 PM, Jon Allured notifications@github.com
wrote:

Has anyone made any progress on this one? I should have some time this week to work on it, but didn't want to duplicate efforts.
Thanks!
Jon

/cc @etagwerker @bmabey @vrinek @JonRowe

Reply to this email directly or view it on GitHub:
#317 (comment)

daqo commented Jan 25, 2015

For now, just downgrade to version 1.3.


David Qorashi

On Sun, Jan 25, 2015 at 4:36 PM, Jon Allured notifications@github.com
wrote:

Has anyone made any progress on this one? I should have some time this week to work on it, but didn't want to duplicate efforts.
Thanks!
Jon

/cc @etagwerker @bmabey @vrinek @JonRowe

Reply to this email directly or view it on GitHub:
#317 (comment)

@shelling

This comment has been minimized.

Show comment
Hide comment
@shelling

shelling Jan 28, 2015

confirm on rails 4.1.9

confirm on rails 4.1.9

rafamanzo added a commit to mezuro/kalibro_processor that referenced this issue Jan 30, 2015

rafamanzo added a commit to mezuro/kalibro_configurations that referenced this issue Jan 30, 2015

rafamanzo added a commit to rafamanzo/base-rails-app that referenced this issue Jan 30, 2015

macool added a commit to GrowMoi/moi that referenced this issue Feb 9, 2015

downgrade `database_cleaner`
It's dropping the `schema_migrations` table. See DatabaseCleaner/database_cleaner#317
@etagwerker

This comment has been minimized.

Show comment
Hide comment
@etagwerker

etagwerker Feb 9, 2015

Member

While we work on a solution to this, I see two workarounds:

Either

DatabaseCleaner.strategy = :truncation, {except: %w[public.schema_migrations]}

or

Downgrade to 1.3.0

Thanks for your contributions!

Member

etagwerker commented Feb 9, 2015

While we work on a solution to this, I see two workarounds:

Either

DatabaseCleaner.strategy = :truncation, {except: %w[public.schema_migrations]}

or

Downgrade to 1.3.0

Thanks for your contributions!

@geoffharcourt

This comment has been minimized.

Show comment
Hide comment
@geoffharcourt

geoffharcourt Feb 21, 2015

@etagwerker, thanks! Any chance we can get a 1.5.0 release with the fix?

@etagwerker, thanks! Any chance we can get a 1.5.0 release with the fix?

@etagwerker

This comment has been minimized.

Show comment
Hide comment
@etagwerker

etagwerker Feb 21, 2015

Member

Could you check that it's working correctly by using master? If everything is alright I can release 1.4.1 soon.

Member

etagwerker commented Feb 21, 2015

Could you check that it's working correctly by using master? If everything is alright I can release 1.4.1 soon.

@geoffharcourt

This comment has been minimized.

Show comment
Hide comment
@geoffharcourt

geoffharcourt Feb 21, 2015

Master is able to run specs on Rails 4.2 without messing up the schema_migrations table. Thanks again.

Master is able to run specs on Rails 4.2 without messing up the schema_migrations table. Thanks again.

@daqo

This comment has been minimized.

Show comment
Hide comment
@daqo

daqo Feb 22, 2015

The fix works perfectly.

daqo commented Feb 22, 2015

The fix works perfectly.

@mehmetdavut

This comment has been minimized.

Show comment
Hide comment
@mehmetdavut

mehmetdavut Mar 7, 2015

@odigity thanks, it works 👍

@odigity thanks, it works 👍

@joshco

This comment has been minimized.

Show comment
Hide comment
@joshco

joshco Apr 13, 2015

I just ran into this too. 1.4.1 fixes it

joshco commented Apr 13, 2015

I just ran into this too. 1.4.1 fixes it

@mib32

This comment has been minimized.

Show comment
Hide comment
@mib32

mib32 Aug 4, 2015

I would like to add, that if you have something like this

DatabaseCleaner.strategy = :truncation, {:except => %w[spatial_ref_sys]}

I mean, have 1.4.1 installed, but configured the exception for some table like spatial_ref_sys then you also would lose your migrations! Just add her, like this.

DatabaseCleaner.strategy = :truncation, {:except => %w[spatial_ref_sys public.schema_migrations]}

mib32 commented Aug 4, 2015

I would like to add, that if you have something like this

DatabaseCleaner.strategy = :truncation, {:except => %w[spatial_ref_sys]}

I mean, have 1.4.1 installed, but configured the exception for some table like spatial_ref_sys then you also would lose your migrations! Just add her, like this.

DatabaseCleaner.strategy = :truncation, {:except => %w[spatial_ref_sys public.schema_migrations]}

Domenoth added a commit to EndPointCorp/solidus_multi_currency that referenced this issue Jan 29, 2016

Domenoth added a commit to EndPointCorp/solidus_multi_currency that referenced this issue Mar 4, 2016

sauloperez added a commit to coopdevs/timeoverflow that referenced this issue Sep 18, 2016

sauloperez added a commit to coopdevs/timeoverflow that referenced this issue Nov 16, 2016

enricostano added a commit to coopdevs/timeoverflow that referenced this issue Nov 18, 2016

@DatabaseCleaner DatabaseCleaner locked and limited conversation to collaborators May 15, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.