0
를 사용하는 대신 자식의 repo의 서버에서 실행

I 업그레이드 된 슈 프레 상공 버전 3.0에서 버전 3.1로하지만고정 레일 마이그레이션 카피 스트라 노

내가 대신 마이그레이션 파일을 생성 내 로컬 개발 환경에서 망할 놈의 마이그레이션 파일에서 확인하는 것을 잊었다 대신에 서버에; 내 개발 환경에서 git로 마이그레이션을 커밋했지만 이제는 테이블이 존재할 때 마이그레이션을 실행하려고하기 때문에 배포와 관련된 모든 문제가 발생합니다.

서버에 있기 때문에 마이그레이션을 수행 할 필요가 없습니다. 서버 프로그램에 rake db:migrate:status 실행

:

up  20151015124064 Add meta title to page.spree static content 
    up  20151015124065 Add render as partial for layout for spree pages.spree static content 
    up  20151015124066 Add pages stores.spree static content 
    down 20160707102753 Create spree store credits.spree 
    down 20160707102754 Create spree store credit categories.spree 
    down 20160707102755 Create spree store credit events.spree 
    down 20160707102756 Create spree store credit types.spree 
    down 20160707102757 Add missing indexes.spree 
    down 20160707102758 Remove duplicated indexes from multi columns.spree 
    down 20160707102759 Remove user index from spree state changes.spree 
    down 20160707102760 Add position to spree payment methods.spree 
    down 20160707102761 Add taxable adjustment total to line item.spree 
    down 20160707102762 Migrate payment methods display.spree 
    down 20160707102763 Spree payment method store credits.spree 
    down 20160707102764 Rename has and belongs to associations to model names.spree 
    down 20160707102765 Spree store credit types.spree 
    down 20160707102766 Add discontinued to products and variants.spree 
    down 20160707102767 Remove shipping method id from spree orders.spree 
    down 20160707102768 Add id column to earlier habtm tables.spree 
    down 20160707102769 Add indexes.spree 
    down 20160707102770 Add missing indices on user.spree auth 
    down 20160707102771 Remove show in footer from spree pages.spree static content 

내 위치 시스템에서 그것을 보여줍니다

up  20151015124064 Add meta title to page.spree static content 
    up  20151015124065 Add render as partial for layout for spree pages.spree static content 
    up  20151015124066 Add pages stores.spree static content 
    up  20160707102753 Create spree store credits.spree 
    up  20160707102754 Create spree store credit categories.spree 
    up  20160707102755 Create spree store credit events.spree 
    up  20160707102756 Create spree store credit types.spree 
    up  20160707102757 Add missing indexes.spree 
    up  20160707102758 Remove duplicated indexes from multi columns.spree 
    up  20160707102759 Remove user index from spree state changes.spree 
    up  20160707102760 Add position to spree payment methods.spree 
    up  20160707102761 Add taxable adjustment total to line item.spree 
    up  20160707102762 Migrate payment methods display.spree 
    up  20160707102763 Spree payment method store credits.spree 
    up  20160707102764 Rename has and belongs to associations to model names.spree 
    up  20160707102765 Spree store credit types.spree 
    up  20160707102766 Add discontinued to products and variants.spree 
    up  20160707102767 Remove shipping method id from spree orders.spree 
    up  20160707102768 Add id column to earlier habtm tables.spree 
    up  20160707102769 Add indexes.spree 
    up  20160707102770 Add missing indices on user.spree auth 
    up  20160707102771 Remove show in footer from spree pages.spree static content 

내가 up하지 down해야 서버의 마이그레이션 상태를 추정한다.

어떻게 접근해야할까요?

답변

0

당신은 당신이 당신의 SQL 콘솔 및 다시 실행 카피 스트라 노 배포 또는 에서 해당 테이블을 삭제할 수 있습니다 잃는 데이터가없는 경우 할 수 있습니다

rake db:migrate:up VERSION=20151015124064 

하여 서버에서 수동으로 up 마이그레이션 파일 버전 rake db:migrate:status

주의의 결과의 두 번째 열입니다 : 당신이 두 경우 모두에 해당 테이블을 삭제해야 기억

+0

감사합니다. Vishal, 데이터가 있습니다. 불행히도 마이그레이션을 시도합니다. 테이블이 이미 존재하므로 실패합니다. 테이블을 삭제해도 문제는 없지만 되돌릴 수없는 마이그레이션이 있습니다. –

+0

비가역 마이그레이션은 실행 테이블 또는 다른 테이블의 일부이며 가능한 경우 되돌릴 수없는 마이그레이션 파일을 나열 할 수 있습니다. –

+0

그리고 마이그레이션이 성공하지 못했기 때문에 되돌릴 수없는 모든 이전에 대해 ** 변한 ** 대신 ** 변신 ** 및 ** 변신 ** ** 메서드를 추가 할 수 있으므로 마이그레이션 및 롤백을위한 다른 논리를 작성할 수 있습니다. 그리고 SQL을 덤프하여 데이터를 보관할 수 있습니다. –

0

데이터를 잃어 버리고 다시 시도하기를 원하지 않으면 시도 할 수있는 또 다른 방법이 있습니다.

마이그레이션 버전이 schema_migrations 테이블의 레코드로 존재하는지 여부에 따라 마이그레이션이 up 또는 down으로 표시됩니다.

class SchemaMigration < ActiveRecord::Base 
    self.primary_key = :version 
    attr_accessible :version 

    # you can call the method below via console or even call 
    # or execute the commands directly from the rails console 
    def self.fix_migrations 
    # basically a list of all migrations that you run on server but are not marked as up 
    down_migrations = %w(20160707102753 20160707102754 ... 20160707102771) 
    down_migrations.each do |m| 
     # this will add an entry in the schema_migrations datatable 
     # on server so rake db:migrate won't try to run these again 
     SchemaMigration.create(version: m) 
    end   
    end 

end 

그리고 레일 콘솔을 통해, 당신은 실행 : SchemaMigration.fix_migrations 그래서, 당신이 당신의 문제를 해결할 수있는 한 가지 방법은 다음을 포함하는 파일 app/models/schema_migration.rb를 추가하는 것입니다.

특정 이전을 다시 실행해야하거나 실수로 이전에 실행 된 적이없는 이전 버전을 추가 한 경우 SchemaMigration.find_by_version('xxxx').delete을 사용하여 항상 schema_migrations에서 항목을 제거 할 수 있습니다. 그러면 rake db:migrate에서 해당 마이그레이션을 다시 실행할 수 있습니다.