From: Julien HENRY Date: Mon, 17 Jun 2013 16:38:51 +0000 (+0200) Subject: SONAR-4178 Add triggers on Oracle to emulate identity column X-Git-Tag: 3.7~435 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=861565e0491c53ffff1d8dbe5b28de9cf496fa90;p=sonarqube.git SONAR-4178 Add triggers on Oracle to emulate identity column --- diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index f060ae68e59..85fb8a3f1ad 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -32,7 +32,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 411; + public static final int LAST_VERSION = 412; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/ActiveDashboardMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/ActiveDashboardMapper.xml index 18085d74dad..c62f80dafd6 100644 --- a/sonar-core/src/main/resources/org/sonar/core/dashboard/ActiveDashboardMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/ActiveDashboardMapper.xml @@ -3,20 +3,11 @@ - + INSERT INTO active_dashboards (dashboard_id, user_id, order_index) VALUES (#{dashboardId}, #{userId}, #{orderIndex}) - - - - select active_dashboards_seq.NEXTVAL from DUAL - - INSERT INTO active_dashboards (id, dashboard_id, user_id, order_index) - VALUES (#{id}, #{dashboardId}, #{userId}, #{orderIndex}) - - - + INSERT INTO dashboards (user_id, name, description, column_layout, shared, is_global, created_at, updated_at) VALUES (#{userId}, #{name}, #{description}, #{columnLayout}, #{shared}, #{global}, #{createdAt}, #{updatedAt}) - - - - select dashboards_seq.NEXTVAL from DUAL - - INSERT INTO dashboards (id, user_id, name, description, column_layout, shared, is_global, created_at, updated_at) - VALUES (#{id}, #{userId}, #{name}, #{description}, - #{columnLayout}, #{shared}, #{global}, #{createdAt}, #{updatedAt}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml index ee2b13ed999..07f2a323880 100644 --- a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml @@ -3,20 +3,10 @@ - + INSERT INTO widgets (dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id) VALUES (#{dashboardId}, #{key}, #{name}, #{description}, #{columnIndex}, #{rowIndex}, #{configured}, #{createdAt}, #{updatedAt}, #{resourceId}) - - - - select widgets_seq.NEXTVAL from DUAL - - INSERT INTO widgets (id, dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id) - VALUES (#{id}, #{dashboardId}, #{key}, #{name}, #{description}, #{columnIndex}, - #{rowIndex}, #{configured}, #{createdAt}, #{updatedAt}, #{resourceId}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml index ed3cb3e960c..deb555dea0e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml @@ -3,15 +3,9 @@ - + INSERT INTO widget_properties (widget_id, kee, text_value) VALUES (#{widgetId}, #{key}, #{value}) - - - INSERT INTO widget_properties (id, widget_id, kee, text_value) - VALUES (widget_properties_seq.NEXTVAL, #{widgetId}, #{key}, #{value}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml b/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml index 4b87e975d42..5a97b824756 100644 --- a/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml @@ -21,13 +21,4 @@ INSERT INTO duplications_index (snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line) VALUES (#{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine}) - - - - - select duplications_index_seq.NEXTVAL from DUAL - - INSERT INTO duplications_index (id, snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line) - VALUES (#{id}, #{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine}) - diff --git a/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml b/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml index ee684f90ddf..c7416c87a63 100644 --- a/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml @@ -25,16 +25,5 @@ #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) - - - - select graphs_seq.NEXTVAL from DUAL - - insert into graphs - (id, resource_id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at) - values ( - #{id}, #{resourceId}, #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId}, - #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) - diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/ActionPlanMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/ActionPlanMapper.xml index 663284e21ac..764141ca66b 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/ActionPlanMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/ActionPlanMapper.xml @@ -18,20 +18,11 @@ p.kee as projectKey - + INSERT INTO action_plans (kee, name, description, user_login, project_id, status, deadline, created_at, updated_at) VALUES (#{kee}, #{name}, #{description}, #{userLogin}, #{projectId}, #{status}, #{deadLine}, #{createdAt}, #{updatedAt}) - - - - select issues_seq.NEXTVAL from DUAL - - INSERT INTO action_plans (id, kee, name, description, user_login, project_id, status, deadline, created_at, updated_at) - VALUES (#{id}, #{kee}, #{name}, #{description}, #{userLogin}, #{projectId}, #{status}, #{deadLine}, #{createdAt}, #{updatedAt}) - - update action_plans set name=#{name}, diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml index d9d778458a0..f09b9e4794e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml @@ -20,16 +20,6 @@ VALUES (#{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) - - - - select issue_changes_seq.NEXTVAL from DUAL - - INSERT INTO issue_changes (id, kee, issue_key, user_login, change_type, change_data, created_at, updated_at) - VALUES (#{id}, #{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) - - delete from issue_changes where kee=#{id} diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml index 80c36ec8c09..f8aaa53f945 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml @@ -28,20 +28,11 @@ - + INSERT INTO issue_filter_favourites (user_login, issue_filter_id, created_at) VALUES (#{userLogin}, #{issueFilterId}, current_timestamp) - - - - select issue_filter_favourites_seq.NEXTVAL from DUAL - - INSERT INTO issue_filter_favourites (id, user_login, issue_filter_id, created_at) - VALUES (#{id},#{userLogin}, #{issueFilterId}, current_timestamp) - - delete from issue_filter_favourites where id=#{id} diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml index a85abad3bbe..3e908084468 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml @@ -74,20 +74,11 @@ - + INSERT INTO issue_filters (name, user_login, shared, description, data, created_at, updated_at) VALUES (#{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) - - - - select issue_filters_seq.NEXTVAL from DUAL - - INSERT INTO issue_filters (id, name, user_login, shared, description, data, created_at, updated_at) - VALUES (#{id}, #{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) - - update issue_filters set name=#{name}, diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 06fa350595e..505f9ce267e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -70,22 +70,6 @@ #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) - - - - select issues_seq.NEXTVAL from DUAL - - INSERT INTO issues (id, kee, component_id, root_component_id, rule_id, action_plan_key, severity, manual_severity, - message, line, effort_to_fix, status, - resolution, checksum, reporter, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, - issue_close_date, created_at, updated_at) - VALUES (#{id}, #{kee}, #{componentId}, #{rootComponentId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity}, - #{message}, #{line}, #{effortToFix}, #{status}, - #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{issueAttributes}, #{issueCreationDate}, - #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml index 713fc15f2e4..425b8cc07bd 100644 --- a/sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml @@ -8,18 +8,9 @@ from measure_filters WHERE user_id is null and name=#{id} - + INSERT INTO measure_filters (name, user_id, shared, description, data, created_at, updated_at) VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) - - - - select measure_filters_seq.NEXTVAL from DUAL - - INSERT INTO measure_filters (id, name, user_id, shared, description, data, created_at, updated_at) - VALUES (#{id}, #{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/SemaphoreMapper.xml b/sonar-core/src/main/resources/org/sonar/core/persistence/SemaphoreMapper.xml index 4b9fbb134f4..81ed974e32f 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/SemaphoreMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/SemaphoreMapper.xml @@ -8,14 +8,6 @@ VALUES (#{name}, #{checksum}, current_timestamp, current_timestamp, #{lockedAt}) - - - select semaphores_seq.NEXTVAL from DUAL - - INSERT INTO semaphores (id, name, checksum, created_at, updated_at, locked_at) - VALUES (#{id}, #{name}, #{checksum}, current_timestamp, current_timestamp, #{lockedAt}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 47f7780a0f8..1d75faef1a7 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -171,6 +171,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('404'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('405'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('410'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('411'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('412'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml index be5da6887f2..d12932595ab 100644 --- a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml @@ -73,15 +73,6 @@ VALUES (#{key}, #{resourceId}, #{userId}, #{value}) - - - - select properties_seq.NEXTVAL from DUAL - - INSERT INTO properties (id, prop_key, resource_id, user_id, text_value) - VALUES (#{id}, #{key}, #{resourceId}, #{userId}, #{value}) - - delete from properties where prop_key=#{id} and resource_id is null and user_id is null diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml index 51fdfe17d1a..91c494daa4a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml @@ -65,15 +65,5 @@ #{resourceId}, #{rootProjectId}, #{qualifier}) - - - - select resource_index_seq.NEXTVAL from DUAL - - insert into resource_index (id, kee, position, name_size, resource_id, root_project_id, qualifier) - values (#{id}, #{key}, #{position}, #{nameSize}, - #{resourceId}, #{rootProjectId}, #{qualifier}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index 394c9d56b73..3a19fe43730 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -167,7 +167,7 @@ - + insert into projects (name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, enabled, created_at) values ( @@ -177,20 +177,6 @@ ) - - - - select projects_seq.NEXTVAL from DUAL - - insert into projects - (id, name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, enabled, created_at) - values ( - #{id}, #{name}, #{longName}, #{description}, #{scope}, #{qualifier}, - #{key}, #{language}, #{rootId}, #{copyResourceId}, - #{personId}, #{enabled}, #{createdAt} - ) - - update projects set name=#{name}, long_name=#{longName}, description=#{description}, scope=#{scope}, qualifier=#{qualifier}, kee=#{key}, diff --git a/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml b/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml index 6d92b6fb878..f6474ea516c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml @@ -19,16 +19,5 @@ values ( #{resourceId}, #{snapshotId}, #{data}, #{dataType}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) - - - - - select snapshot_data_seq.NEXTVAL from DUAL - - insert into snapshot_data - (id, resource_id, snapshot_id, snapshot_data, data_type, created_at, updated_at) - values ( - #{id}, #{resourceId}, #{snapshotId}, #{data}, #{dataType}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) - diff --git a/sonar-core/src/main/resources/org/sonar/core/template/LoadedTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/template/LoadedTemplateMapper.xml index 5b6862e541b..e946a81ba99 100644 --- a/sonar-core/src/main/resources/org/sonar/core/template/LoadedTemplateMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/template/LoadedTemplateMapper.xml @@ -15,18 +15,9 @@ WHERE kee = #{key} AND template_type = #{type} - + INSERT INTO loaded_templates (kee, template_type) VALUES (#{key}, #{type}) - - - - select loaded_templates_seq.NEXTVAL from DUAL - - INSERT INTO loaded_templates (id, kee, template_type) - VALUES (#{id}, #{key}, #{type}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/user/AuthorMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/AuthorMapper.xml index 4071f72247b..fbb92585f10 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/AuthorMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/AuthorMapper.xml @@ -13,20 +13,10 @@ FROM authors WHERE person_id=#{id} - + INSERT INTO authors (person_id, login, created_at, updated_at) VALUES (#{personId}, #{login}, #{createdAt}, #{updatedAt}) - - - - select authors_seq.NEXTVAL from DUAL - - INSERT INTO authors (id, person_id, login, created_at, updated_at) - VALUES (#{id}, #{personId}, #{login}, - #{createdAt}, #{updatedAt}) - - diff --git a/sonar-core/src/main/resources/org/sonar/core/user/RoleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/RoleMapper.xml index bbef4611eed..d230d2899a8 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/RoleMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/RoleMapper.xml @@ -3,34 +3,16 @@ - + INSERT INTO group_roles (group_id, resource_id, role) VALUES (#{groupId}, #{resourceId}, #{role}) - - - - select group_roles_seq.NEXTVAL from DUAL - - INSERT INTO group_roles (id, group_id, resource_id, role) - VALUES (#{id}, #{groupId}, #{resourceId}, #{role}) - - - + INSERT INTO user_roles (user_id, resource_id, role) VALUES (#{userId}, #{resourceId}, #{role}) - - - - select user_roles_seq.NEXTVAL from DUAL - - INSERT INTO user_roles (id, user_id, resource_id, role) - VALUES (#{id}, #{userId}, #{resourceId}, #{role}) - - delete from group_roles where resource_id=#{resourceId} and role=#{role} diff --git a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml index bbc0ba808ea..1ae3c8f845d 100644 --- a/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml +++ b/sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml @@ -3,7 +3,7 @@ - + INSERT INTO project_measures ( value, metric_id, snapshot_id, rule_id, text_value, tendency, measure_date, project_id, alert_status, alert_text, url, description, rule_priority, characteristic_id, variation_value_1, @@ -16,7 +16,7 @@ ) - + INSERT INTO measure_data (measure_id, snapshot_id, data) VALUES (#{measure.id}, #{measure.snapshotId}, #{data}) @@ -48,25 +48,4 @@ WHERE id = #{id} - - - INSERT INTO project_measures ( - id, - value, metric_id, snapshot_id, rule_id, text_value, tendency, measure_date, - project_id, alert_status, alert_text, url, description, rule_priority, characteristic_id, variation_value_1, - variation_value_2, variation_value_3, variation_value_4, variation_value_5, person_id) - VALUES ( - project_measures_seq.NEXTVAL, - #{value}, #{metricId}, #{snapshotId}, #{ruleId}, #{textValue}, #{tendency}, - #{measureDate}, #{projectId}, #{alertStatus}, #{alertText}, - #{url}, #{description}, #{rulePriority.ordinal}, #{characteristic.id}, #{variationValue1}, - #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId} - ) - - - - INSERT INTO measure_data (id, measure_id, snapshot_id, data) - VALUES (measure_data_seq.NEXTVAL, #{measure.id}, #{measure.snapshotId}, #{data}) - - diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/412_add_oracle_id_triggers.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/412_add_oracle_id_triggers.rb new file mode 100644 index 00000000000..f0e53e99b3e --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/412_add_oracle_id_triggers.rb @@ -0,0 +1,113 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# SonarQube is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# Sonar 3.6 +# SONAR-3340 +class AddOracleIdTriggers < ActiveRecord::Migration + + + def self.up + case dialect() + when "oracle" + upgrade_oracle() + else + # Do nothing + end + end + + private + + def self.upgrade_oracle + create_id_trigger('action_plans') + create_id_trigger('active_dashboards') + create_id_trigger('active_rule_changes') + create_id_trigger('active_rule_notes') + create_id_trigger('active_rule_param_changes') + create_id_trigger('active_rule_parameters') + create_id_trigger('active_rules') + create_id_trigger('alerts') + create_id_trigger('authors') + create_id_trigger('characteristic_properties') + create_id_trigger('characteristics') + create_id_trigger('dashboards') + create_id_trigger('dependencies') + create_id_trigger('duplications_index') + create_id_trigger('events') + create_id_trigger('graphs') + create_id_trigger('group_roles') + create_id_trigger('groups') + create_id_trigger('groups_users') + create_id_trigger('issue_changes') + create_id_trigger('issue_filter_favourites') + create_id_trigger('issue_filters') + create_id_trigger('issues') + create_id_trigger('loaded_templates') + create_id_trigger('manual_measures') + create_id_trigger('measure_data') + create_id_trigger('measure_filter_favourites') + create_id_trigger('measure_filters') + create_id_trigger('metrics') + create_id_trigger('notifications') + create_id_trigger('project_links') + create_id_trigger('project_measures') + create_id_trigger('projects') + create_id_trigger('properties') + create_id_trigger('quality_models') + create_id_trigger('resource_index') + create_id_trigger('rule_notes') + create_id_trigger('rules') + create_id_trigger('rules_parameters') + create_id_trigger('rules_profiles') + create_id_trigger('semaphores') + create_id_trigger('snapshot_data') + create_id_trigger('snapshot_sources') + create_id_trigger('snapshots') + create_id_trigger('user_roles') + create_id_trigger('users') + create_id_trigger('widget_properties') + create_id_trigger('widgets') + end + + def self.create_id_trigger(table) + execute_ddl('create trigger for table ' + table, + + %{CREATE OR REPLACE TRIGGER #{table}_id_trg + BEFORE INSERT ON #{table} + FOR EACH ROW + BEGIN + IF :new.id IS null THEN + SELECT #{table}_seq.nextval INTO :new.id FROM dual; + END IF; + END;}) + end + + def self.execute_ddl(message, ddl) + begin + say_with_time(message) do + ActiveRecord::Base.connection.execute(ddl) + end + rescue + # already executed + end + end + +end +