Translate existing Rails database into seed data file - mysql

Is it possible to build a seed data file from an existing mysql database?
I know how to populate a new database with all the tables from an existing database. I'm curious if its possible to build a seed file (seed.rb) from a db.

Try this https://github.com/ludicast/yaml_db
Should provide all the abilities you're looking for.

There are a few gems for the purpose of extracting seeds from an existing database. You could try seed_dump, for instance.

Related

Generate migration from MySQL schema

converting a project and looking for a way to connect to DB schema, read it and generate knexJS migration files to integrate in new project.
Is there a way to do this? and how?
No, there is no way to extract migration file for current schema of some database. If you really want to create one, it must be written manually.
But you don't even need one. You can just start using knex, with your old database dump and in the future when there should be changes done to the schema you can write new migrations for those specific incremental changes to the schema.
For running migrations you should use knex's migration functionality.

SaaS application on shared server with multiple databases

I am going to create a SaaS application in PHP. In that application the user can create and manage multiple tables to extend functionality. After user finish with the application he can download php code and database.
We will also provide sql import functionality so the user can create schema from (.sql) file.
I search on google but not found any proper solution. You can consider sqlfiddle functionality here.
I have 2 options in my mind but need better solution:
1) For creating multiple database and its tables, use table prefix as a solution
2) Convert mysql to sqlite. At the time of download create export as mysql (.sql) file.
It can have aprox. 10,000 users/databases. Please suggest a solution to provide each user a seperate database if any.
If shared server will not work I will purchase VPS. The main requirement is to provide each user their own database.
I am going to choose sqlite as a choice for db. After doing some benchmark sqlite seems good option for DDL and DML operation.
I will use mysql to sqlite .sql converter: https://github.com/sutara79/convert-mysql-to-sqlite
To improve the speed I follow following stackoverflow post:
Improve INSERT-per-second performance of SQLite?

NodeJS application database versioning and data migration

I am planning to use Postgres as my database and sequelize as my ORM framework one of my NodeJS project. I need your suggestion on how to accomplish database table changes in production enviroment.
For example , we deployed our version-1 application with some database schema.
Later , there is a change in my schema in Version-2. Say one of the table is altered and few columns are dropped and few columns are added.
Also one of the table itself is not required in Version-2.
In my production , I have some database with data. When I install Version-2 of my NodeJS application , I need to keep the old data as it is and apply the new database schema of Version-2.
How to achieve this , Let me point out some reference to this.
Thanks
Sequelize (or rather, sequelize-cli) has built in support for migrations.
You can write migrations using the Sequelize js api (e.g. queryInterface.dropColumn('users', 'address')) or write raw SQL and pass it to sequelize.query()

Grails with CSV (No DB)

I have been building a grails application for quite a while with dummy data using MySQL server, this was eventually supposed to be connected to Greenplum DB (postgresql cluster).
But this is not feasible anymore due to firewall issues.
We were contemplating connecting grails to a CSV file on a shared drive( which is constantly updated by greenplum DB, data is appended hourly only)
These CSV files are fairly large(3mb, 30mb and 60mb) The last file has 550,000+ rows.
Quick questions:
Is this even feasible? Can CSV be treated as a database and can grails directly access this CSV file and run queries on it, similar to that of a DB?
Assuming this is feasible, how much rework will be required in the grails codes in Datasource, controller and index ( Currently, we are connected to Mysql and we filter data in controller and index using sql queries and ajax calls using remotefunction)
Will the constant reading( csv -> grails ) and writing (greenplum -> csv) render the csv file corrupt or bring up any more problems?
I know this is not a very robust method, but I really need to understand the feasibility of this idea. Can grails function wihtout any DB and merely a CSV file on a shared drive accesssible to multiple users?
The short answer is, No. This won't be a good solution.
No.
It would be nearly impossible, if at all possible to rework this.
Concurrent access to a file like that in any environment is a recipe for disaster.
Grails is not suitable for a solution like this.
update:
Have you considered using the built in H2 database which can be packaged with the Grails application itself? This way you can distribute the database engine along with your Grails application within the WAR. You could even have it populate it's database from the CSV you mention the first time it runs, or periodically. Depending on your requirements.

Migrate Grail's HSQLDB embedded database

how to migrate Grail's HSQLDB embedded database(That contains my App's Data that I don't want to lose) into external one, such as MySQL or ApacheDerby?
If your data isn't important just let hibernate regenerate your schema, else try this: http://www.grails.org/plugin/liquibase
The MySQL Migration Toolkit may be exactly what you need.
A little searching turned up this article that shows examples of what the GUI Tool looks like.
I haven't had to migrate data from a HSQLDB to any other DB, but if I had data that I didn't want to use in a HSQLDB then I'd definitely try this method.
You are going to want to backup the
HSQLDB database that you want to save
(I'm assuming you used a file DB
rather than an in-memory one right?)
Change your DataSource to a MySQL
datasource with the dbCreate set to
update (or something non-destructive)
Run the Migration Toolkit and migrate
your data
Otherwise you ought to be able to view the data in your DB by using another tool (DBVisualizer, RazorDB, or others) and they might be able to help you export the data.
Because grails uses hibernate underneath, no migration is necessary. All you need to do is repoint your conf\DataSources.groovy to the new database, and next time you startup, it will create tables in the new DB.
See section 3.3 in this doc for more information on MySQL config.