xronos-ch / xronos.rails

Ruby on Rails application powering XRONOS, an open infrastructure for chronometric data from archaeological contexts worldwide
https://xronos.ch
MIT License
4 stars 0 forks source link

Add admin CLI for importing tabular datasets #341

Open joeroe opened 3 weeks ago

joeroe commented 3 weeks ago

Until we get the graphical interface up and running.

joeroe commented 2 weeks ago

Had a quick look at this today. My plan of attack would be:

  1. Clean up the ImportTable model so it's self-contained and can be used comfortably from the command line (currently there's a lot of input parsing logic that gets in the way and belongs in the controller)
  2. Define an ActiveJob that does the actual import and logs the results back to the ImportTable
  3. Add a method to ImportTable that creates the job

At that point we could either just stick with running it from the Rails console in production, which would look something like:

Paper trail.set_whodunnit_user(...)
import_table = ImportTable.create_and_save('file.csv', ...)
import_table.import

Which is not too bad. Or wrap it in a rake task or use one of the gems available for this kind of script management. Though I looked at the rake option and the syntax for passing parameters is not pretty.