Browse Source

Fix interactive delays in database migrations with no TTY (#12969)

Fix #12587
Eugen Rochko 1 month ago
parent
commit
4363d06986
No account linked to committer's email address

+ 15
- 13
db/migrate/20170918125918_ids_to_bigints.rb View File

@@ -70,20 +70,22 @@ class IdsToBigints < ActiveRecord::Migration[5.1]
70 70
     included_columns << [:deprecated_preview_cards, :id] if table_exists?(:deprecated_preview_cards)
71 71
 
72 72
     # Print out a warning that this will probably take a while.
73
-    say ''
74
-    say 'WARNING: This migration may take a *long* time for large instances'
75
-    say 'It will *not* lock tables for any significant time, but it may run'
76
-    say 'for a very long time. We will pause for 10 seconds to allow you to'
77
-    say 'interrupt this migration if you are not ready.'
78
-    say ''
79
-    say 'This migration has some sections that can be safely interrupted'
80
-    say 'and restarted later, and will tell you when those are occurring.'
81
-    say ''
82
-    say 'For more information, see https://github.com/tootsuite/mastodon/pull/5088'
73
+    if $stdout.isatty
74
+      say ''
75
+      say 'WARNING: This migration may take a *long* time for large instances'
76
+      say 'It will *not* lock tables for any significant time, but it may run'
77
+      say 'for a very long time. We will pause for 10 seconds to allow you to'
78
+      say 'interrupt this migration if you are not ready.'
79
+      say ''
80
+      say 'This migration has some sections that can be safely interrupted'
81
+      say 'and restarted later, and will tell you when those are occurring.'
82
+      say ''
83
+      say 'For more information, see https://github.com/tootsuite/mastodon/pull/5088'
83 84
 
84
-    10.downto(1) do |i|
85
-      say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
86
-      sleep 1
85
+      10.downto(1) do |i|
86
+        say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
87
+        sleep 1
88
+      end
87 89
     end
88 90
 
89 91
     tables = included_columns.map(&:first).uniq

+ 15
- 13
db/migrate/20180528141303_fix_accounts_unique_index.rb View File

@@ -20,19 +20,21 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2]
20 20
   disable_ddl_transaction!
21 21
 
22 22
   def up
23
-    say ''
24
-    say 'WARNING: This migration may take a *long* time for large instances'
25
-    say 'It will *not* lock tables for any significant time, but it may run'
26
-    say 'for a very long time. We will pause for 10 seconds to allow you to'
27
-    say 'interrupt this migration if you are not ready.'
28
-    say ''
29
-    say 'This migration will irreversibly delete user accounts with duplicate'
30
-    say 'usernames. You may use the `rake mastodon:maintenance:find_duplicate_usernames`'
31
-    say 'task to manually deal with such accounts before running this migration.'
32
-
33
-    10.downto(1) do |i|
34
-      say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
35
-      sleep 1
23
+    if $stdout.isatty
24
+      say ''
25
+      say 'WARNING: This migration may take a *long* time for large instances'
26
+      say 'It will *not* lock tables for any significant time, but it may run'
27
+      say 'for a very long time. We will pause for 10 seconds to allow you to'
28
+      say 'interrupt this migration if you are not ready.'
29
+      say ''
30
+      say 'This migration will irreversibly delete user accounts with duplicate'
31
+      say 'usernames. You may use the `rake mastodon:maintenance:find_duplicate_usernames`'
32
+      say 'task to manually deal with such accounts before running this migration.'
33
+
34
+      10.downto(1) do |i|
35
+        say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
36
+        sleep 1
37
+      end
36 38
     end
37 39
 
38 40
     duplicates = Account.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM accounts GROUP BY lower(username), lower(domain) HAVING count(*) > 1').to_hash

+ 12
- 10
db/migrate/20181024224956_migrate_account_conversations.rb View File

@@ -62,16 +62,18 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
62 62
   end
63 63
 
64 64
   def up
65
-    say ''
66
-    say 'WARNING: This migration may take a *long* time for large instances'
67
-    say 'It will *not* lock tables for any significant time, but it may run'
68
-    say 'for a very long time. We will pause for 10 seconds to allow you to'
69
-    say 'interrupt this migration if you are not ready.'
70
-    say ''
71
-
72
-    10.downto(1) do |i|
73
-      say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
74
-      sleep 1
65
+    if $stdout.isatty
66
+      say ''
67
+      say 'WARNING: This migration may take a *long* time for large instances'
68
+      say 'It will *not* lock tables for any significant time, but it may run'
69
+      say 'for a very long time. We will pause for 10 seconds to allow you to'
70
+      say 'interrupt this migration if you are not ready.'
71
+      say ''
72
+
73
+      10.downto(1) do |i|
74
+        say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
75
+        sleep 1
76
+      end
75 77
     end
76 78
 
77 79
     migrated  = 0

Loading…
Cancel
Save