Skip to content

Commit 0808b55

Browse files
authored
Merge pull request #255 from espoo-dev/feat-development-seeds
Feat development seeds
2 parents 39b1664 + be40caa commit 0808b55

22 files changed

+472
-53
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@
3939
# Ignore all environment files (except example).
4040
/.env*
4141
!.env.example
42+
43+
lib/data/procedures/

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
## Getting Started
99

1010
- create a .env file based on .env.example and copy the content of .env.example to .env (`$ cp .env.example .env`)
11-
- docker compose build
12-
- docker compose run web bundle install
13-
- docker compose run web bin/rails db:setup
14-
- bin/dev
11+
- run `docker compose build`
12+
- run `docker compose up -d`
13+
- run `docker compose exec web bin/setup`
14+
- run `bin/dev`
1515
- visit http://localhost:3000/
1616

1717
## Run tests

db/seeds.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
# Not proud of, but we are using this as a place to run scripts,
44
# since we can't run rake tasks or access console on render free version
55

6-
# Rails.logger.debug "Seeding default data..."
7-
# Dir[Rails.root.join("db/seeds/*.rb")].each do |seed|
8-
# load seed
9-
# end
6+
if Rails.env.development?
7+
Rails.logger.debug "Seeding data..."
8+
Dir[Rails.root.join("db/seeds/*.rb")].each do |seed|
9+
load seed
10+
end
11+
else
12+
Rails.logger.debug { "Skipping seed data loading in #{Rails.env} environment" }
13+
end
1014

1115
# Rails.logger.debug { "Seeding #{Rails.env} data..." }
1216
# Dir[Rails.root.join("db/seeds", Rails.env, "*.rb")].each do |seed|

db/seeds/01_users.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
Rails.logger.debug "1. Creating User..."
4+
5+
user = User.create!(
6+
email: "user@email.com",
7+
password: "qwe123",
8+
password_confirmation: "qwe123"
9+
)
10+
Rails.logger.debug { "Created User with email: #{user.email}" }
11+
Rails.logger.debug { "User's password: #{user.password}" }

db/seeds/02_procedures_default.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
Rake::Task.clear
4+
Rails.application.load_tasks
5+
6+
Rails.logger.debug "2. Creating default Procedures..."
7+
8+
Rake::Task["port_values_2008:import"].invoke
9+
Rake::Task["procedures:create_json_file"].invoke("lib/data/procedures.csv", 100)
10+
11+
batch_files = Rails.root.glob("lib/data/procedures/batch_*.json")
12+
13+
if batch_files.empty?
14+
Rails.logger.debug "No JSON files found."
15+
else
16+
batch_files.each do |batch_file|
17+
next unless File.exist?(batch_file)
18+
19+
Rails.logger.debug { "Importing #{batch_file}" }
20+
21+
Rake::Task["procedures:persist_in_database"].invoke(batch_file)
22+
Rake::Task["procedures:persist_in_database"].reenable
23+
end
24+
end
25+
26+
Rails.logger.debug { "Created #{batch_files.count} default Procedures!" }

db/seeds/03_procedures_custom.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
Rails.logger.debug "8. Creating custom Procedure..."
4+
5+
user = User.last
6+
procedure = Procedure.create!(
7+
name: "Procedure A CUSTOM",
8+
code: "123",
9+
amount_cents: 12_345,
10+
description: "Desc A",
11+
custom: true,
12+
user_id: user.id
13+
)
14+
Rails.logger.debug { "Created custom Procedure: #{procedure.name} (#{procedure.code})" }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
Rails.logger.debug "4. Creating default Health Insurances..."
4+
35
health_insurance_data = [
46
"São Camilo",
57
"ISSEC",
@@ -15,3 +17,5 @@
1517
health_insurance_data.each do |name|
1618
HealthInsurance.create!(name: name)
1719
end
20+
21+
Rails.logger.debug { "Created #{health_insurance_data.count} default Health Insurances..." }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
Rails.logger.debug "7. Creating custom Health Insurance..."
4+
5+
user = User.last
6+
health_insurance = HealthInsurance.create!(
7+
name: "Plano de saude CUSTOM",
8+
custom: true,
9+
user_id: user.id
10+
)
11+
Rails.logger.debug { "Created custom Health Insurance: #{health_insurance.name}" }

db/seeds/06_hospitals.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
Rails.logger.debug "5. Creating Hospital..."
4+
5+
hospital = Hospital.create!(
6+
name: "Hospital A",
7+
address: "A St."
8+
)
9+
Rails.logger.debug { "Created Hospital: #{hospital.name}" }

db/seeds/07_patients.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
Rails.logger.debug "6. Creating Patient..."
4+
5+
user = User.last
6+
patient = Patient.create!(
7+
name: "Paciente Usuario 1",
8+
user_id: user.id
9+
)
10+
Rails.logger.debug { "Created Patient: #{patient.name}" }

0 commit comments

Comments
 (0)