PostgreSQL adapter method .tables return table names without schema
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 48/100
調査の方向性
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 はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DatabaseCleaner/database_cleaner-sequel のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
DatabaseCleaner/database_cleaner-sequel#28 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
DatabaseCleaner/database_cleaner-sequel#23 · リアクション 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
DatabaseCleaner/database_cleaner-sequel#18 · コメント 4 件 · リアクション 3 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
DatabaseCleaner/database_cleaner-sequel#2 · コメント 5 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
DatabaseCleaner/database_cleaner-sequel#3 · コメント 3 件 ·
DatabaseCleaner/database_cleaner-sequel の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
googleapis/google-api-ruby-client#28001 · リアクション 5 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100