Skip to content

Commit 0fd8675

Browse files
check pg version directly with the current connection
1 parent f400883 commit 0fd8675

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/safe-pg-migrations/plugins/idempotent_statements.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ def add_column(table_name, column_name, type, **options)
2323
error_message = "/!\\ Column '#{column_name}' already exists in '#{table_name}' with a different type"
2424
raise error_message
2525
end
26+
2627
options_without_default_value_backfill = options.except(:default_value_backfill)
27-
return super(table_name, column_name, type, **options_without_default_value_backfill) unless column_exists?(table_name, column_name, type)
2828

29-
log_message(<<~MESSAGE.squish
30-
/!\\ Column '#{column_name}' already exists in '#{table_name}' with the same type (#{type}).
31-
Skipping statement.
32-
MESSAGE
33-
)
29+
if column_exists?(table_name, column_name, type)
30+
log_message(<<~MESSAGE.squish
31+
/!\\ Column '#{column_name}' already exists in '#{table_name}' with the same type (#{type}).
32+
Skipping statement.
33+
MESSAGE
34+
)
35+
else
36+
super(table_name, column_name, type, **options_without_default_value_backfill)
37+
end
3438
end
3539

3640
def remove_column(table_name, column_name, type = nil, **options)

test/StatementInsurer/change_column_null_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def skip_if_unmet_requirements!
127127

128128
def met_requirements?
129129
Gem::Requirement.new('>6.1').satisfied_by?(Gem::Version.new(::ActiveRecord::VERSION::STRING)) &&
130-
SafePgMigrations.pg_version_num >= 120_000
130+
SafePgMigrations.get_pg_version_num(@connection) >= 120_000
131131
end
132132
end
133133
end

0 commit comments

Comments
 (0)