mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix set_pk_sequence and add a test for it.
This commit is contained in:
parent
4f6fb19662
commit
3dae34e217
2 changed files with 9 additions and 1 deletions
|
@ -303,7 +303,7 @@ module ActiveRecord
|
|||
|
||||
if pk
|
||||
if sequence
|
||||
quoted_sequence = quote_column_name(sequence)
|
||||
quoted_sequence = quote_table_name(sequence)
|
||||
|
||||
select_value <<-end_sql, 'SCHEMA'
|
||||
SELECT setval('#{quoted_sequence}', #{value})
|
||||
|
|
|
@ -388,6 +388,14 @@ class SchemaTest < ActiveRecord::TestCase
|
|||
assert_equal "1", @connection.select_value("SELECT nextval('#{sequence_name}')")
|
||||
end
|
||||
|
||||
def test_set_pk_sequence
|
||||
table_name = "#{SCHEMA_NAME}.#{PK_TABLE_NAME}"
|
||||
_, sequence_name = @connection.pk_and_sequence_for table_name
|
||||
@connection.set_pk_sequence! table_name, 123
|
||||
assert_equal "124", @connection.select_value("SELECT nextval('#{sequence_name}')")
|
||||
@connection.reset_pk_sequence! table_name
|
||||
end
|
||||
|
||||
private
|
||||
def columns(table_name)
|
||||
@connection.send(:column_definitions, table_name).map do |name, type, default|
|
||||
|
|
Loading…
Reference in a new issue