aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-04-28 09:49:54 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-04-28 09:49:54 -0700
commite4c48fff379bef7492fc5158181395763ed843d1 (patch)
treee3ea9bb2f2569c45641f9026da4a3cbd1158f4c1 /activerecord
parent71cf6ef1f5c29a8d318f2ff9390f56f768edb963 (diff)
parent5156110476575f1b26be0b204ab2e12d2dd37434 (diff)
downloadrails-e4c48fff379bef7492fc5158181395763ed843d1.tar.gz
rails-e4c48fff379bef7492fc5158181395763ed843d1.tar.bz2
rails-e4c48fff379bef7492fc5158181395763ed843d1.zip
Merge pull request #6028 from sikachu/master-fix_plpgsql
Create plpgsql language if not available
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/schema/postgresql_specific_schema.rb50
1 files changed, 29 insertions, 21 deletions
diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb
index 84228cdd0a..e51db50ae3 100644
--- a/activerecord/test/schema/postgresql_specific_schema.rb
+++ b/activerecord/test/schema/postgresql_specific_schema.rb
@@ -127,28 +127,36 @@ _SQL
);
_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