jmarsh24 / tangocloud

This is tango music streaming platform
https://tangocloud.app
2 stars 1 forks source link

Create seeds for the application #156

Closed jmarsh24 closed 3 weeks ago

jmarsh24 commented 1 month ago

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 and bin/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.

jmarsh24 commented 1 month ago

Shaping Notes

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.

jmarsh24 commented 3 weeks ago
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