Rails Exporter Plugin
Seeds file
http://rails.kirschekreativ.de/seeds-file.html

Copyright © 2013 Joerg Kirschstein

 

Seeds file

Rails Exporter Plugin works as a seeds generator. It creates ruby code to fill each table with valid data.

The following Workbench attributes are supported and considered during the creation:

COMMENTS
Table comments are converted into ruby comments.

DEFAULT VALUES
Sets all default values, if valid.

FOREIGN KEYS
Foreign keys are used in the CREATE command of rails data rows. 1:1, 1:n: the referenced columns are filled with a releating parent object by random. n:m: creates additional join tables, filled with a related object by random. polymorphic: uses random relation from multiple referenced tables.

LIMIT
Limit values are considered.

UNIQUE
Unique values are considered, Rails Exporter tries to change the value to a unqiue one. If it fails after several attempts, the seed creation for that table ends. Relations and indices are considered in a dynamic created ruby routine.

SORT
Before creating the rails files, the tables are checked [and renamed to "_y", if double or a prefix is added, if it starts with a number ("60">"a60")] and keys are memorized. By that, Rails Exporter Plugin sorts the tables for correct seeds creation. For example: all tables that are only child tables of a relation, but are not parents, are sorted to the end, and vice versa.

SEED VALUES
Depending on the rails field type, the seed values are created as follows:

INTEGER
Random number between 1 and 100.000

STRING
Random Word plus a random length-random number prefix. [e.g. Marillion_1981]

BINARY
Fixed graphic pixel binary coded value

BOOLEAN
Random T(rue) or F(alse)

TEXT
Random Word plus a random length-random number prefix. [e.g. Marillion_1982], max length 256

FLOAT
Random decimal value between 1,1 and 100000,999

DECIMAL
Random decimal value between 1,1 and 100000,999999

DATE
Random date between [1971-12-04 and 2013-12-04]

TIME
Random time between [00:00:00.000 and 23:59:00.000]

DATETIME
Random datetime between [1971-12-04 23:00:00.000 and 2013-12-04 23:59:59.000]

The seeds actions are displayed in the command line/console, ending with a finished message. You may alter the seeds logic and content to your own needs in the lua script source code of the plugin.

Rails Exporter Plugins converts MySQL columnd types to rails types:

  • INT, INTEGER, NUMERIC, TINYINT, BIGINT, SMALLINT, MEDIUMINT, BIT > INTEGER
  • FLOAT, DOUBLE > FLOAT
  • DECIMAL > DECIMAL
  • BOOLEAN, BOOL > BOOLEAN
  • TIME > TIME
  • DATE > DATE
  • DATETIME, TIMESTAMP > DATETIME
  • BINARY, BLOB > BINARY
  • TEXT > TEXT
  • VARCHAR, YEAR, ENUM and everything else as a default > STRING