Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 946955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:00:17+00:00 2026-05-15T23:00:17+00:00

Goal: Using a CRON task (or other scheduled event) to update database with nightly

  • 0

Goal: Using a CRON task (or other scheduled event) to update database with nightly export of data from an existing system.

All data is created/updated/deleted in an existing system. The website does no directly integrate with this system, so the rails app simply needs to reflect the updates that appear in the data export.

I have a .txt file of ~5,000 products that looks like this:

"1234":"product name":"attr 1":"attr 2":"ABC Manufacturing":"2222"
"A134":"another product":"attr 1":"attr 2":"Foobar World":"2447"
...

All values are strings enclosed in double quotes (") that are separated by colons (:)

Fields are:

  • id: unique id; alphanumeric
  • name: product name; any character
  • attribute columns: strings; any character (e.g., size, weight, color, dimension)
  • vendor_name: string; any character
  • vendor_id: unique vendor id; numeric

Vendor information is not normalized in the current system.

What are best practices here? Is it okay to delete the products and vendors tables and rewrite with the new data on every cycle? Or is it better to only add new rows and update existing ones?

Notes:

  1. This data will be used to generate Orders that will persist through nightly database imports. OrderItems will need to be connected to the product ids that are specified in the data file, so we can’t rely on an auto-incrementing primary key to be the same for each import; the unique alphanumeric id will need to be used to join products to order_items.
  2. Ideally, I’d like the importer to normalize the Vendor data
  3. I cannot use vanilla SQL statements, so I imagine I’ll need to write a rake task in order to use Product.create(...) and Vendor.create(...) style syntax.
  4. This will be implemented on EngineYard
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:00:17+00:00Added an answer on May 15, 2026 at 11:00 pm

    I wouldn’t delete the products and vendors tables on every cycle. Is this a rails app? If so there are some really nice ActiveRecord helpers that would come in handy for you.

    If you have a Product active record model, you can do:

    p = Product.find_or_initialize_by_identifier(<id you get from file>)
    p.name = <name from file>
    p.size = <size from file>
    etc...
    p.save!
    

    The find_or_initialize will lookup the product in the database by the id you specify, and if it can’t find it, it will create a new one. The really handy thing about doing it this way, is that ActiveRecord will only save to the database if any of the data has changed, and it will automatically update any timestamp fields you have in the table (updated_at) accordingly. One more thing, since you would be looking up records by the identifier (id from the file), I would make sure to add an index on that field in the database.

    To make a rake task to accomplish this, I would add a rake file to the lib/tasks directory of your rails app. We’ll call it data.rake.

    Inside data.rake, it would look something like this:

    namespace :data do
      desc "import data from files to database"
      task :import => :environment do
        file = File.open(<file to import>)
        file.each do |line|
          attrs = line.split(":")
          p = Product.find_or_initialize_by_identifier(attrs[0])
          p.name = attrs[1]
          etc...
          p.save!
        end
      end
    end
    

    Than to call the rake task, use “rake data:import” from the command line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to inline edit cells in a data grid using JQuery and
My Goal is to capture Video using Android Camera and Record Voice from Mic.
My goal is to connect to my database either manually or using an sqladapater,
We're using a back-end proprietary database to feed data to over 100 dynamic pages
Issue Garbage gets erroneously entered into date fields and screws up calculations. Goal Using
Goal : Our application is built using multiple types (e.g. Person, PersonSite(ICollection), Site -
We're using the Maven exec:java goal to run a custom java application that configures
goal : I want to place a text after the submit button using hook_form_alter.
The goal is to mine packet headers for URLs visited using tcpdump. So far,
The goal is to issue the fewest queries to SQL Server using LINQ to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.