Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Postgres extensions at database creation?

It would be lovely if the rake command db:create could be followed by a postgresql installation script. This, for example. (It must be run as postgres user):

CREATE EXTENSION "fuzzystrmatch"; 

This because, in this moment, i'm doing it manually every time I create a database.

Any hints?

like image 419
Alive Developer Avatar asked May 17 '13 14:05

Alive Developer


People also ask

Where does Postgres install extensions?

Extension Files The file format must be extension_name. control, which tells the basics about extension to PostgreSQL, and must be placed in the installation's SHAREDIR/extension directory.

What is create extension in PostgreSQL?

Description. CREATE EXTENSION loads a new extension into the current database. There must not be an extension of the same name already loaded. Loading an extension essentially amounts to running the extension's script file.

What are PostgreSQL extensions?

Extensions were implemented in PostgreSQL 9.1 to allow for easier packaging of additions to PostgreSQL. Extensions can package user-visible functions or use hooks in the PostgreSQL to modify how the database does certain processes.


1 Answers

As of Rails 4, there is a enable_extension method:

class AddFuzzyStringMatching < ActiveRecord::Migration   def change     enable_extension "fuzzystrmatch"   end end 
like image 53
Dylan Markow Avatar answered Sep 17 '22 02:09

Dylan Markow