Sha256: 9eb8c60ba372710076a118f5a0550eb11445914c22aa5a3fd5b27df6e0b99929

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "cases/helper"

class PostgresqlRenameTableTest < ActiveRecord::PostgreSQLTestCase
  def setup
    @connection = ActiveRecord::Base.connection
    @connection.create_table :before_rename, force: true
  end

  def teardown
    @connection.drop_table "before_rename", if_exists: true
    @connection.drop_table "after_rename", if_exists: true
  end

  test "renaming a table also renames the primary key index" do
    # sanity check
    assert_equal 1, num_indices_named("before_rename_pkey")
    assert_equal 0, num_indices_named("after_rename_pkey")

    @connection.rename_table :before_rename, :after_rename

    assert_equal 0, num_indices_named("before_rename_pkey")
    assert_equal 1, num_indices_named("after_rename_pkey")
  end

  private
    def num_indices_named(name)
      @connection.execute(<<~SQL).values.length
        SELECT 1 FROM "pg_index"
          JOIN "pg_class" ON "pg_index"."indexrelid" = "pg_class"."oid"
          WHERE "pg_class"."relname" = '#{name}'
      SQL
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ibm_db-5.5.0 test/cases/adapters/postgresql/rename_table_test.rb
ibm_db-5.4.1 test/cases/adapters/postgresql/rename_table_test.rb
ibm_db-5.4.0 test/cases/adapters/postgresql/rename_table_test.rb
ibm_db-5.3.2 test/cases/adapters/postgresql/rename_table_test.rb
ibm_db-5.3.1 test/cases/adapters/postgresql/rename_table_test.rb