Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

0 votes
0 answers
11 views

Delete record and record associations based on multiple reference attributes

I have a join table that handles the logic of who owns what: create_table :exercise_drills do |t| t.references :exercise, foreign_key: { on_delete: :cascade }, null: false t.references :drill, ...
Chrismisballs's user avatar
0 votes
0 answers
38 views

How can I fix Postgres errors in Minitest?

I am using Minitest and Postgres to test my Rails website. When I added a "Like" model, I started getting Postgresql deadlock errors Minitest::UnexpectedError: ActiveRecord::Deadlocked: PG::...
tolia k's user avatar
0 votes
0 answers
42 views

What does INSERT INTO "public" mean from a failed import of a csv file into TablePlus postgresql database? [closed]

First time trying to import a csv file into a postgresql rails database using TablePlus. The table has seven columns but I was only importing a single row with just three of the columns to test it. ...
mwhocl's user avatar
  • 75
0 votes
0 answers
43 views

Generate a PG dump when click a button

im creating a rails app (basically a monolith). currently, im creating a new feature, "when i click some button, it download a sql script with db backup". i understand that i can execute ...
Nicolás's user avatar
0 votes
1 answer
75 views

Rails 7: Psql trying to connect to the wrong database but trying to create correct database

In production mode, I am testing connecting a rails 7 project to a remote server for the postgresql database. However when I try to connect to it, it starts looking to connect to the postgres database ...
Ese10's user avatar
  • 19
1 vote
1 answer
55 views

Rails: commit inner nested transaction regardless of parent transaction rollback (requires_new: true is not enough)

Imagine an operation that needs to be protected against race conditions, and therefore is run inside a Rails with_lock block. with_lock starts a new transaction. In this specific case, we're not ...
sandre89's user avatar
  • 5,680
0 votes
1 answer
68 views

Upsert_all with uniqueness index constraint

I'm facing a dilemma. I've created a model with an wave_order column with uniqueness db index with wavable. wavable is a polymorphic (but we don't care actually). # migration create_table :...
brcebn's user avatar
  • 1,672
2 votes
2 answers
69 views

How to find the size of a table in bytes in Ruby on Rails?

Versions for My Environment: Ruby 3.2.2 Rails 7.1.2 PSQL 15 - (the gem is pg 1.1) Preface: I did not find a direct answer after some searching on the Internet, so I am posting this to show what I ...
Luke Loera's user avatar
0 votes
2 answers
119 views

Is there any simple way to transform jsonb field into csv? [closed]

I have a model with a jsonb field where responses from a third-party service are stored. The response changes periodically; some fields are added, some disappear. I want to generate a CSV from a ...
user3390963's user avatar
  • 2,329
0 votes
0 answers
77 views

Using test_prof before_all recipe with manual connection switching in multiple db setup

I am using test-prof gem with before_all recipe to create all the necessary records for the suite and run a heavy service afterwards. Yet I'm running into a problem when a block of queries is executed ...
potashin's user avatar
  • 44.5k
0 votes
2 answers
80 views

How to optimize performance and speed up loading data from database?

I have a database table cars that has close to 500k records. I was facing issues with long loading times to load data from this table. @cars = Car.order('created_at DESC').paginate(page: params[:page],...
user984621's user avatar
  • 47.7k
0 votes
0 answers
43 views

Rails Active Record query joins and merge get Ids

User -> Has many cats Vaccinations -> has many cats Cat -> belongs to vaccination User::CatRecords is a namespaced ActiveRecord model -> belongs to cat This is what I have tried so far ...
Manav's user avatar
  • 659
0 votes
0 answers
41 views

How to create migration and indexing for table created by airbyte automatically in Rails

I have a postgres database table which is created by airbyte automatically in rails app. I want to manage migration and indexing for new column. There is no mechanism right now to handle this since ...
Beu's user avatar
  • 1,534
1 vote
2 answers
118 views

Processing 500k records crashes the server. How to batch it?

I have a database table holding 500k records. I need to load these records, do an API call, fetch data from this API endpoint, and save new data back to the database. I tried to do it like this (...
user984621's user avatar
  • 47.7k
0 votes
0 answers
33 views

Order Records by json/hash column's key [duplicate]

I'm having a scenario where I need to perform sorting based on hash/json's key. To make it clearer, TableA has three columns: col1 -> vendor_name(type: string) col2 ->store_name(type: string) ...
Ariharan S's user avatar

15 30 50 per page
1
2 3 4 5
683