百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

schema_validations

> 编程语言
开源

根据数据库模式自动创建验证。

174 stars0 点赞5 次浏览
访问官网GitHub

工具介绍

根据数据库模式自动创建验证。

SchemaValidations

SchemaValidations is an ActiveRecord extension that keeps your model class definitions simpler and more DRY, by automatically defining validations based on the database schema.

Overview

One of the great things about Rails (ActiveRecord, in particular) is that it inspects the database and automatically defines accessors for all your columns, keeping your model class definitions simple and DRY. That's great for simple data columns, but where it falls down is when your table contains constraints.

ruby
create_table :users do |t|
    t.string :email, null: false, limit: 30
    t.boolean :confirmed, null: false
end

In that case the constraints null: false, limit: 30 and :boolean must be validated on the model level, to avoid ugly database exceptions:

ruby
class User true, :maximum=>50

which shows the exact validation definition call.

SchemaValidations defines the validations lazily for each class, only creating them when they are needed (in order to validate a record of the class, or in response to introspection on the class). So you may need to search through the log file for "schema_validations" to find all the validations, and some classes' validations may not be defined at all if they were never needed for the logged use case.

Compatibility

As of version 1.2.0, SchemaValidations supports and is tested on:

  • ruby 2.5 with activerecord 5.2, using mysql2, postgresql:9.6 or sqlite3
  • ruby 2.5 with activerecord 6.0, using mysql2, postgresql:9.6 or sqlite3
  • ruby 2.5 with activerecord 6.1, using mysql2, postgresql:9.6 or sqlite3
  • ruby 2.7 with activerecord 5.2, using mysql2, postgresql:9.6 or sqlite3
  • ruby 2.7 with activerecord 6.0, using mysql2, postgresql:9.6 or sqlite3
  • ruby 2.7 with activerecord 6.1, using mysql2, postgresql:9.6 or sqlite3
  • ruby 2.7 with activerecord 7.0, using mysql2, postgresql:9.6 or sqlite3
  • ruby 3.0 with activerecord 6.0, using mysql2, postgresql:9.6 or sqlite3
  • ruby 3.0 with activerecord 6.1, using mysql2, postgresql:9.6 or sqlite3
  • ruby 3.0 with activerecord 7.0, using mysql2, postgresql:9.6 or sqlite3
  • ruby 3.1 with activerecord 6.0, using mysql2, postgresql:9.6 or sqlite3
  • ruby 3.1 with activerecord 6.1, using mysql2, postgresql:9.6 or sqlite3
  • ruby 3.1 with activerecord 7.0, using mysql2, postgresql:9.6 or sqlite3

Earlier versions of SchemaValidations supported:

  • rails 3.2, 4.1, and 4.2.0
  • MRI ruby 1.9.3 and 2.1.5

Release Notes

2.4.1

  • Add AR 6.1 and 7.0
  • add ruby 3.1

2.4.0

  • Add AR 6.0
  • Add Ruby 3.0
  • Remove support for AR = 4.2.1

1.1.0

  • Works with Rails 4.2.

1.0.1

  • Fix enums in Rails 4.1. Thanks to @lowjoel

1.0.0

  • Works with Rails 4.0. Thanks to @davll
  • No longer support Rails < 3.2 or Ruby < 1.9.3

0.2.2

  • Rails 2.3 compatibility (check for Rails::Railties symbol). thanks to https://github.com/thehappycoder

0.2.0

  • New feature: ActiveRecord#validators and ActiveRecord#validators_on now ensure schema_validations are loaded

History

  • SchemaValidations is derived from the "Red Hill On Rails" plugin schema_validations originally created by harukizaemon (https://github.com/harukizaemon)

  • SchemaValidations was created in 2011 by Michał Łomnicki and Ronen Barzel

Testing

Are you interested in contributing to schema_validations? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.

Some things to know about to help you develop and test:

  • schema_dev: SchemaValidations uses schema_dev to facilitate running rspec tests on the matrix of ruby, activerecord, and database versions that the gem supports, both locally and on github actions

    To to run rspec locally on the full matrix, do:

      $ schema_dev bundle install
      $ schema_dev rspec

    You can also run on just one configuration at a time; For info, see schema_dev --help or the schema_dev README.

    The matrix of configurations is specified in schema_dev.yml in the project root.

Code coverage results will be in coverage/index.html -- it should be at 100% coverage.

License

This gem is released under the MIT license.

Issues· 20 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言