lib/pg_partition_manager.rb
# Create tables to hold future data
Create tables to hold future data
Create tables to hold future data
def create_tables
      schema, table = @partition[:parent_table].split(".")
      start = @start
      stop = period_end(start)
      (0..(@partition[:premake] || 4)).map do |month|
        child_table = "#{schema}.#{table}_p#{start.to_s.tr("-", "_")}"
        @db.exec("create table if not exists #{child_table} partition of #{schema}.#{table} for values from ('#{start}') to ('#{stop}')")
        start = stop
        stop = period_end(start)
        child_table
      end
    end
def create_tables schema , table = @partition [ :parent_table ] . split ( "." ) start = @start stop = period_end ( start ) ( 0 .. ( @partition [ :premake ] || 4 ) ) . map do | month | child_table = "#{schema}.#{table}_p#{start.to_s.tr("-", "_")}" @db . exec ( "create table if not exists #{child_table} partition of #{schema}.#{table} for values from ('#{start}') to ('#{stop}')" ) start = stop stop = period_end ( start ) child_table end end
Create tables to hold future data
Create tables to hold future data
# Note that this starts in the *current* period, so we start at 0 rather # than 1 for the range, to be sure the current period gets a table *and* # we make the number of desired future tables