You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
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.
Im running into the same problem. Using the %only option isn't really ideal because we have MULTIPLE table names, also I believe you need to include the schema.table_name even using the %only option, since otherwise it seems to throw it to 'delete' which is just deleting the entire table for me.
Take a look at #1154 issue of Sequel gem jeremyevans/sequel#1154.
My database consists of multiple schemas with some number of tables with the same name, like this:
I am using
database_cleaner
(1.5.1) andrspec
(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.Database contains all the data that was inserted during the tests. I open log files and see this:
As you can see - no schema provided to PSQL, just raw table names. Ok, I open
Sequel
adapter ofdatabase_cleaner
and learned how it tries to delete the data from the tables:As we see, db_cleaner gem get tables name with sequel
.tables
method. Ok, go toSequel
code (adapters/shared/postgres.rb
- 525 line of code) and see thattables
method return table names WITHOUT schemas.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:Thanks!
The text was updated successfully, but these errors were encountered: