Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:25:07+00:00 2026-06-03T23:25:07+00:00

I have a migration where I create a products table like so class CreateProducts

  • 0

I have a migration where I create a products table like so

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :name
      t.hstore :data

      t.timestamps
    end
  end
end

On the activerecord-postgres-hstore page they add an index to the table (in SQL) with

CREATE INDEX products_gin_data ON products USING GIN(data);

However that change is not tracked by migrations (I’m guessing because it’s Postgres specific?), is there a way to create an index from within a migration?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:25:09+00:00Added an answer on June 3, 2026 at 11:25 pm

    Yes! You can make another migration and use the ‘execute’ method… like so:

    class IndexProductsGinData < ActiveRecord::Migration
      def up
        execute "CREATE INDEX products_gin_data ON products USING GIN(data)"
      end
    
      def down
        execute "DROP INDEX products_gin_data"
      end
    end
    

    UPDATE: You might also want to specify this line in config/application.rb:

    config.active_record.schema_format = :sql
    

    You can read about it here: http://apidock.com/rails/ActiveRecord/Base/schema_format/class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my Profile Migration like this : class CreateProfiles < ActiveRecord::Migration def self.up
I have the following Rails model: class CreateFoo < ActiveRecord::Migration def self.up create_table :foo
I have this model attributes : class CreateRoles < ActiveRecord::Migration # create role model
I have a migration: def change create_table :tasks do |t| t.date :date, :null =>
I have a model called Category which looks like this: class Category < ActiveRecord::Base
i have this crazy label for each time i create a migration that use
I have an ExpenseType object that I have created with the following migration: class
consider that i have a migration as follows create_table :dummies do |t| t.decimal :the_dummy_number
I have a migration named 20120311145341_create_resource1s.rb. I accidently deleted that table in database. I
I have a migration that will dynamically create tables on fly per date. Something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.