CSV to SQL
- Get repository
git clone https://github.com/santannalucas/csv_importer.git
- Ruby version
This app uses Ruby 3.0.0 and Rails ~> 7.0, be sure to change you version manager to version 3 and that you have rails 7 installed:
user@ubuntu:~/csv_importer$ rvm use ruby-3.0.0
Using /home/user/.rvm/gems/ruby-3.0.0
user@ubuntu:~/csv_importer$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
user@ubuntu:~/csv_importer$ rails -v
Rails 7.0.4.2
user@ubuntu:~/csv_importer$ bundle install
- Database creation
Application use PostgreSQL Database, configuration should look like this:
# PostgreSQL 10
default: &default
adapter: postgresql
host: localhost
username: lucas
password: password
production:
<<: *default
database: exercise
development:
<<: *default
database: exercise_dev
test:
<<: *default
database: exercise_test
- Database initialization
rake db:create
rake db:migrate
- Running Application
To run applications just start the server:
user@ubuntu:~/csv_importer$ rails s
And then open localhost on you browser (preferable Chrome) http://127.0.0.1:3000
- Test Unit
You can ran the test unit as per below:
user@ubuntu:~/csv_importer$ rails test
As a user, I should be able to upload this sample CSV and import the data into a database.
a. The data needs to load into 3 tables. People, Locations and Affiliations
b. A Person can belong to many Locations
c. A Person can belong to many Affiliations
d. A Person without an Affiliation should be skipped
e. A Person should have both a first_name and last_name. All fields
need to be validated except for last_name, weapon and vehicle which are optional.
f. Names and Locations should all be titlecased
-
User Cases
- As a user, I should be able to view these results from the importer in a table.
- As a user, I should be able to paginate through the results so that I can see a maximum of 10 results at a time.
- As a user, I want to type in a search box so that I can filter the results I want to see.
- As a user, I want to be able to click on a table column heading to reorder the visible results.
-
Assumptions
- Person First Name and Last Name will be used to find existing record and update if exist or create if it doesn't (UPSERT)
- Special Characters are allowed.
- Requirements says that a person should have both first and last name, but last_name is optional. So uniqueness was created for both. As result only one Person can have a name with no last_name.