Skip to content

Instantly share code, notes, and snippets.

@kevinhq
Created August 28, 2020 03:27
Show Gist options
  • Save kevinhq/6446d35b864252216a24a870176fabc0 to your computer and use it in GitHub Desktop.
Save kevinhq/6446d35b864252216a24a870176fabc0 to your computer and use it in GitHub Desktop.
Virtual Column Index for ahoy_events table
class AddVirtualColumnIndexToAhoyEvents < ActiveRecord::Migration[6.0]
def up
ActiveRecord::Base.connection.execute (
'ALTER TABLE ahoy_events ADD properties_id INT AS (JSON_UNQUOTE(properties->"$.id")) STORED;'
)
ActiveRecord::Base.connection.execute (
'ALTER TABLE ahoy_events ADD INDEX (properties_id);'
)
end
def down
ActiveRecord::Base.connection.execute (
"ALTER TABLE ahoy_events DROP properties_id;"
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment