Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6028 from sikachu/master-fix_plpgsql

Create plpgsql language if not available
  • Loading branch information...
commit e4c48fff379bef7492fc5158181395763ed843d1 2 parents 71cf6ef + 5156110
Aaron Patterson tenderlove authored
Showing with 29 additions and 21 deletions.
  1. +29 −21 activerecord/test/schema/postgresql_specific_schema.rb
50 activerecord/test/schema/postgresql_specific_schema.rb
View
@@ -127,28 +127,36 @@
);
_SQL
- execute <<_SQL
- CREATE TABLE postgresql_partitioned_table_parent (
- id SERIAL PRIMARY KEY,
- number integer
- );
- CREATE TABLE postgresql_partitioned_table ( )
- INHERITS (postgresql_partitioned_table_parent);
-
- CREATE OR REPLACE FUNCTION partitioned_insert_trigger()
- RETURNS TRIGGER AS $$
- BEGIN
- INSERT INTO postgresql_partitioned_table VALUES (NEW.*);
- RETURN NULL;
- END;
- $$
- LANGUAGE plpgsql;
-
- CREATE TRIGGER insert_partitioning_trigger
- BEFORE INSERT ON postgresql_partitioned_table_parent
- FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger();
+begin
+ execute <<_SQL
+ CREATE TABLE postgresql_partitioned_table_parent (
+ id SERIAL PRIMARY KEY,
+ number integer
+ );
+ CREATE TABLE postgresql_partitioned_table ( )
+ INHERITS (postgresql_partitioned_table_parent);
+
+ CREATE OR REPLACE FUNCTION partitioned_insert_trigger()
+ RETURNS TRIGGER AS $$
+ BEGIN
+ INSERT INTO postgresql_partitioned_table VALUES (NEW.*);
+ RETURN NULL;
+ END;
+ $$
+ LANGUAGE plpgsql;
+
+ CREATE TRIGGER insert_partitioning_trigger
+ BEFORE INSERT ON postgresql_partitioned_table_parent
+ FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger();
_SQL
-
+rescue ActiveRecord::StatementInvalid => e
+ if e.message =~ /language "plpgsql" does not exist/
+ execute "CREATE LANGUAGE 'plpgsql';"
+ retry
+ else
+ raise e
+ end
+end
begin
execute <<_SQL
Please sign in to comment.
Something went wrong with that request. Please try again.