I have an sql file with respective create table statements (and columns, keys etc.). Is there a way to automatically generate models (if not even scaffolds) from this?
Thanks in advance
-
Rails doesn't have anything out of the box that will do this for you. You could always write a custom generator to parse the sql file and create models. guides.rubyonrails.org/generators.htmlSean Huber– Sean Huber2016-12-29 14:42:29 +00:00Commented Dec 29, 2016 at 14:42
2 Answers
You may want to check out the schema_to_scaffold gem
This Gem generates Rails command strings based on a Rails database schema you already have. Unlike traditional migrations, which modify the database as they generate Rails scaffolding code, this Gem reads the schema for your database and generates the Rails code which matches your database's existing columns.
You could manually use sql file create database.
Simple way is use sqlite, it's easier to setup.
cat db.sql | sqlite3 db/development.sqlite3
Then run rake db:schema:dump to dump database to schema in Rails.