Skip to content

session.truncate to reuse a Session for successive imports without recreating the table #32

Description

@sncalvo

Problem

The manual-control API creates a staging table, inserts, transfers, drops. If a user wants to run several imports back-to-back in the same session (same connection, same schema), they either drop+recreate (slow) or live with stale data.

Proposal

session = StagingTable::Session.new(User)
session.create_table

batches.each do |batch|
  session.truncate            # O(1), keeps table structure/indexes
  session.insert(batch)
  session.transfer
end

session.drop_table

Acceptance criteria

  • truncate runs TRUNCATE <staging_table> (PG/MySQL) or DELETE FROM ... (SQLite)
  • Preserves any indexes created via after_insert_indexes
  • Instrumented with staging_table.truncate
  • Tested against all three adapters

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions