PostgreSQL adapter method .tables return table names without schema
还没有人认领这个 Issue。
评估
调研方向
先从 database_cleaner/sequel/deletion.rb 中的 delete_tables 方法和 database_cleaner/sequel/truncation.rb 中的 tables_to_truncate 方法开始,然后检查 adapters/shared/postgres.rb 中 tables 方法附近的代码。验证来自多个 schema 的表是否使用带 schema 限定的标识符表示,并验证删除或截断是否会从列出的每个 schema 中移除记录。
由索引模型根据 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
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 38/100
DatabaseCleaner/database_cleaner-sequel#18 · 4 条评论 · 3 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 30/100
DatabaseCleaner/database_cleaner-sequel#2 · 5 条评论 · 2 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 35/100
DatabaseCleaner/database_cleaner-sequel#3 · 3 条评论 ·
查看 DatabaseCleaner/database_cleaner-sequel 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 2/5 1-3 小时 新手友好度 66/100
demarche-numerique/demarche.numerique.gouv.fr#14301 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
voxpupuli/puppet-powerdns#251 ·
-
needs verification
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 6 天内回复