48 questions
0
votes
1
answer
75
views
use activerecord-import to upsert only when values have changed
How to use activerecord-import to upsert only when values have changed?
Body:
I'm using the activerecord-import gem in a Rails 6 app to bulk upsert data into a PostgreSQL database. Here's an example ...
0
votes
0
answers
24
views
Move after_commit notification to background job in rails while using activerecord#import [duplicate]
I have a Rails model with an after_commit callback that sends a notification to users. However, this operation takes too long, so I want to move it to a background job.
Current Code:
I create or ...
1
vote
1
answer
290
views
PG:Undefined object error when using activeimport with constraint
I am trying to do an upsert with ActiveImport. When running the import I am trying to pass it a named constraint in order to tell it when to update certain columns.
User.import(
@import_values,
...
0
votes
1
answer
573
views
Is it possible to provide multiple unique indexes to conflict_target in activerecord-import on_duplicate_key_update option for Postgres in Rails?
I have a unique constraint on two columns, one being the primary key and also have a unique index on another column. When I use import method, I can only define one conflict_target as far as I know. ...
0
votes
0
answers
152
views
Creating new record with HABTM association is slow when bulk data is entered
@report = current_account.reports.new(report_params)
@report.name.try(:strip!)
@report.report_type = "campaign"
@report.save
Reports has_and_belongs_to_many contacts and vice versa
When we have ...
0
votes
1
answer
2k
views
ActiveRecord Import - duplicate key value violates unique constraint
Attempting to update a large dataset with ActiveRecord Import, I'm struggling to see why my insert is failing.
In my schema for the model, this line exists:
t.index ["variant_id", "...
1
vote
1
answer
454
views
Ruby on Rails, creating a many to many association after an activerecord-import
I am creating a few records programmatically based on a users input and creating an array of records to import.
When I check the database I can see the relationship has been created if they are new ...
2
votes
2
answers
2k
views
import with recursive using activerecord-import gem: has_many through association not working
Trying to import CSV file to the database using "activerecord-import gem".
I have the following Models
question.rb
require 'csv'
class Question < ApplicationRecord
has_many :question_answers, ...
0
votes
1
answer
2k
views
Active-record-import on_duplicate_key_update SUM existing value
How is possible to SUM the value of array to my existing row field during on_duplicate_key_update?
For example:
Model.import array, on_duplicate_key_update: [ :column_value + array_value]
Thank you.
0
votes
0
answers
2k
views
Restrict activerecord-import to update only
I'm using activerecord-import to bulk update a single field on existing records.
While I am learning how to use the gem. Is there a way to restrict so nothing ever gets created?
I'm currently using ...
1
vote
2
answers
472
views
Model database csv bulk insertion from zip file
Need to import csv data inside a zip file to my product model using activerecord-import and rubyzip gem.
This code works (download the zip and display the csv name)
desc "Import products data from ...
0
votes
1
answer
567
views
Is there an efficient means of using ActiveRecord#Pluck for my situation?
I need to insert a lot of data into a new database. Like, a lot of data, so even nanoseconds count in the context of this query. I'm using activerecord-import to bulk-insert into Postgres, but that ...
3
votes
1
answer
3k
views
active record-import is creating duplicate records
I am using active-record import gem in a class method to import array of listings read from csv file as shown in code below:
def self.import_listings(file)
start = Time.now
...
3
votes
1
answer
1k
views
Rails+resque background job import not adding anything to the database
I have an issue with importing a lot of records from a user provided excel file into a database. The logic for this is working fine, and I’m using ActiveRecord-import to cut down on the number of ...
6
votes
1
answer
2k
views
How to initialize PaperTrail versions to perform bulk insert using ActiveRecord-import gem?
I'm using activerecord-import gem to import multiple ActiveRecord documents in single query. Then I'm initializing related associations using saved documents ids and importing them too, and so on.
...
1
vote
0
answers
519
views
activerecord-import gem: has_many through issue
With help of activerecord-import gem I'm trying to save list of records with has_many through children in one query.
my models:
class Mailing < ActiveRecord::Base
has_many :...
4
votes
3
answers
5k
views
CSV Parse Taking Too Much Memory
I'm trying to read a 5MM line file and right now it is exceeding my alotted memory usage on heroku. My method is somewhat fast ~200 inserts/second.. I believe it's crashing on the import.. So my plan ...
0
votes
1
answer
684
views
How do I get my IDs auto-generated when a NULL value is inserted in PostGres?
I’m using PostGres 9.5. I have the following set up in my table, in hopes of auto-generating IDs …
myproject=> \d my_object_times
Table "public.my_object_times"
...
1
vote
1
answer
80
views
How can I edit existing activerecord objects in a sql database using ruby scripts?
How can activerecord objects be edited externally with scripts? I'm currently using the activerecord-import gem to insert objects into the database. Is it possible to edit existing records using this ...
0
votes
0
answers
745
views
All Rails active record foreign keys are nil after import via activerecord-import gem
Ruby 2.3.0, Rails 4.2.4, PostgreSQL 9.5
UPDATE: added activerecord-import code below.
Does anyone know how to make these associations hold, so that a model's table attributes can be referenced in ...
-4
votes
1
answer
2k
views
How to save multiple records in one query with callbacks
I have an array of new objects of active records I want to save them all in one query and I also want to call before_create callback. I used activerecored-import gem and also tried with insert method ...
8
votes
1
answer
5k
views
What do I need to do to get activerecord-import to work?
I am trying to use activerecord-import, but I can't seem to get my application to recognize its existence.
I get
undefined method `supports_import?' for #<Class:...>
or
undefined method `...
0
votes
1
answer
206
views
identifying problematic row of data giving mass import error
I am using activerecord-import to bulk insert a bunch of data in a .csv file into my rails app. Unfortunately, I am getting an error when I call import on my model.
ArgumentError (invalid byte ...
7
votes
3
answers
5k
views
activerecord-import gem NoMethodError: undefined method 'import'
I'm trying to use the activerecord-import gem and I've followed the directions on the wiki to a tee but I'm getting a NoMethodError: undefined method 'import' for #<Class:0x8b009b0>. Here's my ...