title: MySQL - Reserving a range of IDs for child objects for each parent object
body: <p>I have Companies and each Company has multiple Products. Models have following relation-</p>
  
  <p>class Company &lt; ActiveRecord::Base
    has_many :products
  end
  class Products &lt; ActiveRecord::Base
    belongs_to :company
  end</p>
  
  <p>I want to reserve 1000 product IDs for each Company.</p>
  
  <p>So </p>
  
  <ul>
  <li>Company1 can have product IDs from 1-1000</li>
  <li>Company2 can have product IDs from 1001-2000</li>
  </ul>
  
  <p>I want to reserve the PRIMARY keys of Products table for each Company rather than having scoped primary key and duplicate IDs (because a consumer/company can remember product ID and access it using url '.../product/1000').</p>
  
  <p>Solution I have in mind-
  Should I create multiple sequences (one for each company as and when company gets created). With default value as (Company.ID -1) * 1000 + 1.
  And use nextval for this sequence when product is created for a company 1. I am sure that a company will not have 1000 products in the system (improbable).</p>
  
  <p>Can you suggest a better approach?</p>