db-nuker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +49 -0
- data/db-nuker.gemspec +15 -0
- data/lib/db-nuker.rb +2 -0
- data/lib/db_nuker.rb +32 -0
- data/lib/mysql2_patch.rb +11 -0
- metadata +49 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 4a12ad9532a4566eb448f3a9231df54ada5e6e41
         | 
| 4 | 
            +
              data.tar.gz: cd91edb66d3da1c9b761cc45b84490903c4e7b74
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 2b4e229a89faeebe4cc6c28b35bfe79a06408f1855678e365c449d87d4fcb89be322c306d6f636463960583448fa3e697d3fca823aba93656a7533a2140a4c4a
         | 
| 7 | 
            +
              data.tar.gz: 028bb1f9f907f20a000ca368c3d88be70dc3a713126c8257c66fd9b60e7a1ecf5d392fb298d9e6cd96fe09df2010061fd82827c9a108854cdaed9ac3d9ef4aa7
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            # DB Nuker
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Faster database cleaner for _MySQL_
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Usage
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            1) Add it your gemfile
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ```ruby
         | 
| 10 | 
            +
            gem 'db-nuker'
         | 
| 11 | 
            +
            ```
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            2) Create file `spec/support/db_nuker.rb`
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ```ruby
         | 
| 16 | 
            +
            RSpec.configure do |config|
         | 
| 17 | 
            +
              config.use_transactional_fixtures = false
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              config.before(:suite) do
         | 
| 20 | 
            +
                DBNuker.boom!
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              config.after(:each) do
         | 
| 24 | 
            +
                DBNuker.boom!
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
            ```
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            3) Enjoy!
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            ## How Does It Work?
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Pure magic!
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            ## No, Really?
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            It cleans only those tables that have records in them
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            ## Known Caveates
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            Doesn't reset the tables auto-increments. Well, you shouldn't rely
         | 
| 42 | 
            +
            on certain IDs in your tests anyways.
         | 
| 43 | 
            +
             | 
| 44 | 
            +
             | 
| 45 | 
            +
            ## License & Copyright
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            All code in this repository is released under the terms of the MIT license
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            Copyright (C) 2014 Nikolay Nemshilov
         | 
    
        data/db-nuker.gemspec
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require File.dirname(__FILE__) + '/lib/db_nuker'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Gem::Specification.new do |gem|
         | 
| 5 | 
            +
              gem.name          = "db-nuker"
         | 
| 6 | 
            +
              gem.version       = DBNuker::VERSION
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              gem.authors       = ["Nikolay Nemshilov"]
         | 
| 9 | 
            +
              gem.email         = ['nemshilov@gmail.com']
         | 
| 10 | 
            +
              gem.description   = "An awesome db nuker"
         | 
| 11 | 
            +
              gem.summary       = "An awesome db nuker. FTW"
         | 
| 12 | 
            +
              gem.license       = 'MIT'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              gem.files         = `git ls-files`.split($/)
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/db-nuker.rb
    ADDED
    
    
    
        data/lib/db_nuker.rb
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            module DBNuker
         | 
| 2 | 
            +
              VERSION = "1.0.0"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              def self.boom!
         | 
| 5 | 
            +
                query = tables_to_delete.map do |table|
         | 
| 6 | 
            +
                  "DELETE FROM #{table};"
         | 
| 7 | 
            +
                end.join("")
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                execute query if query.size > 0
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def self.connection
         | 
| 13 | 
            +
                ActiveRecord::Base.connection
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def self.execute(query)
         | 
| 17 | 
            +
                connection.execute query
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def self.tables_to_delete
         | 
| 21 | 
            +
                result = execute("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{db_name}' AND table_rows > 0")
         | 
| 22 | 
            +
                result.map{ |row| row[0] } - tables_to_skip
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def self.tables_to_skip
         | 
| 26 | 
            +
                @tables_to_skip ||= %w{ schema_migrations sessions }
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def self.db_name
         | 
| 30 | 
            +
                @db_name ||= connection.instance_variable_get('@config')[:database]
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
    
        data/lib/mysql2_patch.rb
    ADDED
    
    | @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            ActiveRecord::Base.instance_eval do
         | 
| 2 | 
            +
              def self.mysql2_connection(config)
         | 
| 3 | 
            +
                config[:username] = 'root' if config[:username].nil?
         | 
| 4 | 
            +
                config[:flags] = 2 | 65536 | 131072 # FOUND_ROWS | MULTI_STATEMENTS | MULTI_RESULTS
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                client = Mysql2::Client.new(config.symbolize_keys)
         | 
| 7 | 
            +
                options = config.values_at(:host, :username, :password, :database, :port, :socket, :flags)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                ActiveRecord::ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: db-nuker
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Nikolay Nemshilov
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-03-14 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: An awesome db nuker
         | 
| 14 | 
            +
            email:
         | 
| 15 | 
            +
            - nemshilov@gmail.com
         | 
| 16 | 
            +
            executables: []
         | 
| 17 | 
            +
            extensions: []
         | 
| 18 | 
            +
            extra_rdoc_files: []
         | 
| 19 | 
            +
            files:
         | 
| 20 | 
            +
            - README.md
         | 
| 21 | 
            +
            - db-nuker.gemspec
         | 
| 22 | 
            +
            - lib/db-nuker.rb
         | 
| 23 | 
            +
            - lib/db_nuker.rb
         | 
| 24 | 
            +
            - lib/mysql2_patch.rb
         | 
| 25 | 
            +
            homepage: 
         | 
| 26 | 
            +
            licenses:
         | 
| 27 | 
            +
            - MIT
         | 
| 28 | 
            +
            metadata: {}
         | 
| 29 | 
            +
            post_install_message: 
         | 
| 30 | 
            +
            rdoc_options: []
         | 
| 31 | 
            +
            require_paths:
         | 
| 32 | 
            +
            - lib
         | 
| 33 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 34 | 
            +
              requirements:
         | 
| 35 | 
            +
              - - ">="
         | 
| 36 | 
            +
                - !ruby/object:Gem::Version
         | 
| 37 | 
            +
                  version: '0'
         | 
| 38 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 39 | 
            +
              requirements:
         | 
| 40 | 
            +
              - - ">="
         | 
| 41 | 
            +
                - !ruby/object:Gem::Version
         | 
| 42 | 
            +
                  version: '0'
         | 
| 43 | 
            +
            requirements: []
         | 
| 44 | 
            +
            rubyforge_project: 
         | 
| 45 | 
            +
            rubygems_version: 2.2.2
         | 
| 46 | 
            +
            signing_key: 
         | 
| 47 | 
            +
            specification_version: 4
         | 
| 48 | 
            +
            summary: An awesome db nuker. FTW
         | 
| 49 | 
            +
            test_files: []
         |