What should the migration look like? I would like to take advantage of the jsonb array querying technique.
How do I migrate an ActiveRecord model attribute from json to jsonb?
767 views Asked by Lee Dykes At
1
There are 1 answers
Related Questions in RUBY-ON-RAILS
- How to display legend box in tooltip text for amCharts 5 in Rails application?
- how to integrate cashfree payment gateway in ruby on rails project
- RSpec Capybara throwing Selenium error when trying to click a button with browser confirm
- rails minitest not picking up fixture properly, instance variable not percolating
- Duplicate GET requests - Rails & Heroku
- How to stub out current_user in JWT model for Rspec?
- NameError in Home#index
- Verifying Google Identity OAuth2 token with Ruby
- Error WebMock::NetConnectNotAllowedError in testing with stub using minitest in rails (using Faraday)
- why is mission_control-jobs erroring with load path error?
- Rescuing validation errors from a polymorphic association
- New error on random number assigned to local variable , Rails
- How to fix error in model with gem lockbox
- Images uploaded via Active Storage not displaying in Active Admin or on certain devices
- controller test_methods generating two errors intermittently
Related Questions in POSTGRESQL
- Only the first SQL script gets executed inside Docker Postgres container
- Compare fields in two tables
- Hibernate ClobJdbcType bindings: what are the diferences?
- Postgres && statement Error in Mybatis Mapper?
- Can this query be optimized? (Choosing a random row to insert, that excludes previously inserted Rows)
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- How to copy data from SQLite to postgreSQL?
- PGAdmin4 configured behind a reverse proxy but unable to connect to Postgresql server
- Updates to pgsodium encrypted values don't use specified key_id
- Connecting to Postgres running in a Docker container using psql
- Can't connect to local postgresql server from my docker container
- Django Arrayfield migration to cloud sql (Postgresql) not creating the column
- Get list of matching keywords for each post
- docker-compose can't reset postgresql database
Related Questions in RAILS-ACTIVERECORD
- unable to set pool and timeout settings when using ActiveRecord::Base.establish_connection()
- In Rails 7, what is the right ActiveRecord callback to use if I need to prevent (or rollback) persistance on error?
- Is there a way to create a has_many association that just filters items from another has_many association?
- Rails Active Record Statement Invalid Undefined column
- Rails query working in console but not in the controller
- RSpec test failing because of file field
- ActiveRecord validation error: saying field is blank even though it isn't
- Rails eager loading with WHERE clause results in two SQL queries
- Decrypting Fields Encrypted by Rails Active Record Encryptor in Plain Ruby
- How to destroy a bi-directional has_one association from either end?
- Why is this Rails collection_select not rendering the association attribute?
- How can I retry an ActionController action inside a rescue_from for a StaleObjectError
- Extract records from PostgreSQL based on time of day component of timestamp/DateTime in Rails Active Record
- Rails Active Record, reciprocal dependency hell
- database_tasks: false not working in rails 7.1
Related Questions in JSONB
- How to make Postgres GIN index work with jsonb_* functions?
- How to correctly insert a jsonb into postgresql using a Java PreparedStatement
- How to query jsonb column with spring data
- Having problems in creating a data model and repository for a JSONB data type in Supabase for Flutter
- Updating a specific field within a JSONB column in Supabase in Flutter
- Unable to select a jsonb column to a struct with a Json<_> field
- HasColumnName() with JSON property in EF Core 8
- Can I change a JSONB key with a query?
- PostgreSQL JSON: test if a value is contained in an array
- Postgres JSONB object filtering
- Storing an array of strings in postgresDB using golang gorm
- Reading jsonb from Hibernate 6 native query
- How to integrate i18n translation resource saved as JSONB data and fetched with REST API on React?
- Postgres, searching with ILIKE operator from json array works different, than from regular table
- Dynamically map JSON to a SQL table, adding and naming columns based on JSON keys
Related Questions in RAILS-POSTGRESQL
- How do I migrate an ActiveRecord model attribute from json to jsonb?
- LPAD & RPAD with parameter
- In postgresql , I am getting duplicates in a schema when I restore some tables in to a other schema in the same db .why?
- How to Connect to Docker Postgres Container from Host Machine
- Issues with understanding multiple joins
- Backup taken from pgadmin is smaller than backup taken from pgdump
- Rails Tenant schema switching with background jobs not working
- update query not working on Heroku using cloud 9 command line
- Find conversations between users
- How can I calculate locationGeo space in pgadmin 3 type with PostGIS functions?
- Postgres Trigger in specified time
- How to send PG binary data from the Rails controller?
- Why is Postgres double-quoting the first function identifier when I set a default function for a column?
- Why does this Postgres Select Query work in the local Docker Container but not on Amazon RDS Postgres?
- Rails ActiveRecord Behaviour?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I would write the migration this way:
I don't know how this compares performance-wise to other solutions, but I tested this on a table with 120,000 records, each record having four
jsoncolumns and it took me about a minute to migrate that table. Of course, I guess it depends on how complex thejsonstructure is.Also, notice that if your existing records have a default value of
{}, you have to add to the above statementsdefault: {}, because otherwise you'll havejsonbcolumns, but the default value will remain as'{}'::json.