1

I am new to web development and I apologize if this is a basic question. I am looking for advice on choosing the most appropriate strategy for an auction site done in RoR.

Users can create auctions, which are active for a certain period of time. Each auction should have corresponding db tables, one for general details (i.e. user that created it, time to expiry) and another table that holds every bid made. The bids table is more for record keeping.
I'm ignorant with databases and am assuming that having multiple bid tables, with every bid for multiple auctions may overload the system, so once an auction expires, I want to export the records of the bids table and delete it.

If this is the best approach, here are my points of doubt

  1. Upon auction creation is it possible to generate a bids table strictly for the particular auction dynamically and if so how?
  2. Assuming the bids table is created dynamically. When a user places a bid, can I use javascript/ajax/JSON to make a post request to save the details to the bids table?
  3. How would the code for post request look? I'm assuming since the table is made dynamically, there is no corresponding model, controller/actions/view I can refer to and that too, invoke through the auction model.
  4. Is it possible to export db table records and delete them based on time expiration, if so how?

All help is much appreciated.

Sl.aze
  • 53
  • 1
  • 8
  • 1
    I worked with database with billions of lines. With the right indexes they still respond to queries within milliseconds. Database are just build to deal with huge amount of data. There is no need to create new table for each item on sale. And there is very like not a reason to export old data into an archive for a long period of time. – spickermann Mar 19 '16 at 18:29

1 Answers1

2

I haven't seen DB tables created dynamically - it's certainly not common.

What'd be more typical is to make a single Bids table and store the auction_id for each bid record. You use has_many and belongs_to to link the auction with it's bids list.

Then, when an auction expires, you find all the bids with auction.bids and run your export function on them. For example,

require 'yaml' # you could also dump as txt, json, csv, etc
def export(auction_id)
  Auction.find(auction_id).bids.each do |bid|
    File.open("bids_backup", "a") do |f|
      f.puts YAML.dump(bid.attributes)
    end
    bid.destroy
  end
end

Note that you'd have to slightly alter this export function if you're deploying to Heroku, since they have a read-only filesystem.

Since you asked about selecting bids within a time frame, I'll just link to this and this question on the topic.

Community
  • 1
  • 1
max pleaner
  • 26,189
  • 9
  • 66
  • 118