Created
April 3, 2020 16:08
-
-
Save nightcrawler-/df333934187c30f50167462d52af1fb5 to your computer and use it in GitHub Desktop.
Load seeds from a json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file should contain all the record creation needed to seed the database with its default values. | |
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). | |
# | |
# Examples: | |
# | |
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | |
# Character.create(name: 'Luke', movie: movies.first) | |
# Seed file: | |
# /home/frederick/Dev/data/legacy-medexam | |
# | |
# id :bigint not null, primary key | |
# address :string | |
# email :string | |
# location :string | |
# name :string | |
# phone :string | |
# registration :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# practitioner_id :bigint | |
# | |
# address :string | |
# dob :date | |
# gender :integer | |
# name :string | |
# pn :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# national_id :string | |
# workplace_id :bigint | |
# address :string | |
# email :string | |
# fax :string | |
# location :string | |
# name :string | |
# phone :string | |
# registration :string | |
# signature :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
practitioner = Practitioner.create!( | |
address: "P.O. Box 3310-10200, Lisbit", | |
email: "[email protected]", | |
fax: "10005", | |
location: "Nauru", | |
name: "Lizzy Caplan", | |
phone: "072300564", | |
registration: "W1590" | |
) | |
workplaces = JSON.parse(File.read('/home/frederick/Dev/data/legacy-medexam/workplace-employees.json')) | |
workplaces.each do |w| | |
workplace = Workplace.create!( | |
name: w["name"], | |
address: w["address"], | |
email: w["email"], | |
location: w["location"], | |
phone: w["phone"], | |
registration: w["registration"], | |
practitioner_id: practitioner.id | |
) | |
w["employees"].each do |e| | |
employee = Employee.create!( | |
name: e["name"], | |
dob: e["dob"], | |
gender: e["gender"], | |
pn: e["pn"], | |
national_id: e["national_id"], | |
workplace_id: workplace.id | |
) | |
workplace.employees << employee | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file should contain all the record creation needed to seed the database with its default values. | |
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). | |
# | |
# Examples: | |
# | |
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | |
# Character.create(name: 'Luke', movie: movies.first) | |
# Seed file: | |
# /home/frederick/Dev/data/legacy-medexam | |
# | |
# id :bigint not null, primary key | |
# address :string | |
# email :string | |
# location :string | |
# name :string | |
# phone :string | |
# registration :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# practitioner_id :bigint | |
# | |
# address :string | |
# dob :date | |
# gender :integer | |
# name :string | |
# pn :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# national_id :string | |
# workplace_id :bigint | |
# address :string | |
# email :string | |
# fax :string | |
# location :string | |
# name :string | |
# phone :string | |
# registration :string | |
# signature :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
practitioner = Practitioner.create!( | |
address: "P.O. Box 3310-10200, Lisbit", | |
email: "[email protected]", | |
fax: "10005", | |
location: "Nauru", | |
name: "Lizzy Caplan", | |
phone: "072300564", | |
registration: "W1590" | |
) | |
workplaces = JSON.parse(File.read('/home/frederick/Dev/data/legacy-medexam/workplace-employees.json')) | |
workplaces.each do |w| | |
workplace = Workplace.create!( | |
name: w["name"], | |
address: w["address"], | |
email: w["email"], | |
location: w["location"], | |
phone: w["phone"], | |
registration: w["registration"], | |
practitioner_id: practitioner.id | |
) | |
w["employees"].each do |e| | |
employee = Employee.create!( | |
name: e["name"], | |
dob: e["dob"], | |
gender: e["gender"], | |
pn: e["pn"], | |
national_id: e["national_id"], | |
workplace_id: workplace.id | |
) | |
workplace.employees << employee | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment