Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

PostgreSQL adapter method .tables return table names without schema

オープン
#6 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
postgresql, ruby
領域
databases

調査の方向性

database_cleaner/sequel/deletion.rb の delete_tables メソッドと database_cleaner/sequel/truncation.rb の tables_to_truncate メソッドから始め、次に tables メソッド周辺の adapters/shared/postgres.rb を確認してください。複数のスキーマのテーブルがスキーマ修飾された識別子で表現されていること、また削除またはトランケーションによって一覧にあるすべてのスキーマからレコードが削除されることを検証してください。

索引モデルが issue の本文から書いたものです。

説明

Take a look at #1154 issue of Sequel gem https://github.com/jeremyevans/sequel/issues/1154.

My database consists of multiple schemas with some number of tables with the same name, like this:

       Schema    |          Name           | Type    |  Owner   
-----------------+-------------------------+---------+----------
 type1           | tasks                   | table   | user
 type1           | updates                 | table   | user
 type2           | tasks                   | table   | user
 type2           | updates                 | table   | user
 type3           | tasks                   | table   | user
 type3           | updates                 | table   | user
  ...

I am using database_cleaner (1.5.1) and rspec (3.4.0) for my tests. Database config contains search_path for all the schemas. When I try to clear DB with :deletion method (or :truncate) - it didn't remove any records.

DatabaseCleaner[:sequel, { connection: DB }]

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:deletion)
  end

  config.around(:each) do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end

Database contains all the data that was inserted during the tests. I open log files and see this:

I, INFO -- : (0.000349s) ALTER TABLE "updates" DISABLE TRIGGER ALL
I, INFO -- : (0.000444s) ALTER TABLE "tasks" DISABLE TRIGGER ALL
I, INFO -- : (0.000236s) ALTER TABLE "updates" DISABLE TRIGGER ALL
I, INFO -- : (0.000232s) ALTER TABLE "tasks" DISABLE TRIGGER ALL
I, INFO -- : (0.000202s) ALTER TABLE "updates" DISABLE TRIGGER ALL
I, INFO -- : (0.000200s) ALTER TABLE "tasks" DISABLE TRIGGER ALL
....
I, INFO -- : (0.000349s) DELETE FROM "tasks"
I, INFO -- : (0.000444s) DELETE FROM "updates"
I, INFO -- : (0.000249s) DELETE FROM "tasks"
I, INFO -- : (0.000314s) DELETE FROM "updates"
...

As you can see - no schema provided to PSQL, just raw table names. Ok, I open Sequel adapter of database_cleaner and learned how it tries to delete the data from the tables:

    # database_cleaner/sequel/deleteion.rb : 30-46
    def delete_tables(db, tables)  # tables - connection.tables method of Sequel
      tables.each do |table|
        db[table.to_sym].delete
      end
    end

   # database_cleaner/sequel/truncation.rb : 64-67
    def tables_to_truncate(db)
       (@only || db.tables.map(&:to_s)) - @tables_to_exclude
    end

As we see, db_cleaner gem get tables name with sequel .tables method. Ok, go to Sequel code (adapters/shared/postgres.rb - 525 line of code) and see that tables method return table names WITHOUT schemas.

2.1.7 :004 > DB.tables # DB - sequel connection
 => [:updates, :tasks, :updates, :tasks, :updates, :schema_info, :tasks, :tasks, :tasks, :updates, :tasks, :updates]

Thats why no one record is removed and that is why database_cleaner doesn't remove any data.

For correct removing of the data from the tables with schema database_cleaner gem needs something like this:

[:type1__updates, :type1__tasks, :type2__updates, :type2__tasks, :type3__updates, :type3__tasks ]

Thanks!

主要言語
Ruby
スター
19
フォーク
11
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DatabaseCleaner/database_cleaner-sequel のほかの issue

DatabaseCleaner/database_cleaner-sequel の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。