aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-07-05 16:47:16 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-07-05 16:47:16 +0200
commita3aa963c3c1bdcc34165dfb7b6a1e708895bc33d (patch)
tree003f5442df207574647f3025b62c8aca0a93f5fd
parent6a7cacff4c3b1fd83ad09bba006935253427abb8 (diff)
downloadsonarqube-a3aa963c3c1bdcc34165dfb7b6a1e708895bc33d.tar.gz
sonarqube-a3aa963c3c1bdcc34165dfb7b6a1e708895bc33d.zip
SONAR-4178 Delete Oracle triggers when dropping table
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/config/environment.rb37
1 files changed, 31 insertions, 6 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb
index 259de14ed11..98b97b52c8e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb
@@ -126,7 +126,7 @@ class ActiveRecord::Migration
change_column(tablename, columnname, :big_integer, :null => true)
end
end
-
+
# SONAR-4178
def self.create_table(table_name, options = {})
super(table_name, options)
@@ -137,12 +137,22 @@ class ActiveRecord::Migration
# Do nothing
end
end
-
+
+ def drop_table(table_name, options = {})
+ super(table_name, options)
+ case dialect()
+ when "oracle"
+ drop_id_trigger(table_name)
+ else
+ # Do nothing
+ end
+ end
+
def self.create_id_trigger(table)
- execute_ddl("create trigger for table #{table}",
-
+ execute_ddl("create trigger for table #{table}",
+
%{CREATE OR REPLACE TRIGGER #{table}_id_trg
- BEFORE INSERT ON #{table}
+ BEFORE INSERT ON #{table}
FOR EACH ROW
BEGIN
IF :new.id IS null THEN
@@ -151,6 +161,21 @@ class ActiveRecord::Migration
END;})
end
+
+ def self.drop_id_trigger(table)
+ execute_ddl("drop trigger for table #{table}",
+
+ %{DECLARE
+ e EXCEPTION;
+ PRAGMA EXCEPTION_INIT(e,-4080);
+ BEGIN
+ EXECUTE IMMEDIATE 'DROP TRIGGER #{table}_id_trg';
+ EXCEPTION
+ WHEN e THEN
+ NULL;
+ END;})
+ end
+
private
def self.execute_ddl(message, ddl)
@@ -192,4 +217,4 @@ DatabaseVersion.automatic_setup
# Some changes have been done in activerecord-jdbc-adapter. Most of them relate to column types.
# All these changes are prefixed by the comment #sonar
#
-# \ No newline at end of file
+#