GithubHelp home page GithubHelp logo

qpc-github / activerecord-pedantmysql2-adapter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shopify/activerecord-pedantmysql2-adapter

1.0 1.0 0.0 58 KB

Active Record adapter for MySQL that reports warnings.

License: MIT License

Ruby 99.26% Roff 0.74%

activerecord-pedantmysql2-adapter's Introduction

Activerecord::PedantMysql2

Build Status Code Climate Coverage Status Gem Version

ActiveRecord adapter for MySQL that report warnings.

The main usage is to progressively identify and fix MySQL warnings generated by legacy rails applications, and ultimately enable strict mode.

Alternatively it can be used to treat all MySQL warnings as errors.

Installation

Add this line to your application's Gemfile:

gem 'activerecord-pedantmysql2-adapter'

And then execute:

$ bundle

Finally in your database.yml:

adapter: pedant_mysql2

Or if you're using DATABASE_URL or the url key in database.yml, you can use the pedant-mysql2 URL scheme:

url: pedant-mysql2://host/database

Usage

By default it will raise warnings as errors. But you can define any behaviour yourself in an initializer.

You can report them to your exception tracker:

  PedantMysql2.on_warning = lambda { |warning| Airbrake.notify(warning) }

or totally silence them:

  PedantMysql2.silence_warnings!

and to restore it to raising warnings as errors:

  PedantMysql2.raise_warnings!

You can easily whitelist some types of warnings:

PedantMysql2.ignore(/Some warning I don't care about/i)

If you want to silence warnings for a limited scope, you can capture the warnings:

warnings = PedantMysql2.capture_warnings do
  # perform query that may raise an error you want to stifle
end

Thread-safe

This gem is tested to be thread safe with a couple known exceptions.

PedantMysql2.ignore is not thread safe and should only be called during initialization of your app. Changing this within a thread while another is updating it could be problematic. PedantMysql2.on_warning= is not thread safe, this should also be called only during initialization.

If you find any other parts that are not thread-safe, please create an issue or PR.

Development

Setting up the development environment is very straightforward. In order to keep the test as simple as possible we rely on your MySQL database to have a travis user and a pedant_mysql2_test database.

You can set this up easily using the following commands as your root MySQL user:

CREATE USER 'travis'@'localhost';
CREATE DATABASE pedant_mysql2_test;
GRANT ALL PRIVILEGES ON pedant_mysql2_test.* TO 'travis'@'localhost';

Contributing

  1. Fork it ( http://github.com/Shopify/activerecord-pedantmysql2-adapter/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

activerecord-pedantmysql2-adapter's People

Contributors

byroot avatar casperisfine avatar eapache avatar edouard-chin avatar etiennebarrie avatar fw42 avatar girasquid avatar nvasilevski avatar ryanseys avatar sunblaze avatar wvanbergen avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.