@@ -4,7 +4,7 @@ module SafePgMigrations
4
4
module StatementInsurer
5
5
PG_11_VERSION_NUM = 110_000
6
6
7
- %i[ change_column_null change_column create_table ] . each do |method |
7
+ %i[ change_column_null change_column ] . each do |method |
8
8
define_method method do |*args , &block |
9
9
with_setting ( :statement_timeout , SafePgMigrations . config . pg_safe_timeout ) { super ( *args , &block ) }
10
10
end
@@ -46,8 +46,25 @@ def add_foreign_key(from_table, to_table, **options)
46
46
without_statement_timeout { validate_foreign_key from_table , options_or_to_table } unless validate_present
47
47
end
48
48
49
+ def create_table ( *)
50
+ with_setting ( :statement_timeout , SafePgMigrations . config . pg_safe_timeout ) do
51
+ super do |td |
52
+ yield td if block_given?
53
+ td . indexes . map! do |key , index_options |
54
+ index_options [ :algorithm ] ||= :default
55
+ [ key , index_options ]
56
+ end
57
+ end
58
+ end
59
+ end
60
+
49
61
def add_index ( table_name , column_name , **options )
50
- options [ :algorithm ] = :concurrently
62
+ if options [ :algorithm ] == :default
63
+ options . delete :algorithm
64
+ else
65
+ options [ :algorithm ] = :concurrently
66
+ end
67
+
51
68
SafePgMigrations . say_method_call ( :add_index , table_name , column_name , options )
52
69
53
70
without_timeout { super }
0 commit comments