Commit 11e9f11d authored by Arthur Del Esposte's avatar Arthur Del Esposte 🤘🏻
Browse files

Add component:seed task to populate database through seed files

parent 17797872
Pipeline #3539731 failed with stage
in 3 minutes and 41 seconds
......@@ -42,10 +42,15 @@ To set the three required URL, edit the [services config file](config/services.y
### Resource and Components
In order to automatically populate the database with resource and components data we recommend that you use the [resource config file](config/resource.yml). See the [file](config/resource.yml) to undestand how to add data. After this, run the task to create components in database:
In order to automatically populate the database with resource and components data we recommend that you use the one of the following methods:
* Create components data through [resource config file](config/resource.yml). See the [file](config/resource.yml) to undestand how to add data. After this, run the task to create components in database:
```$ bundle exec rake component:create```
* Create components data through seed files. See the [existing seed files](lib/seeds/) to understand hot to create your own script. After this, run the task to create components in database:
** To run all seed files: ```$ bundle exec rake component:seed```
** To run a specific seed file: ```$ bundle exec rake component:seed[my_file_name.rb]```
You can also use alternative ways to populate the database with your informantion. You could add new fields or table by adding new migrations or create your own scripts to populate the database, for instance.
......@@ -5,7 +5,7 @@
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
adapter: postgresql
encoding: unicode
pool: 5
timeout: 100000
......
......@@ -18,6 +18,8 @@ namespace :component do
desc 'Create components with lib/seeds scripts'
task :seed, [:file_name, :needs] => [:environment] do |t, args|
resource = BasicResource.first.nil? ? BasicResource.create! : BasicResource.first
if args[:file_name]
system("bundle exec rails runner #{Rails.root.join('lib/seeds', args[:file_name])}")
else
......@@ -25,6 +27,8 @@ namespace :component do
system("bundle exec rails runner #{file}")
end
end
Component.update_all(basic_resource_id: resource.id)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment