### Strategy class implementation example Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md Implement strategy classes by inheriting from 'DatabaseCleaner::Strategy'. Each strategy must define a '#clean' method for performing the actual database cleaning. Transactional strategies may also define a '#start' method. ```ruby # lib/database_cleaner/orm_name/truncation.rb require 'database_cleaner/strategy' require 'orm' module DatabaseCleaner module OrmName class Truncation < Strategy def clean # actual database cleaning code goes here ORM.truncate_all_tables! end end end end ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/databasecleaner/database_cleaner/blob/main/CONTRIBUTE.markdown Steps to install project dependencies using Bundler and execute the test suite using RSpec and Cucumber. Cucumber tests may require Redis to be running or can be managed via Docker. ```shell bundle install bundle exec rspec bundle exec cucumber ``` -------------------------------- ### Minitest Database Cleaner Integration (Ruby) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Demonstrates how to integrate DatabaseCleaner with Minitest. It sets the default strategy to `:transaction` and uses Minitest's `before` and `after` hooks to start and clean the database for each test. An alternative using the `minitest-around` gem with `DatabaseCleaner.cleaning` is also shown for more concise setup. ```ruby DatabaseCleaner.strategy = :transaction class Minitest::Spec before :each do DatabaseCleaner.start end after :each do DatabaseCleaner.clean end end # with the minitest-around gem, this may be used instead: class Minitest::Spec around do |tests| DatabaseCleaner.cleaning(&tests) end end ``` -------------------------------- ### RSpec shared example for adapter testing Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md Utilize the 'database_cleaner-core' RSpec shared example to verify that your adapter adheres to the Database Cleaner API. This checks for the presence of required methods. ```ruby # spec/database_cleaner/orm_name_spec.rb require 'database_cleaner/orm_name' require 'database_cleaner/spec' RSpec.describe DatabaseCleaner::OrmName do it_should_behave_like "a database_cleaner adapter" end ``` -------------------------------- ### Run DatabaseCleaner Tests with Docker Source: https://github.com/databasecleaner/database_cleaner/blob/main/CONTRIBUTE.markdown This command starts the necessary services, like Redis, using Docker Compose, which is required for running the Cucumber specifications for DatabaseCleaner. ```shell docker compose up ``` -------------------------------- ### Setup database_cleaner-active_record Gem Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown This snippet shows how to add the database_cleaner-active_record gem to your Gemfile for use in test environments. It's the most common setup for Rails applications. ```ruby group :test do gem 'database_cleaner-active_record' end ``` -------------------------------- ### Cucumber Database Cleaner Setup (Ruby) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Provides instructions for integrating DatabaseCleaner with Cucumber, particularly for Rails projects. It suggests using the provided generator or manually creating a `features/support/database_cleaner.rb` file. The setup involves requiring `database_cleaner/active_record`, setting the strategy (e.g., `:truncation`), and defining an `Around` hook to manage the cleaning process between scenarios. ```ruby require 'database_cleaner/active_record' DatabaseCleaner.strategy = :truncation Around do |scenario, block| DatabaseCleaner.cleaning(&block) end ``` -------------------------------- ### Setup Multiple ORM Gems Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Demonstrates how to include multiple database_cleaner adapter gems in your Gemfile if your project utilizes more than one ORM or database system. ```ruby group :test do gem 'database_cleaner-active_record' gem 'database_cleaner-redis' end ``` -------------------------------- ### Basic Truncation Strategy Setup Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Configures Database Cleaner to use the `:truncation` strategy, which is suitable for clearing all data from tables before tests. This requires the relevant adapter gem to be loaded. ```ruby require 'database_cleaner/active_record' DatabaseCleaner.strategy = :truncation # To clean the DB: DatabaseCleaner.clean ``` -------------------------------- ### Default ORM Strategies Defined Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Defines default cleaning strategies for all supported ORM libraries, simplifying setup and usage. ```APIDOC Feature: Default ORM Strategies Defined Description: Default cleaning strategies have been established for all ORM libraries supported by DatabaseCleaner. This simplifies the initial setup and usage for developers. Related Features: - Add a NullStrategy - Mongo colletion indexes are dropped for collections being removed ``` -------------------------------- ### Transaction Strategy with Cleaning Block Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown An alternative way to use the `:transaction` strategy by wrapping test execution within a `DatabaseCleaner.cleaning` block. This automatically handles starting and cleaning the transaction. ```ruby require 'database_cleaner/active_record' DatabaseCleaner.strategy = :transaction DatabaseCleaner.cleaning do # Code that modifies the database within a transaction # DatabaseCleaner will automatically start and clean up end ``` -------------------------------- ### RSpec Configuration Example Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Configures RSpec to use Database Cleaner with the :transaction strategy and clean with :truncation before tests. It also ensures transactions are managed during test execution. ```ruby RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end config.around(:each) do |example| DatabaseCleaner.cleaning do example.run end end end ``` -------------------------------- ### MongoDB Truncation Strategy Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Refines the MongoDB truncation strategy to exclude system collections starting with 'system' from being truncated, preventing accidental data loss. ```APIDOC Bugfix: MongoDB Truncation Strategy Description: Fixes the MongoDB truncation logic to prevent system collections (those starting with 'system') from being excluded from truncation. This ensures only user-defined collections are targeted. Databases: - MongoDB Related Features: - PostgreSQL sequence reset - Avoid dropping views in Postgres ``` -------------------------------- ### Clone Repository and Set Upstream Source: https://github.com/databasecleaner/database_cleaner/blob/main/CONTRIBUTE.markdown Instructions for forking the DatabaseCleaner repository and cloning your fork locally. It also shows how to add the original repository as an upstream remote for keeping your fork updated. ```shell git clone git remote add upstream git@github.com:DatabaseCleaner/database_cleaner.git ``` -------------------------------- ### Bootstrap a new gem with bundle Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md Use the 'bundle gem' command to create the initial file structure for a new Database Cleaner adapter gem. This command generates all necessary files and directories for a standard Ruby gem. ```bash bundle gem database_cleaner-orm_name ``` -------------------------------- ### Adapter initialization file structure Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md Organize adapter files within the 'lib/database_cleaner/orm_name' directory. This includes strategy files (e.g., truncation.rb, deletion.rb) and a version file. ```text -lib -database_cleaner - orm_name - truncation.rb - deletion.rb - transaction.rb - version.rb - orm_name.rb ``` -------------------------------- ### Main adapter file (orm_name.rb) Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md The main adapter file must require the core library, all strategy files, and configure the default strategy for the ORM. This sets up the adapter for use with Database Cleaner. ```ruby # lib/database_cleaner/orm_name.rb require 'database_cleaner/orm_name/version' require 'database_cleaner/core' require 'database_cleaner/orm_name/transaction' require 'database_cleaner/orm_name/truncation' require 'database_cleaner/orm_name/deletion' DatabaseCleaner[:orm_name].strategy = :transaction ``` -------------------------------- ### Transaction Strategy with Manual Start/Clean Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Sets up the `:transaction` strategy, which wraps tests in a database transaction. This requires explicit calls to `DatabaseCleaner.start` before tests and `DatabaseCleaner.clean` after. ```ruby require 'database_cleaner/active_record' DatabaseCleaner.strategy = :transaction # Usually called in test setup: DatabaseCleaner.start # ... run tests ... # Cleanup after test: DatabaseCleaner.clean ``` -------------------------------- ### DatabaseCleaner API and Strategies Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Documentation for Database Cleaner's core API and available cleaning strategies. This includes setting the strategy and performing cleaning operations. ```APIDOC DatabaseCleaner API and Strategies: Strategy Configuration: DatabaseCleaner.strategy = :strategy_name Sets the cleaning strategy for DatabaseCleaner. Parameters: :strategy_name (Symbol): The name of the strategy to use. Supported values include :transaction, :truncation, :deletion, or nil. Example: DatabaseCleaner.strategy = :transaction Cleaning Operations: DatabaseCleaner.clean Cleans the database according to the currently set strategy. Returns: The result of the cleaning operation (e.g., number of rows deleted). DatabaseCleaner.clean_with(strategy_name) Cleans the database using a specific strategy, overriding the current one for this operation. Parameters: strategy_name (Symbol): The strategy to use for this specific cleaning operation. Example: DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.cleaning do ... end A block that ensures the database is cleaned before and after the block's execution, typically used with the :transaction strategy. Example: DatabaseCleaner.cleaning do # Your test code here end Supported Strategies: :transaction Description: Uses database transactions to clean data. Transactions are rolled back after tests. Pros: Generally the fastest strategy if applicable. Cons: Can be difficult to manage if tests require multiple database connections or run in different processes. :truncation Description: Truncates tables, which is typically faster than deletion for large datasets. Pros: Faster than :deletion for many table structures. Cons: May require specific database privileges; performance can vary based on table structure and foreign key constraints. :deletion Description: Deletes all records from tables. Pros: Simple to understand and implement. Cons: Can be slower than :truncation, especially for tables with many rows or complex relationships. nil Description: Disables automatic cleaning. No cleaning operations are performed. Pros: Useful for specific scenarios or when manual cleaning is preferred. Cons: Requires manual intervention for database cleanup. ``` -------------------------------- ### Mixed Strategy: Initial Truncation then Transaction Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Shows how to perform an initial database cleanup using `:truncation` and then switch to the `:transaction` strategy for subsequent tests. This combines the thoroughness of truncation with the speed of transactions. ```ruby require 'database_cleaner/active_record' # Perform an initial full cleanup DatabaseCleaner.clean_with :truncation # Set the strategy for subsequent tests DatabaseCleaner.strategy = :transaction # Then manage DatabaseCleaner.start and DatabaseCleaner.clean as needed ``` -------------------------------- ### Database Cleaner Configuration Options Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Details on configuration options for Database Cleaner, including changes in naming conventions and support for new parameters like :db and regular expressions for URL allowlisting. ```APIDOC Configuration Options: - `:url_allowlist` (String or Regexp): - Description: Specifies a list or regular expression of database URLs that are permitted for remote connections. - Changes: Renamed from `:url_whitelist`. Now supports regular expressions for more flexible matching. - Example: ```ruby DatabaseCleaner.url_allowlist = [/localhost/, /127.0.0.1/] ``` - `:allow_remote_database_url` (Boolean): - Description: Enables or disables the use of remote database URLs. Defaults to false. - Related: Used in conjunction with `:url_allowlist`. - `:db` (String or Hash): - Description: Specifies the database connection string or configuration. Replaces older options like `:connection` and `:url` for consistency. - Example: ```ruby DatabaseCleaner.db = 'postgres://user:pass@host:port/dbname' DatabaseCleaner.db = { adapter: 'postgresql', database: 'mydb' } ``` - `:orm` (Symbol or String): - Description: Specifies the Object-Relational Mapper (ORM) or adapter to use. Setter methods `#orm=` are deprecated. - Deprecation: All `#orm=` setter methods are deprecated in favor of direct configuration or adapter-specific setup. - `:connection` (String or Hash): - Description: Deprecated configuration option for specifying the database connection. Replaced by `:db`. - `:reset_ids` (Boolean): - Description: Option for ActiveRecord truncation strategy to reset sequence IDs after truncation. Deprecated. - Status: Deprecated in favor of other methods or strategies. - `:cache_tables` (Boolean): - Description: Option for Mongo truncation strategy to cache table names. Defaults to true. Deprecated in favor of deletion strategies. - Status: Deprecated in favor of deletion strategies. Related Methods/Concepts: - `DatabaseCleaner.connections`: Recommended alternative for managing multiple connections. - `DatabaseCleaner.url_whitelist`: Deprecated alias for `url_allowlist`. - `DatabaseCleaner.url`: Deprecated method for specifying Redis connection, replaced by `#db`. ``` -------------------------------- ### Other Adapter and Strategy Changes Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Covers support and fixes for other database adapters like Oracle, Redis, and Ohm, as well as general strategy improvements. ```APIDOC Other Adapters/Strategies: - Fully define Mysql2 adaptor constant. - Don't truncate schema tables in Postgres. - activerecord-oracle_enhanced-adapter now works again. - Redis & Ohm support. - Caching of tables to truncate is now optional. - #clean_with now works with multiple connections. - CI Improvements. - README/Documentation improvements. - Upgrade to RSpec 2. - Postgres Adapter no longer generates invalid SQL when no tables provided. - Rescue LoadError when AR adapters not available. - Fixes DatabaseCleaner::[] to cache cleaners. ``` -------------------------------- ### DatabaseCleaner Strategy Interface Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md Defines the expected interface for custom Database Cleaner strategies. Strategies must inherit from 'DatabaseCleaner::Strategy' and implement core methods for cleaning operations. ```APIDOC DatabaseCleaner::Strategy Inherits from: DatabaseCleaner::Base Instance Methods: #clean Description: Executes the cleaning logic for the strategy. Purpose: Performs the actual database cleanup operation (e.g., truncation, deletion). Required: Yes Example: def clean # ... database cleaning code ... end #start Description: Initializes the strategy's state, typically for transactional strategies. Purpose: Starts a database transaction or sets up any necessary context before cleaning. Optional: Yes (required for transactional strategies) Example: def start # ... start transaction logic ... end Related Concepts: - DatabaseCleaner::Base: The base class for all Database Cleaner components. - DatabaseCleaner[:orm_name].strategy = :strategy_name: Configuration to set the default strategy for a specific ORM. ``` -------------------------------- ### Sequel Adapter Changes Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Details improvements and fixes for the Sequel adapter, including support for multiple migration storage names and handling of symbol/string mismatches. ```APIDOC Sequel Adapter: - Improved Sequel support and added more tests. - Sequel strategy fix dealing with symbol/string mismatch on table names. - Sequel fix to normalize all table names to strings. - Add Sequel support for multiple migration storage names. - Sequel::Transaction works with latest Sequel. ``` -------------------------------- ### Configure URL Allowlist (Dynamic) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Enables dynamic matching of database URLs using regular expressions or procs. This provides more flexible control over which remote database URLs are allowed. ```ruby DatabaseCleaner.url_allowlist = [ %r{^postgres://postgres@localhost}, proc {|uri| URI.parse(uri).user == "test" } ] ``` -------------------------------- ### DatabaseCleaner ORM and Database Configuration (APIDOC) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Details how to configure DatabaseCleaner to manage multiple Object-Relational Mappers (ORMs) and databases within a single application. It shows syntax for specifying particular ORMs (e.g., `:active_record`, `:mongo_mapper`) and databases (e.g., `db: :two`, `db: ModelWithDifferentConnection`). Usage beyond configuration follows the standard `DatabaseCleaner.start` and `DatabaseCleaner.clean` methods. ```APIDOC DatabaseCleaner[:active_record].strategy = :transaction DatabaseCleaner[:mongo_mapper].strategy = :truncation # How to specify particular databases DatabaseCleaner[:active_record, db: :two] # You may also pass in the model directly: DatabaseCleaner[:active_record, db: ModelWithDifferentConnection] # Usage beyond that remains the same with DatabaseCleaner.start calling any setup on the different configured databases, and DatabaseCleaner.clean executing afterwards. ``` -------------------------------- ### Configure URL Allowlist (Static) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Specifies a static list of database URLs that are permitted when `DATABASE_URL` is used. DatabaseCleaner will only allow connections to URLs matching entries in this list. ```ruby DatabaseCleaner.url_allowlist = ['postgres://postgres@localhost', 'postgres://foo@bar'] ``` -------------------------------- ### Sequel Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Introduces support for the Sequel ORM, allowing database cleaning operations to be integrated with projects using Sequel. ```APIDOC Feature: Sequel Support Description: Adds compatibility for the Sequel ORM, enabling its use with DatabaseCleaner for database management tasks. Related Features: - DataMapper Strategies Updates - ActiveRecord and PSQL truncate command ``` -------------------------------- ### DatabaseCleaner::cleaning Method Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Introduces a new method `DatabaseCleaner::cleaning` which accepts a block, allowing for more flexible control over the cleaning process within a specific scope. ```ruby DatabaseCleaner.cleaning do # Code that needs to be executed within the cleaning context end ``` -------------------------------- ### NullStrategy Implementation Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Introduces a NullStrategy, providing a no-operation strategy for scenarios where no database cleaning is required or desired. ```APIDOC Feature: NullStrategy Implementation Description: A new NullStrategy has been added. This strategy performs no actions, serving as a placeholder or an option for disabling database cleaning. Related Features: - Default ORM strategies defined - Exclude database views from tables_to_truncate ``` -------------------------------- ### Database Cleaner Feature Additions Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Highlights new features and support for different database technologies and testing methodologies. ```APIDOC Feature Additions: - **Trilogy Support**: - Description: Added support for the Trilogy database adapter. - Reference: https://github.com/DatabaseCleaner/database_cleaner/pull/707 - **Cucumber Specs**: - Update: CONTRIBUTE.md updated to mention Cucumber specs as a testing dependency. - Reference: https://github.com/DatabaseCleaner/database_cleaner/pull/721 - **Deletion Aliases**: - Description: Introduced deletion aliases for truncation strategies for Mongo, Mongoid, and Redis adapters. - Reference: https://github.com/DatabaseCleaner/database_cleaner/pull/654 - **New :db Configuration Key**: - Description: Added a new `:db` ORM configuration key for consistency with `#db` and `#db=` methods. - Reference: https://github.com/DatabaseCleaner/database_cleaner/pull/649 ``` -------------------------------- ### MongoDB/Moped Adapter Changes Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Details support and fixes for MongoDB and Moped adapters, including handling collections with 'system' in their name and support for Moped without Mongoid. ```APIDOC MongoDB/Moped Adapter: - Fix issue where Moped cleaner was missing collections with 'system' in their name. - Suppport for Moped when used without Mongoid. - MongoDB :truncation strategy (without use of additional library like Mogoid). - Support for Mongoid 3/Moped. ``` -------------------------------- ### Database Cleaner Ruby Version Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Information regarding the Ruby versions supported by Database Cleaner, including dropped support for older versions and testing with newer ones. ```APIDOC Ruby Version Support: - **Dropped Support**: - Ruby 2.4: Support for Ruby 2.4 has been dropped as it reached End-Of-Life in March 2020. - Older Rubies: Support for older Ruby versions has been removed. - **Supported Versions**: - Ruby 2.5, 2.6, 2.7: Support for these versions is included. - Ruby 3.3: Testing with Ruby 3.3 is being integrated into Continuous Integration (CI) pipelines. - **Deprecation Warnings**: - Ruby 2.7: Fixed deprecation warnings related to Ruby 2.7. ``` -------------------------------- ### IBM_DB Adapter Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Adds support for the IBM_DB Adapter, enabling database cleaning for DB2 versions 9.7 and above. ```APIDOC Feature: IBM_DB Adapter Support Description: Introduces support for the IBM_DB Adapter, specifically for DB2 versions 9.7 and higher. This allows DatabaseCleaner to manage and clean DB2 databases. Databases: - DB2 (>= 9.7) Related Features: - Configurable logger - Reversed GH-41 (Mongo indexes no longer dropped) ``` -------------------------------- ### Clean and Clean! Aliases Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Aliases the 'clean' and 'clean_with' methods to 'clean!' and 'clean_with!' respectively, providing a more idiomatic Ruby interface for triggering cleaning operations. ```APIDOC Feature: Clean and Clean! Aliases Description: The methods 'clean' and 'clean_with' are now aliased to 'clean!' and 'clean_with!' respectively. This change offers a more conventional Ruby naming convention for methods that modify state or perform destructive actions. API Methods: - clean! - clean_with! Related Features: - Mongoid Support ``` -------------------------------- ### RSpec Capybara Database Cleaner Configuration (Ruby) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Configures DatabaseCleaner strategy for RSpec feature specs using Capybara. It dynamically switches to `:truncation` for drivers that do not share a database connection with specs (e.g., external browsers), while retaining `:transaction` for `:rack_test` to maintain performance. Ensures DatabaseCleaner runs after Capybara's cleanup. ```ruby require 'capybara/rspec' # ... RSpec.configure do |config| config.use_transactional_fixtures = false config.before(:suite) do if config.use_transactional_fixtures? raise(<<-MSG) Delete line `config.use_transactional_fixtures = true` from rails_helper.rb (or set it to false) to prevent uncommitted transactions being used in JavaScript-dependent specs. During testing, the app-under-test that the browser driver connects to uses a different database connection to the database connection used by the spec. The app's database connection would not be able to access uncommitted transaction data setup over the spec's database connection. MSG end DatabaseCleaner.clean_with(:truncation) end config.before(:each) do DatabaseCleaner.strategy = :transaction end config.before(:each, type: :feature) do # :rack_test driver's Rack app under test shares database connection # with the specs, so continue to use transaction strategy for speed. driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test unless driver_shares_db_connection_with_specs # Driver is probably for an external browser with an app # under test that does *not* share a database connection with the # specs, so use truncation strategy. DatabaseCleaner.strategy = :truncation end end config.before(:each) do DatabaseCleaner.start end config.append_after(:each) do DatabaseCleaner.clean end end ``` -------------------------------- ### CouchPotato/CouchDB Truncation Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Provides basic truncation support for CouchPotato and CouchDB, enabling database cleaning for NoSQL document databases. ```APIDOC Feature: CouchPotato/CouchDB Truncation Description: Basic truncation capabilities have been added for CouchPotato and CouchDB. This allows for cleaning operations on these NoSQL databases. Databases: - CouchDB ORMs: - CouchPotato Related Features: - SQLite3 fallback to delete - JDBC for ActiveRecord on JRuby ``` -------------------------------- ### Addresses Ruby 1.9/1.8 Differences in AR PostgreSQLAdapter Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Resolves bugs in the ActiveRecord PostgreSQLAdapter truncation strategy caused by differences between Ruby 1.9 and 1.8. ```APIDOC Bugfix: Addresses Ruby 1.9/1.8 Differences in AR PostgreSQLAdapter Description: This fix addresses compatibility issues arising from differences between Ruby 1.9 and 1.8 within the ActiveRecord PostgreSQLAdapter's truncation strategy. It ensures consistent behavior across Ruby versions. ORMs: - ActiveRecord Databases: - PostgreSQL Ruby Versions: - 1.9, 1.8 Related Features: - Fix MySQL Syntax Error during DataMapper Truncation - Fixes truncation for PostgreSQL ``` -------------------------------- ### Mysql2Adapter Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Adds support for the Mysql2Adapter, enabling database cleaning operations for MySQL databases using the mysql2 gem. ```APIDOC Feature: Mysql2Adapter Support Description: Introduces compatibility with the Mysql2Adapter, allowing DatabaseCleaner to effectively clean MySQL databases when using the mysql2 gem. Databases: - MySQL Related Features: - Multiple ORM/Connection Support - ActiveRecord config file ERB processing ``` -------------------------------- ### Configurable Logger Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Introduces a configurable logger option, allowing users to specify a custom logger for debugging and monitoring database cleaning activities. ```APIDOC Feature: Configurable Logger Description: Users can now configure a custom logger to aid in debugging and monitoring the DatabaseCleaner process. This provides greater visibility into the cleaning operations. Configuration Options: - logger: Specify a logger instance. Related Features: - Avoid trying to load ':default' ActiveRecord config - Cache DB connections ``` -------------------------------- ### Optimized Truncation for AR/PSQL Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Implements a single command to truncate all tables for ActiveRecord and PostgreSQL, significantly improving performance by avoiding cascade operations. ```APIDOC Feature: Optimized Truncation for AR/PSQL Description: For ActiveRecord and PostgreSQL, all tables are now truncated using a single command. This optimization bypasses cascade operations, leading to improved performance. Databases: - PostgreSQL ORMs: - ActiveRecord Related Features: - Sequel Support - DataMapper Strategies Update ``` -------------------------------- ### ActiveRecord Adapter Changes Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Details various improvements and fixes related to the ActiveRecord adapter, including transaction handling, truncation strategies, and compatibility with different Rails and adapter versions. ```APIDOC ActiveRecord Adapter: - Fixes transaction rollback issues with Active Record application-level transactions. - Supports AR 4.0 by using `begin_transaction`. - Adds Rails 4 support for SQLite3Adapter. - Truncation strategy caches the list of tables for performance. - Deletion strategy disables referential integrity and works with multiple statements. - Fixes `pre_count` logic in AR Postgres. - Fixes truncation error with SQLite, resetting id count. - Fixes transaction errors when using `after_commit` hooks in AR. - Defines Mysql2 adaptor constant. - Fixes typo in Postgres superclass (POSTGRE_ADAPTER_PARENT > POSTGRES_ADAPTER_PARENT). - Fixes MySqlAdapter superclass bug via class_eval loading of superclasses. - Faster truncation strategy for ActiveRecord with MySQL or PostgreSQL. - Proper Mysql2Adapter superclass fix. - AR delete strategy now disables referential integrity. - Fixes Postgres adapter for JRuby. - schema_migrations table name is now retrieved from ActiveRecord. - Caches AR DB connections which speeds up cleaning with multiple DBs and allows for transaction strategy. ``` -------------------------------- ### Truncation Strategy with Specific Tables (Only) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Shows how to configure the `:truncation` strategy to only clean specified tables, excluding others. This is useful for tables that should persist across test runs. ```ruby DatabaseCleaner.strategy = [:truncation, only: %w[widgets dogs some_other_table]] ``` -------------------------------- ### General Gem Improvements Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Details general improvements to the gem, such as RSpec upgrades, autoloading logic exposure, and compatibility changes. ```APIDOC General Gem Improvements: - Upgraded RSpec to remove deprecation warnings. - Autoloading logic is now exposed, see PR #212 for details. - Dropping support for Ruby 1.8.x; Only 1.9.x and beyond will be supported going forward. - Now supporting and testing against ruby 2.0.x. - Patch release to fix broken gemspec file. - Use class_eval loading of superclasses to ensure right version of class is patched. - Fixes missing #uses_sequence invokation in adapter classes for sqlite and sqlite3. - Support for Rails 3.2. - Documenation fixes/improvements. - View caching works with the schema_plus gem loaded (ActiveRecord::ConnectionAdapters::AbstractAdapter#views was renamed to an internal name). ``` -------------------------------- ### Truncation Strategy with Excluded Tables (Except) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Illustrates configuring the `:truncation` strategy to exclude certain tables from being cleaned. The `schema_migrations` table is automatically excluded by default. ```ruby DatabaseCleaner.strategy = [:truncation, except: %w[widgets]] ``` -------------------------------- ### Database Cleaner Strategy Deprecations and Changes Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Details on the deprecation of specific truncation strategies in favor of deletion methods, and changes in adapter configurations for various databases. ```APIDOC Strategy Deprecations and Changes: - **Deletion vs. Truncation**: - Description: Truncation strategies for Mongo, Mongoid, and Redis adapters are deprecated in favor of deletion strategies. - Rationale: Provides a more consistent and potentially safer way to clean data. - Status: Deprecated. - **Redis Adapter**: - Deprecation: The `#url` method for the Redis adapter is deprecated. - Replacement: Use the `#db` configuration option instead. - **Mongo Adapter**: - Bugfix: Addressed issues with the `:mongo` strategy, improving its reliability. - Caching: The `:cache_tables => true` option is deprecated in favor of `false`, preparing for caching removal in v2.0. - **Mongoid Adapter**: - Autoloading: Fixed issues with autodetected adapter loading for `database_cleaner-mongoid`. - **ActiveRecord Adapter**: - Safeguards: Conventional `sqlite://` URLs are now skipped from safeguards. - Metadata: `ar_internal_metadata` is excluded from truncation on Rails 5. - **ORM Adapter Gems**: - New API: Introduced a new API for ORM Adapter gems, facilitating better integration and development. - **Gem Splitting**: - Change: The core gem was split into `database_cleaner-core` and a `database_cleaner` metagem. - Impact: Adapter gems are now split into their own repositories for modularity. ``` -------------------------------- ### Fix Version Checking for PostgreSQL Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Corrects version checking logic for PostgreSQL, ensuring accurate compatibility checks and proper adapter behavior. ```APIDOC Bugfix: Fix Version Checking for PostgreSQL Description: The version checking mechanism for PostgreSQL has been fixed. This ensures that the gem correctly identifies PostgreSQL versions and applies appropriate logic, such as for sequence resets. Databases: - PostgreSQL Related Features: - Don't modify array passed with :except key - When truncating in postgresql (>= 8.4) sequences are now reset ``` -------------------------------- ### DataMapper Strategies Update Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Updates DataMapper strategies to ensure compatibility with DataMapper version 1.1, maintaining seamless integration for projects using both. ```APIDOC Feature: DataMapper Strategies Update Description: Ensures that the DataMapper strategies within DatabaseCleaner are compatible with DataMapper version 1.1. Dependencies: - DataMapper 1.1 Related Features: - Sequel Support - ActiveRecord and PSQL truncate command ``` -------------------------------- ### Modify .gemspec for adapter dependencies Source: https://github.com/databasecleaner/database_cleaner/blob/main/ADAPTERS.md Add 'database_cleaner-core' and the specific ORM dependency to your gem's .gemspec file. This ensures the adapter has the necessary core functionality and ORM integration. ```ruby spec.add_dependency "database_cleaner-core" spec.add_dependency "orm_name", "some version if required" ``` -------------------------------- ### Multiple ORM/Connection Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Enables cleaning multiple databases within the same project, supporting databases managed by the same or different ORMs, enhancing flexibility for complex projects. ```APIDOC Feature: Multiple ORM/Connection Support Description: Allows DatabaseCleaner to manage and clean multiple database connections simultaneously. This includes connections managed by the same ORM and those managed by different ORMs within a single project. Use Cases: - Cleaning ActiveRecord and Mongoid databases in the same project. - Managing distinct database connections for the same ORM. Related Features: - ActiveRecord config file ERB processing - Mysql2Adapter support - Deletion strategy for ActiveRecord ``` -------------------------------- ### Workaround for ActiveRecord-jdbc-adapter Superclass Mismatches Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Provides a workaround for superclass mismatches encountered with the ActiveRecord-jdbc-adapter, ensuring compatibility. ```APIDOC Bugfix: Workaround for ActiveRecord-jdbc-adapter Superclass Mismatches Description: A workaround has been implemented to address superclass mismatches that can occur when using the ActiveRecord-jdbc-adapter. This ensures smoother operation and compatibility. ORMs: - ActiveRecord Adapters: - ActiveRecord-jdbc-adapter Related Features: - Fixes truncation for PostgreSQL - Removes extraneous puts call from configuration.rb ``` -------------------------------- ### SqlServer Truncation with FKs Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Ensures the truncation strategy works correctly on SqlServer tables that have foreign key constraints, preventing errors during cleanup. ```APIDOC Bugfix: SqlServer Truncation with FKs Description: The truncation strategy has been updated to correctly handle SqlServer tables that contain foreign key constraints. This resolves issues that previously occurred during cleanup operations. Databases: - SqlServer Related Features: - PostgreSQL Sequence Reset - Reversed Mongo index dropping ``` -------------------------------- ### Mongoid Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Adds comprehensive support for the Mongoid ODM, enabling database cleaning operations for MongoDB databases managed by Mongoid. ```APIDOC Feature: Mongoid Support Description: Introduces full support for the Mongoid Object-Document Mapper. This allows DatabaseCleaner to effectively manage and clean MongoDB databases when used with Mongoid. ORMs: - Mongoid Databases: - MongoDB Related Features: - Clean and Clean! Aliases - PostgreSQL version check for TRUNCATE CASCADE ``` -------------------------------- ### Explicitly Require ERB Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Ensures that the ERB library is explicitly required, preventing potential runtime errors related to missing dependencies. ```APIDOC Bugfix: Explicitly Require ERB Description: The ERB library is now explicitly required at runtime. This guarantees that ERB functionality is available when needed, preventing 'uninitialized constant ERB' errors. Related Features: - Cache DB connections - Don't modify array passed with :except key ``` -------------------------------- ### Disable Production/Remote Safeguards (Environment Variables) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Allows disabling the built-in safeguards that prevent DatabaseCleaner from running in production or against remote databases by setting environment variables. ```bash export DATABASE_CLEANER_ALLOW_PRODUCTION=true export DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true ``` -------------------------------- ### Fixes Bad Error Message for AR Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Corrects a bad error message that occurred when no database was specified for ActiveRecord, improving user feedback. ```APIDOC Bugfix: Fixes Bad Error Message for AR Description: Addresses an issue where an unhelpful error message was displayed when no database configuration was found for ActiveRecord. The error reporting is now more informative. ORMs: - ActiveRecord Related Features: - Avoids trying to load the ':default' ActiveRecord config ``` -------------------------------- ### Avoid Loading Default ActiveRecord Config Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Prevents the gem from attempting to load the ':default' ActiveRecord configuration, which can cause errors if not properly defined. ```APIDOC Bugfix: Avoid Loading Default ActiveRecord Config Description: The gem now avoids attempting to load the ':default' ActiveRecord configuration. This prevents potential errors that could arise if this configuration is missing or improperly set up. ORMs: - ActiveRecord Related Features: - Fixes bad error message for AR - Cache DB connections ``` -------------------------------- ### SQLite3 JRuby Fallback Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Configures SQLite3 on JRuby to fall back to using DELETE statements if TRUNCATE operations are not supported or fail, ensuring reliable cleaning. ```APIDOC Feature: SQLite3 JRuby Fallback Description: For SQLite3 databases running on JRuby, the system will now automatically fall back to using DELETE statements if the TRUNCATE command is not supported or encounters an error. This ensures that database cleaning operations are always successful. Databases: - SQLite3 - JRuby Related Features: - CouchPotato/CouchDB Truncation - JDBC for ActiveRecord on JRuby ``` -------------------------------- ### ORM Type String Specification Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Allows ORM types to be specified in string format, improving flexibility and preventing errors when configuring ORM adapters. ```APIDOC Bugfix: ORM Type String Specification Description: ORM types can now be specified as strings, rather than requiring specific object types. This change prevents configuration errors and makes the gem more robust. Configuration: - Specify ORM type as a string (e.g., 'activerecord', 'sequel'). Related Features: - Exclude database views from tables_to_truncate - Do not remove MongoDB reserved system collections ``` -------------------------------- ### ActiveRecord Config ERB Processing Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Allows the ActiveRecord configuration file (database.yml) to contain and process ERB, enabling dynamic configuration options. ```APIDOC Feature: ActiveRecord Config ERB Processing Description: The ActiveRecord configuration file, typically database.yml, can now include ERB syntax and have it processed. This allows for dynamic generation of database connection configurations. Configuration: - database.yml can contain ERB tags. Related Features: - Multiple ORM/Connection Support - Mysql2Adapter support ``` -------------------------------- ### ActiveRecord Deletion Strategy Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Introduces a deletion strategy for ActiveRecord, providing an alternative method for cleaning tables that may not support truncation. ```APIDOC Feature: ActiveRecord Deletion Strategy Description: A new deletion strategy has been implemented for ActiveRecord. This strategy uses DELETE statements to remove records, offering an alternative to TRUNCATE for tables or databases where truncation is not suitable or available. ORMs: - ActiveRecord Related Features: - Multiple ORM/Connection Support - Mysql2Adapter support ``` -------------------------------- ### Fix AR for Rails 3 Support Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Attempts to fix ActiveRecord support for Rails 3, though user feedback has been mixed, indicating potential for further rework. ```APIDOC Bugfix: Fix AR for Rails 3 Support Description: This release includes fixes aimed at improving ActiveRecord support for Rails 3. However, user feedback indicates that the implementation may require further rework to achieve consistent compatibility. ORMs: - ActiveRecord Frameworks: - Rails 3 Related Features: - Mongoid Support! - Check PostgreSQL version >= 8.2 before using TRUNCATE CASCADE ``` -------------------------------- ### Fix PostgreSQL Truncation Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Addresses issues with truncation in PostgreSQL, ensuring it functions correctly across different versions and configurations. ```APIDOC Bugfix: Fix PostgreSQL Truncation Description: Improvements have been made to the truncation process for PostgreSQL databases. This resolves issues that previously affected its functionality. Databases: - PostgreSQL Related Features: - Fix MySQL Syntax Error during DataMapper Truncation - Workaround for superclass mismatches for the ActiveRecord-jdbc-adapter ``` -------------------------------- ### JDBC for ActiveRecord on JRuby Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Automatically uses JDBC for ActiveRecord connections when JRuby is detected, optimizing database interactions for Java-based Ruby environments. ```APIDOC Feature: JDBC for ActiveRecord on JRuby Description: When running on JRuby, DatabaseCleaner now automatically utilizes JDBC for ActiveRecord connections. This integration leverages Java's database connectivity for potentially improved performance and compatibility. ORMs: - ActiveRecord Environments: - JRuby Related Features: - CouchPotato/CouchDB Truncation - SQLite3 JRuby Fallback ``` -------------------------------- ### Cache DB Connections Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Caches database connections to improve performance and resolve referential integrity bugs when using multiple databases. ```APIDOC Bugfix: Cache DB Connections Description: Database connections are now cached. This optimization improves performance and resolves referential integrity bugs that could occur when managing multiple database connections within the same project. Related Features: - Avoids trying to load the ':default' ActiveRecord config - Explicitly require ERB ``` -------------------------------- ### PostgreSQL Version Check for TRUNCATE CASCADE Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Checks PostgreSQL version to ensure TRUNCATE CASCADE is used only for versions 8.2 and above, preventing compatibility issues. ```APIDOC Bugfix: PostgreSQL Version Check for TRUNCATE CASCADE Description: A check is now performed to ensure that TRUNCATE CASCADE is only used for PostgreSQL versions 8.2 and newer. This prevents errors on older versions that do not support this syntax. Databases: - PostgreSQL (>= 8.2) Related Features: - Correct superclass in ActiveRecord connection adapters - Mongoid Support ``` -------------------------------- ### Fix MySQL Syntax Error during DataMapper Truncation Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Resolves a syntax error encountered by MySQL during DataMapper truncation operations, ensuring smooth execution. ```APIDOC Bugfix: Fix MySQL Syntax Error during DataMapper Truncation Description: A syntax error that MySQL was throwing during DataMapper truncation operations has been fixed. This ensures that DataMapper truncation works correctly with MySQL databases. Databases: - MySQL ORMs: - DataMapper Related Features: - Addresses Ruby 1.9 and 1.8 differences causing bug in AR PostgreSQLAdapter truncation strategy - Fixes truncation for PostgreSQL ``` -------------------------------- ### Disable Production/Remote Safeguards (Ruby) Source: https://github.com/databasecleaner/database_cleaner/blob/main/README.markdown Programmatically disables the production and remote database safeguards within a Ruby application. This is an alternative to using environment variables. ```ruby DatabaseCleaner.allow_production = true DatabaseCleaner.allow_remote_database_url = true ``` -------------------------------- ### PostgreSQL Sequence Reset Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Ensures that PostgreSQL sequences are reset when truncating tables in versions 8.4 and above, maintaining data integrity and sequence continuity. ```APIDOC Bugfix: PostgreSQL Sequence Reset Description: When truncating tables in PostgreSQL versions 8.4 and newer, sequences are now correctly reset. This maintains the integrity of auto-incrementing IDs. Databases: - PostgreSQL (>= 8.4) Related Features: - MongoDB Truncation Strategy - Fixes for FKs on SqlServer tables ``` -------------------------------- ### Remove Extraneous Puts Call Source: https://github.com/databasecleaner/database_cleaner/blob/main/History.rdoc Removes an extraneous 'puts' call from the configuration.rb file, cleaning up unnecessary output during execution. ```APIDOC Bugfix: Remove Extraneous Puts Call Description: An unnecessary 'puts' statement has been removed from the configuration.rb file. This eliminates extraneous output that could appear during the gem's operation. Related Features: - Workaround for superclass mismatches for the ActiveRecord-jdbc-adapter - Mongoid Support! ```