-
Notifications
You must be signed in to change notification settings - Fork 9
Import records from CSV files
-
On the same server where your Rails app is running, create a directory to put your CSV and supporting files into. You will pass this directory to the import script, and it will parse all the CSV files it finds within that directory. For supporting files, such as images or audio files, you can organize them into sub-directories if you wish, but it's not necessary.
-
Give user and group read/write/sticky on files.
chmod -R ug+rws directory
-
Change directories to the Rails root directory
-
Keep in mind that if you are running these commands in a production environment, you will need to add
RAILS_ENV=production
to the beginning of each of the following commands. -
You'll need to know the subdomain of the Press that the imported records will belong to. You can run a rake task to see all the subdomains for all Presses.
bundle exec rake press:list
- If you want to see what options you can pass to the import script, you can run it with
-h
or--help
to see the usage information:
bundle exec script/import --help
- Run the import script, giving it the path to the directory where your CSV files are located, the subdomain of the Press, your user name (and optionally, the visibility that the imported records will have).
bundle exec script/import -d /path/to/directory -p michigan -u me@here.edu -v public
If you want to "reimport" files to a monograph that already exists, pass the monograph's NOID using the -m option like this:
bundle exec script/import -d /path/to/csv_and_files_dir/ -u me@here.edu -m 9593tv67p
There are a couple of options which can help when importing iteratively:
- test mode (add -t to the command) ensures that the slow process of actually creating objects never happens. This is useful for checking that actual file names match the template and, of course, verifying the metadata itself.
- overwrite the monograph name by adding, e.g.:
-n "Import test 07/25 HD"
... to the command. Note that the monograph row in the template is still expected at this time.