Project

nullalign

0.02
No commit activity in last 3 years
No release in over 3 years
If you have a presence validation, you'll probably want a non-null constraint to go with it.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.2
~> 1.3
 Project Readme

Nullalign

Description

nullalign is a tool to detect missing non-null constraints in Rails projects.

Suppose you have a validation like this:

validates :email, presence: true

Do you have a non-null constraint in your database to back that up? If not, nullalign will find it for you.

Nullalign is based on Colin Jones' consistency_fail. I mean really really based on it, as in I copied and pasted over a bunch of the code and changed the module and file names. And a lot of this README, too.

Installation

Put this in the development group in your Gemfile

gem 'nullalign'

Usage

Run it like this:

bundle exec nullalign

Example output

There are presence validators that aren't backed by non-null constraints.
--------------------------------------------------------------------------------
Model              Table Columns
--------------------------------------------------------------------------------
Album              albums: name, owner_id
AttendanceRecord   attendance_records: group_id, attended_at
CheckinLabel       checkin_labels: name, xml
CheckinTime        checkin_times: campus

Generating a migration

You can also run a Rake task which will generate a migration which will add indexes as needed:

bundle exec rake nullalign:fix

Limitations

nullalign depends on being able to find all your ActiveRecord::Base subclasses with some $LOAD_PATH trickery. If any models are in a path either not on your project's load path or in a path that doesn't include the word "models", nullalign won't be able to find or analyze them. I'm open to making the text "models" configurable if people want that. Please open an issue or pull request if so!

To disable nullalign, I could add a thing that checks column comments for a string like 'nonullalign' if people think that would be useful. Just let me know.

Contributors

Tests

You can run the tests with:

bundle exec rspec

License

Released under the MIT License. See the LICENSE file for further details.