39takagikouta / WaRise

1 stars 0 forks source link

誤って消してしまったheroku postgresアドオンにデータベースをheroku run rake db:migrateできない #50

Open 39takagikouta opened 12 months ago

39takagikouta commented 12 months ago

Running rake db:migrate on ⬢ warise... up, run.1864 (Eco) I, [2023-10-29T16:42:28.146328 #2] INFO -- : Migrating to DeviseCreateUsers (20231011154133) == 20231011154133 DeviseCreateUsers: migrating ================================ -- create_table(:users) -> 0.0079s -- add_index(:users, :email, {:unique=>true}) -> 0.0032s -- add_index(:users, :reset_password_token, {:unique=>true}) -> 0.0028s == 20231011154133 DeviseCreateUsers: migrated (0.0140s) =======================

I, [2023-10-29T16:42:28.168179 #2] INFO -- : Migrating to ChangeIsDisplayedDefaultInUsers (20231011161056) == 20231011161056 ChangeIsDisplayedDefaultInUsers: migrating ================== -- change_column_default(:users, :is_displayed, {:from=>nil, :to=>true}) -> 0.0049s == 20231011161056 ChangeIsDisplayedDefaultInUsers: migrated (0.0049s) =========

I, [2023-10-29T16:42:28.175616 #2] INFO -- : Migrating to CreateAlarms (20231012081009) == 20231012081009 CreateAlarms: migrating ===================================== -- create_table(:alarms) -> 0.0059s == 20231012081009 CreateAlarms: migrated (0.0059s) ============================

I, [2023-10-29T16:42:28.184495 #2] INFO -- : Migrating to CreateViewVideos (20231012125819) == 20231012125819 CreateViewVideos: migrating ================================= -- create_table(:view_videos) -> 0.0081s == 20231012125819 CreateViewVideos: migrated (0.0081s) ========================

I, [2023-10-29T16:42:28.195955 #2] INFO -- : Migrating to AddNameToUsers (20231014135448) == 20231014135448 AddNameToUsers: migrating =================================== -- add_column(:users, :name, :string) -> 0.0016s == 20231014135448 AddNameToUsers: migrated (0.0016s) ==========================

I, [2023-10-29T16:42:28.200449 #2] INFO -- : Migrating to ChangeNameToNotNullInUsers (20231014135702) == 20231014135702 ChangeNameToNotNullInUsers: migrating ======================= -- change_column(:users, :name, :string, {:null=>false}) -> 0.0020s == 20231014135702 ChangeNameToNotNullInUsers: migrated (0.0020s) ==============

I, [2023-10-29T16:42:28.205694 #2] INFO -- : Migrating to CreateComedyTags (20231015072839) == 20231015072839 CreateComedyTags: migrating ================================= -- create_table(:comedy_tags) -> 0.0078s -- add_index(:comedy_tags, :name, {:unique=>true}) -> 0.0026s == 20231015072839 CreateComedyTags: migrated (0.0105s) ========================

I, [2023-10-29T16:42:28.219147 #2] INFO -- : Migrating to CreateUserComedyTags (20231015073416) == 20231015073416 CreateUserComedyTags: migrating ============================= -- create_table(:user_comedy_tags) -> 0.0087s -- add_foreign_key(:user_comedy_tags, :users) -> 0.0041s -- add_foreign_key(:user_comedy_tags, :comedy_tags) -> 0.0026s -- add_index(:user_comedy_tags, [:user_id, :comedy_tag_id], {:unique=>true}) -> 0.0028s == 20231015073416 CreateUserComedyTags: migrated (0.0184s) ====================

I, [2023-10-29T16:42:28.240949 #2] INFO -- : Migrating to ModifyUserTables (20231015114403) == 20231015114403 ModifyUserTables: migrating ================================= -- change_column_null(:users, :is_displayed, false) -> 0.0016s == 20231015114403 ModifyUserTables: migrated (0.0016s) ========================

I, [2023-10-29T16:42:28.245471 #2] INFO -- : Migrating to CreateBootcamps (20231015115037) == 20231015115037 CreateBootcamps: migrating ================================== -- create_table(:bootcamps) -> 0.0065s == 20231015115037 CreateBootcamps: migrated (0.0065s) =========================

I, [2023-10-29T16:42:28.254731 #2] INFO -- : Migrating to ModifyAlarmsTable (20231015115156) == 20231015115156 ModifyAlarmsTable: migrating ================================ -- remove_column(:alarms, :user_id) -> 0.0016s -- add_reference(:alarms, :user, {:foreign_key=>true}) -> 0.0048s -- remove_column(:alarms, :bootcamp_id) -> 0.0009s -- add_reference(:alarms, :bootcamp, {:foreign_key=>true}) -> 0.0047s == 20231015115156 ModifyAlarmsTable: migrated (0.0122s) =======================

I, [2023-10-29T16:42:28.269860 #2] INFO -- : Migrating to ModifyViewVideosTable (20231015115554) == 20231015115554 ModifyViewVideosTable: migrating ============================ -- remove_column(:view_videos, :user_id) -> 0.0014s -- add_reference(:view_videos, :user, {:foreign_key=>true}) -> 0.0055s -- add_index(:view_videos, [:user_id, :video_url], {:unique=>true}) -> 0.0027s == 20231015115554 ModifyViewVideosTable: migrated (0.0097s) ===================

I, [2023-10-29T16:42:28.282144 #2] INFO -- : Migrating to ModifyUserComedyTagsTable (20231015115904) == 20231015115904 ModifyUserComedyTagsTable: migrating ======================== -- remove_foreign_key(:user_comedy_tags, :users) -> 0.0053s -- remove_foreign_key(:user_comedy_tags, :comedy_tags) -> 0.0040s -- remove_column(:user_comedy_tags, :user_id) -> 0.0009s -- add_reference(:user_comedy_tags, :user, {:foreign_key=>true}) -> 0.0051s -- remove_column(:user_comedy_tags, :comedy_tag_id) -> 0.0008s -- add_reference(:user_comedy_tags, :comedy_tag, {:foreign_key=>true}) -> 0.0046s -- add_index(:user_comedy_tags, [:user_id, :comedy_tag_id], {:unique=>true}) -> 0.0044s == 20231015115904 ModifyUserComedyTagsTable: migrated (0.0254s) ===============

I, [2023-10-29T16:42:28.317065 #2] INFO -- : Migrating to CreateKeywords (20231015130720) == 20231015130720 CreateKeywords: migrating =================================== -- create_table(:keywords) -> 0.0093s -- add_index(:keywords, [:user_id, :name], {:unique=>true}) -> 0.0025s == 20231015130720 CreateKeywords: migrated (0.0119s) ==========================

I, [2023-10-29T16:42:28.331830 #2] INFO -- : Migrating to ChangeDefaultValuesForVideoLengthInUsers (20231018182922) == 20231018182922 ChangeDefaultValuesForVideoLengthInUsers: migrating ========= -- change_column_default(:users, :min_video_length, 0) -> 0.0087s -- change_column_default(:users, :max_video_length, 3600) -> 0.0098s == 20231018182922 ChangeDefaultValuesForVideoLengthInUsers: migrated (0.0185s)

I, [2023-10-29T16:42:28.353605 #2] INFO -- : Migrating to RenameViewVideosToViewedVideos (20231023123047) == 20231023123047 RenameViewVideosToViewedVideos: migrating =================== -- rename_table(:view_videos, :viewed_videos) -> 0.0110s == 20231023123047 RenameViewVideosToViewedVideos: migrated (0.0111s) ==========

I, [2023-10-29T16:42:28.367401 #2] INFO -- : Migrating to RenameVideoUrlToVideoIdInViewedVideos (20231024150402) == 20231024150402 RenameVideoUrlToVideoIdInViewedVideos: migrating ============ -- rename_column(:viewed_videos, :video_url, :video_id) -> 0.0066s == 20231024150402 RenameVideoUrlToVideoIdInViewedVideos: migrated (0.0067s) ===

I, [2023-10-29T16:42:28.376539 #2] INFO -- : Migrating to RemoveVideoLengthFromUsers (20231024191021) == 20231024191021 RemoveVideoLengthFromUsers: migrating ======================= -- remove_column(:users, :min_video_length, :integer) -> 0.0015s -- remove_column(:users, :max_video_length, :integer) -> 0.0009s == 20231024191021 RemoveVideoLengthFromUsers: migrated (0.0025s) ==============

I, [2023-10-29T16:42:28.381449 #2] INFO -- : Migrating to AddVideoLengthToUsers (20231024193201) == 20231024193201 AddVideoLengthToUsers: migrating ============================ -- add_column(:users, :video_length, :integer, {:default=>0}) -> 0.0023s == 20231024193201 AddVideoLengthToUsers: migrated (0.0023s) ===================

I, [2023-10-29T16:42:28.386309 #2] INFO -- : Migrating to ChangeDefaultOfIsAutomaticallyPostedInUsers (20231025183317) == 20231025183317 ChangeDefaultOfIsAutomaticallyPostedInUsers: migrating ====== -- change_column_default(:users, :is_automatically_posted, true) -> 0.0035s == 20231025183317 ChangeDefaultOfIsAutomaticallyPostedInUsers: migrated (0.0036s)

I, [2023-10-29T16:42:28.392539 #2] INFO -- : Migrating to ChangeDefaultOfIsAutomaticallyPostedInUsersAgain (20231025183550) == 20231025183550 ChangeDefaultOfIsAutomaticallyPostedInUsersAgain: migrating = -- change_column_default(:users, :is_automatically_posted, false) -> 0.0033s == 20231025183550 ChangeDefaultOfIsAutomaticallyPostedInUsersAgain: migrated (0.0034s)

I, [2023-10-29T16:42:28.398635 #2] INFO -- : Migrating to AddBoardIdToViewedVideosTable (20231026105413) == 20231026105413 AddBoardIdToViewedVideosTable: migrating ==================== -- add_reference(:viewed_videos, :alarm, {:foreign_key=>true}) -> 0.0056s -- remove_index(:viewed_videos, {:column=>[:user_id, :video_id], :unique=>true}) -> 0.0044s -- add_index(:viewed_videos, [:user_id, :alarm_id, :video_id], {:unique=>true}) -> 0.0029s == 20231026105413 AddBoardIdToViewedVideosTable: migrated (0.0130s) ===========

I, [2023-10-29T16:42:28.417458 #2] INFO -- : Migrating to AddIndexToViewedVideos (20231026111318) == 20231026111318 AddIndexToViewedVideos: migrating =========================== -- add_index(:viewed_videos, [:user_id, :video_id], {:unique=>true}) -> 0.0032s == 20231026111318 AddIndexToViewedVideos: migrated (0.0033s) ==================

I, [2023-10-29T16:42:28.423943 #2] INFO -- : Migrating to CreateLikes (20231026143650) == 20231026143650 CreateLikes: migrating ====================================== -- create_table(:likes) -> 0.0156s == 20231026143650 CreateLikes: migrated (0.0157s) =============================

I, [2023-10-29T16:42:28.442634 #2] INFO -- : Migrating to AddColumnToUsers (20231028165800) == 20231028165800 AddColumnToUsers: migrating ================================= -- remove_column(:users, :provider, :string) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedColumn: ERROR: column "provider" of relation "users" does not exist /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in exec' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:inblock (2 levels) in execute' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/share_lock.rb:187:in yield_shares' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/dependencies/interlock.rb:41:inpermit_concurrent_loads' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in block in execute' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inhandle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in block in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:inhandle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:752:inblock in log' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/notifications/instrumenter.rb:24:in instrument' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:743:inlog' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:46:in execute' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:671:inremove_column' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:965:in block in method_missing' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:935:inblock in say_with_time' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:935:in say_with_time' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:954:inmethod_missing' /app/db/migrate/20231028165800_add_column_to_users.rb:3:in up' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:908:inpublic_send' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:908:in exec_migration' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:889:inblock (2 levels) in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:888:in block in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:inwith_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:887:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1095:inmigrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1409:in block in execute_migration_in_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:inblock in within_new_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in handle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inblock in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in handle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:insynchronize' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in within_new_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:316:intransaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:209:in transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1460:inddl_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1408:in execute_migration_in_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1382:ineach' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1382:in migrate_without_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1331:inblock in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1481:in block in with_advisory_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:inwith_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1496:in with_advisory_lock_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1477:inwith_advisory_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1331:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1166:inup' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1141:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/tasks/database_tasks.rb:262:inmigrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/railties/databases.rake:92:in block (2 levels) in <main>' /app/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/exe/rake:27:in<top (required)>' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:58:in load' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:58:inkernel_load' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:23:in run' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:486:inexec' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:ininvoke_command' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor.rb:392:in dispatch' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:31:indispatch' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/base.rb:485:in start' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:25:instart' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/exe/bundle:48:in block in <top (required)>' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/friendly_errors.rb:120:inwith_friendly_errors' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/exe/bundle:36:in <top (required)>' /app/bin/bundle:113:inload' /app/bin/bundle:113:in `

'

Caused by: ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "provider" of relation "users" does not exist /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in exec' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:inblock (2 levels) in execute' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/share_lock.rb:187:in yield_shares' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/dependencies/interlock.rb:41:inpermit_concurrent_loads' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in block in execute' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inhandle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in block in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:inhandle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:752:inblock in log' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/notifications/instrumenter.rb:24:in instrument' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:743:inlog' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:46:in execute' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:671:inremove_column' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:965:in block in method_missing' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:935:inblock in say_with_time' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:935:in say_with_time' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:954:inmethod_missing' /app/db/migrate/20231028165800_add_column_to_users.rb:3:in up' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:908:inpublic_send' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:908:in exec_migration' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:889:inblock (2 levels) in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:888:in block in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:inwith_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:887:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1095:inmigrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1409:in block in execute_migration_in_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:inblock in within_new_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in handle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inblock in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in handle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:insynchronize' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in within_new_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:316:intransaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:209:in transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1460:inddl_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1408:in execute_migration_in_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1382:ineach' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1382:in migrate_without_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1331:inblock in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1481:in block in with_advisory_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:inwith_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1496:in with_advisory_lock_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1477:inwith_advisory_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1331:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1166:inup' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1141:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/tasks/database_tasks.rb:262:inmigrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/railties/databases.rake:92:in block (2 levels) in <main>' /app/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/exe/rake:27:in<top (required)>' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:58:in load' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:58:inkernel_load' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:23:in run' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:486:inexec' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:ininvoke_command' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor.rb:392:in dispatch' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:31:indispatch' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/base.rb:485:in start' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:25:instart' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/exe/bundle:48:in block in <top (required)>' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/friendly_errors.rb:120:inwith_friendly_errors' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/exe/bundle:36:in <top (required)>' /app/bin/bundle:113:inload' /app/bin/bundle:113:in `

'

Caused by: PG::UndefinedColumn: ERROR: column "provider" of relation "users" does not exist /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in exec' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:inblock (2 levels) in execute' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/share_lock.rb:187:in yield_shares' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/dependencies/interlock.rb:41:inpermit_concurrent_loads' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in block in execute' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inhandle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in block in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:inhandle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:752:inblock in log' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/notifications/instrumenter.rb:24:in instrument' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract_adapter.rb:743:inlog' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:46:in execute' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:671:inremove_column' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:965:in block in method_missing' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:935:inblock in say_with_time' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:935:in say_with_time' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:954:inmethod_missing' /app/db/migrate/20231028165800_add_column_to_users.rb:3:in up' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:908:inpublic_send' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:908:in exec_migration' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:889:inblock (2 levels) in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:888:in block in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:inwith_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:887:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1095:inmigrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1409:in block in execute_migration_in_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:inblock in within_new_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in handle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inblock in synchronize' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in handle_interrupt' /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:insynchronize' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in within_new_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/database_statements.rb:316:intransaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/transactions.rb:209:in transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1460:inddl_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1408:in execute_migration_in_transaction' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1382:ineach' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1382:in migrate_without_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1331:inblock in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1481:in block in with_advisory_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:inwith_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1496:in with_advisory_lock_connection' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1477:inwith_advisory_lock' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1331:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1166:inup' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/migration.rb:1141:in migrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/tasks/database_tasks.rb:262:inmigrate' /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/railties/databases.rake:92:in block (2 levels) in <main>' /app/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/exe/rake:27:in<top (required)>' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:58:in load' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:58:inkernel_load' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli/exec.rb:23:in run' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:486:inexec' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:ininvoke_command' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor.rb:392:in dispatch' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:31:indispatch' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/vendor/thor/lib/thor/base.rb:485:in start' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/cli.rb:25:instart' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/exe/bundle:48:in block in <top (required)>' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/lib/bundler/friendly_errors.rb:120:inwith_friendly_errors' /app/vendor/bundle/ruby/3.1.0/gems/bundler-2.3.25/exe/bundle:36:in <top (required)>' /app/bin/bundle:113:inload' /app/bin/bundle:113:in `

' Tasks: TOP => db:migrate (See full trace by running task with --trace)

- どの処理までうまく動いているのか
どのようなことがあったか具体的に説明させていただきます。
・誤ってmainブランチでusersテーブルにproviderカラムとuidカラムを追加する作業をし、それに気づかないままgithubのmainブランチに作業をプッシュしてしまった。
・プッシュ前に一度しかコミットをしていなかったため、そのコミット前の状態にコードを戻した上で再びそれをmainにプッシュすれば誤ったプッシュが帳消しになるのではと思い、git revert HEADをしてコミット前の状態にコードを戻した上で再度mainにプッシュを行なった。
・しかし、schema.rbがproviderカラムとuidカラムを追加する前の状態に戻り、それを追加したマイグレーションファイルは消えたにも関わらず、データベースの変更は取り消されていないし、マイグレーションレコードは残っているため、何もマイグレーションできない状態になった。これを解決するため、以下の手順を踏んだ
 ・rails dbconsoleでDELETE FROM schema_migrations WHERE version = '20231028143119';をし、マイグレーションレコードを手動で削除
・rails db:rollbackでマイグレーションの状態を元に戻した
・データベースにはまだ以前のカラムが残っていたので、解消のため20231028165800_add_column_to_users.rb(下記参照)をマイグレーションした後、もう一度providerとuidを別のマイグレーションファイルでusersテーブルに追加
・herokuにデプロイしていたのだが、heroku postgresアドオンを誤って消してしまった
・再度取得し、heroku run rake db:migrateしようとしたが、前述の処理をしたせいで、herokuからすると、usersテーブルにまだproviderカラムとuidカラムがないのに、下記のマイグレーションファイルが両カラムをremoveしようとしているため上記のエラーが表示されているのだと思います。

- 該当のソースコード
```20231028165800_add_column_to_users.rb
class AddColumnToUsers < ActiveRecord::Migration[7.0]
  def up
    remove_column :users, :provider, :string
    remove_column :users, :uid, :string
  end

  def down
    add_column :users, :provider, :string
    add_column :users, :uid, :string
  end
end
  • エラーから考えられる原因 前述の処理をしたせいで、herokuからすると、usersテーブルにまだproviderカラムとuidカラムがないのに、下記のマイグレーションファイルが両カラムをremoveしようとしているため上記のエラーが表示されているのだと思います。

  • 試したこと すいません。手動で巻き戻すことも考えたのですが、あまりにも複雑な状況になってしまっているので、下手に何かをしないほうが良いと判断し、まだ何も行っていません。

長文失礼いたしました。ご対応よろしくお願いいたします。

39takagikouta commented 12 months ago

追記失礼します 特に残しておきたいデータもないので、rails db:dropしたのちに、マイグレーションファイルを全て削除することで、データベースを一から作り直すのが1番手っ取り早いかなと思ったのですが、どうでしょうか

Tsuchiya2 commented 12 months ago

PG::UndefinedColumn: ERROR: column "provider" of relation "users" does not exist

↑が関係しているログかと思われます。特に貴重なデータが入っているわけではないのなら、DBを破棄→作成→マイグレーションの手順で良いかと思います(ローカルで正しく挙動するかを確認した上で)

39takagikouta commented 12 months ago

土屋講師、ご対応ありがとうございます! ご提示いただいた方法で解決することができました!