Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

432
Views
Modify schema name of postgresql db from "public" to "my-project"

I use ActiveRecord to migrate the changes to postgresql db. The schema name by default is "public". Where is the best way to rename this to "my-project-name".?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There is no such method in ActiveRecord::Migration to alter scheme name, but you able to use plain sql command.

First generate migration file:

$> bundle exec rails g migration RenameSchema

Then open it and add:

class RenameSchema < ActiveRecord::Migration
  def up
    execute "ALTER SCHEMA you_old_name RENAME TO you_new_name" 
  end

  def down
    execute "ALTER SCHEMA you_new_name RENAME TO you_old_name" 
  end
end

With that migration you can change name and rollback it back.

Note: You must own the schema to use ALTER SCHEMA. To rename a schema you must also have the CREATE privilege for the database.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!