Closed jmarsh24 closed 3 months ago
After adding the musicians to the digital remaster import, we should add import from el recodo, import all our songs we we have a database table with all the "non changing" data and create an sql dump.
https://gist.github.com/seyhunak/7843549
The audio variant attachments will reference the ones we have in our fixtures.
Our seed process will reference this to recreate the non changing part of the database.
require 'csv'
require 'fileutils'
# List of models to export
models = [
ExternalCatalog::ElRecodo::EmptyPage,
ExternalCatalog::ElRecodo::Orchestra,
ExternalCatalog::ElRecodo::PersonRole,
ExternalCatalog::ElRecodo::Person,
ExternalCatalog::ElRecodo::Song
]
# Iterate over each model and export its data
models.each do |model|
# Define the file path
csv_file_path = Rails.root.join('db/seeds', "#{model.name.demodulize.tableize}.csv")
# Define the directory path
directory_path = File.dirname(csv_file_path)
# Create the directory if it doesn't exist
unless File.directory?(directory_path)
FileUtils.mkdir_p(directory_path)
puts "Directory created at #{directory_path}"
end
# Export the entire table to the CSV file
CSV.open(csv_file_path, 'w') do |csv|
# Get the list of attribute names (columns)
attribute_names = model.column_names
# Write the headers
csv << attribute_names
# Fetch all records and write them to the CSV
model.find_each do |record|
# Write the attribute values for each record
csv << record.attributes.values_at(*attribute_names)
end
end
puts "CSV file exported successfully for #{model.name} to #{csv_file_path}."
end
Development should have a complete seeds file. When a developer sets up the application, there should be at least a basic full functioning application with admin users, el recodo data.
Review Notes
Run
bin/rails db:drop
andbin/setup
it should take about 3 minutes or so. Boot up the application and you should be able to see all the el_recodo data along with photos/etc.