Use MySQL workbench to create tables and data for rails app - mysql

Can I use MySQL Workbench to create the tables and add data then import / connect that into my Rails app? My Rails app is already connected to MySQL. I am just wondering if I create tables in MySQL Workbench through the app_development schema if that will sync over to my Rails project or not and if there's a way to check to see if it worked?

You can use
rake db:schema:dump
to generate schema.rb from an existing database.
Having schema.rb, you can generate an empty initial migration and put create_table and other statements from generated schema there. Doing this will allow you to use all the relevant rake tasks just as if you developed your database "the Rails way" — via a series of migrations.

Related

Why does Cucumber drop tables if schema.rb is not present?

I have a Rails 4 app that uses an external DB I don't control. So there is no schema or migration. Anyway, I create a model and use db setting the table_name in the model.
When I run cucumber it drops the db tables!?
Any idea why and how to avoid it?
$ bundle exec cucumber
Running via Spring preloader in process 18865
.../db/schema.rb doesn't exist yet. Run `rake
db:migrate` to create it, then try again. If you do not intend to use a
database, you should instead alter
.../config/application.rb to limit the frameworks that
will be loaded.
After that the db is empty, no tables.
You should still be able to dump your schema locally if ActiveRecord is connecting to the db.
rake db:schema:dump

how to create migration for already exist table in rails

I have deleted the migration files in rails project. Now i want run the rails project in another system for that i need the migration files to create the table. please tell me how to create the migration files for already created tables in rails.
You still have db/schema.rb file containing all tables and their details..you can use it by rake db:schema:load,this will load the schema into the database, which is faster than running all the migrations.
NEVER DELETE YOUR MIGRATION AND MAINTAIN IT IN SUBVERSION/GIT

migrating rails app from postgresql to mysql

I'm attempting to migrate my rails application from postgresql to mySQL so as to view the data in one place within xampp in PHPmyadmin. The reason is the fact that I need to access the data that is located within the MySQL database from my rails app which is in postgresql.
As of now most questions I found aim to create a new application within mySQL with rails but I need to migrate all of the data my current rails application compatible and use MySQL.
Is there a proper process and simple procedure that allows for this migration from postgresql to mySQL?
Note: MySQL is within xampp
this post
got the answer to your question.
It's very easy, just paste your postgres dump in this website and you'll get the same dump converted in mysql, ready for you to be imported.
Then you will just need to properly configure your database.yml and you're set.

Connecting already existing MySQL table to already existing Scaffold

So, I know that it is certainly possible to connect an already-existing MySQL database to a completely new Rails application through rake db:schema:dump and by configuring the database.yml file, as shown in a couple of Stack Overflow questions and through this blog: Ruby on Rails Tutorial: Creating a Rails Instance from an Existing MySQL DB.
However, is it possible to link an already existing scaffold in Rails 4.1 - one that is generated through say,
rails g scaffold person \
firstname:string lastname:string gender:string age:integer
(and this scaffold is generated with the default SQLite setting), and say you have a MySQL database on AWS named people with columns firstname:string lastname:string age:integer.
Is there some way to link up the rails app to this existing database in such a case?

Easiest way to port a data model to Rails migration

I have designed a data model which has almost 24 tables. I have finished specifying the relations and all the data types are finalized. Now, I want to convert it to migrations in Rails.
I have all the scripts ready for it to be created in MySQL. Is there any tool that converts all the table creation queries into a single Rails migration file?
Thanks
I haven't done it myself but according to this post on the ruby forums
rake db:schema:dump
should be sufficient (delete the schema.rb beforehand).
The almost same question here on SO: Ruby / Rails - Reverse Migration - DDL to Ruby Code