Question

I see that there is a folder for database seeds and a command for it but I couldn't find any documentation on how it works. Can someone help?

Was it helpful?

Solution

I'm sure this is a little late for an answer, but if you haven't found one yet, here goes.

To create seeds:

railway seed harvest 

The keyword harvest will invoke the railway app so that it creates seeds based on whatever you currently have in the database. As for where this goes, depending on what environment you have set, eg development, production, etc, it will place you seed files like so:

root/db/seeds/[environment]/[model].coffee

...where [model] is your model (User, Post, Account, etc), and [environment] is your environment (development, test, production, etc).

To seed the database:

railway seed

The documentation is a little light on seeding right now.

OTHER TIPS

This is an old question and the RailwayJS framework is now called CompoundJS but Johnny's advice still works. For anyone looking for a bit more detail this might help.

db/schema.js

var Country = describe('Country', function () {
    property('name', String);
    set('restPath', pathTo.countries);
});

db/seeds/development/country.js

console.log('Seeding countries...');

var countries = [{
    name: 'Canada'
}, {
    name: 'USA'
}];

countries.forEach(function(obj) {
    Country.create(obj, function(country) {
        console.log('Added: ', country);
    });  
});

Then run:

$ compound seed
Seeding countries...
Added: { name: 'Canada', id: 1 }
Added: { name: 'USA', id: 2 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top