{"id":13601949,"url":"https://github.com/twopoint718/reactive_record","last_synced_at":"2026-03-17T21:34:56.465Z","repository":{"id":6740882,"uuid":"7987113","full_name":"twopoint718/reactive_record","owner":"twopoint718","description":"Generate ActiveRecord models for a pre-existing Postgres db","archived":false,"fork":false,"pushed_at":"2021-11-26T17:37:38.000Z","size":85,"stargazers_count":131,"open_issues_count":6,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-11T21:02:18.845Z","etag":null,"topics":["activerecord-models","constraints","database","postgres","postgres-db","rails","ruby","sql"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twopoint718.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-03T06:13:51.000Z","updated_at":"2024-02-04T11:03:30.000Z","dependencies_parsed_at":"2022-08-26T13:02:05.441Z","dependency_job_id":null,"html_url":"https://github.com/twopoint718/reactive_record","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twopoint718%2Freactive_record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twopoint718%2Freactive_record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twopoint718%2Freactive_record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twopoint718%2Freactive_record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twopoint718","download_url":"https://codeload.github.com/twopoint718/reactive_record/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223458739,"owners_count":17148511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord-models","constraints","database","postgres","postgres-db","rails","ruby","sql"],"created_at":"2024-08-01T18:01:10.454Z","updated_at":"2025-12-30T00:36:38.296Z","avatar_url":"https://github.com/twopoint718.png","language":"Ruby","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.github.com/twopoint718/reactive_record/master/img/reactive_record.png\"\n      alt=\"Reactive record logo\"\u003e\n  \u003cbr\u003e\n  \u003ci\u003eLogo design: \u003ca href=\"https://www.linkedin.com/in/kelly-rauwerdink-80615041\"\u003eKelly Rauwerdink\u003c/a\u003e,\n    \u003ca href=\"https://twitter.com/missingdink\"\u003e@missingdink\u003c/a\u003e,\n    \u003ca href=\"https://missingdink.dribbble.com\"\u003eDribbble\u003c/a\u003e.\n  \u003c/i\u003e\n\u003c/p\u003e\n\n[![Gem Version](https://badge.fury.io/rb/reactive_record.png)](http://badge.fury.io/rb/reactive_record)\n\nGenerates ActiveRecord models to fit a pre-existing Postgres database.\nNow you can use Rails with the db schema you always wanted. It's\n**your** convention over configuration.\n\n## Why?\n\n1. Your app is specific to Postgres and proud of it. You use the mature\n   declarative data validation that only a real database can provide.\n1. You have inherited a database or are more comfortable creating one\n   yourself.\n1. You're a grown-ass DBA who doesn't want to speak ORM baby-talk.\n\n## Features\n\n* Fully automatic. It just works.\n* Creates a model for every table.\n* Creates a comprehensive initial migration.\n* Declares key-, uniqueness-, and presence-constraints.\n* Creates associations.\n* Adds custom validation methods for `CHECK` constraints.\n\n## Usage\n\n### Already familiar with Rails?\n\n* Set up a postgres db normally\n* Set `config.active_record.schema_format = :sql` to use a SQL `schema.rb`\n* After you have migrated up a table, use `rails generate reactive_record:install`\n* Go examine your generated models\n\n### Want more details?\n\n**First** Include the `reactive_record` gem in your project's\n`Gemfile`. *Oh by the way*, you'll have to use postgres in your\nproject. Setting up Rails for use with postgres is a bit outside\nthe scope of this document. Please see [Configuring a Database]\n(http://guides.rubyonrails.org/configuring.html#configuring-a-database)\nfor what you need to do.\n\n``` ruby\ngem 'reactive_record'\n```\n\nBundle to include the library\n\n``` shell\n$ bundle\n```\n\n**Next** Tell `ActiveRecord` to go into beast-mode. Edit your\n`config/application.rb`, adding this line to use sql as the schema\nformat:\n\n``` ruby\nmodule YourApp\n  class Application \u003c Rails::Application\n    # other configuration bric-a-brac...\n    config.active_record.schema_format = :sql\n  end\nend\n```\n\n**Next** Create the database(s) just like you normally would:\n\n``` shell\nrake db:create\n```\n\n**Next** Generate a migration that will create the initial table:\n\n``` shell\n$ rails generate migration create_employees\n```\n\nUse your SQL powers to craft some\n[DDL](http://en.wikipedia.org/wiki/Data_definition_language), perhaps\nthe \"Hello, World!\" of DB applications, `employees`?\n\n``` ruby\nclass CreateEmployees \u003c ActiveRecord::Migration\n  def up\n    execute \u003c\u003c-SQL\n      CREATE TABLE employees (\n        id         SERIAL,\n        name       VARCHAR(255) NOT NULL,\n        email      VARCHAR(255) NOT NULL UNIQUE,\n        start_date DATE NOT NULL,\n\n        PRIMARY KEY (id),\n        CONSTRAINT company_email CHECK (email LIKE '%@example.com')\n      );\n    SQL\n  end\n\n  def down\n    drop_table :employees\n  end\nend\n```\n\n**Lastly** Deploy the `reactive_record` generator:\n\n``` shell\n$ rails generate reactive_record:install\n```\n\nGo look at the generated file:\n\n``` ruby\nclass Employees \u003c ActiveRecord::Base\n  set_table_name 'employees'\n  set_primary_key :id\n  validate :id, :name, :email, :start_date, presence: true\n  validate :email, uniqueness: true\n  validate { errors.add(:email, \"Expected TODO\") unless email =~ /.*@example.com/ }\nend\n```\n\nReactive record does not currently attempt to generate any kind of\nreasonable error message (I'm working on it) :)\n\n**Enjoy**\n\n## Credits\n\nFirstly, thank you,\n[contributors](https://github.com/twopoint718/reactive_record/graphs/contributors)!\n\nAlso a special thanks to Joe Nelson,\n[@begriffs](https://github.com/begriffs), for contributions and\ninspiration; Reactive Record would not exist without his efforts. Thanks to [Bendyworks](http://bendyworks.com/) for the 20%\ntime to work on this project!\n\nAnd, of *course*, a huge thank you to \u003ca href=\"https://www.linkedin.com/in/kelly-rauwerdink-80615041\"\u003eKelly Rauwerdink\u003c/a\u003e for her amazing ability to make \"an art\" even when all I can do is sorta half-articulate what I'm talking about. Thanks!\n\n![Footer](img/bendyworks_github_footer.png)\n","funding_links":[],"categories":["Web 后端","Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwopoint718%2Freactive_record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwopoint718%2Freactive_record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwopoint718%2Freactive_record/lists"}