
--
-- This script is used to initialize the audited data (in the _aud tables) for Samples section (objects) into GMM
-- This script has been done because in June 2010, Samples were not audited. We decided to audit them.
-- None SAMPLES data were existing in the GMM DB. So we needed to import the 
-- samples objects and to initialize the _aud tables of the new Samples objects)
--


-- Note - Remove comment if you need to truncate the _aud tables to well initialize the _aud tables. But if you do that, you will CLEAR the AUDIT HISTORY of those tables
-- DON'T DO THAT ON PRODUCTION (or only if you have reasons)
--TRUNCATE TABLE tm_object_file_type_aud;
--TRUNCATE TABLE tm_object_instance_validation_aud;
--TRUNCATE TABLE tm_object_parameter_validator_aud;
--TRUNCATE TABLE tm_object_type_status_aud;
--TRUNCATE TABLE tm_object_class_validator_aud;
--TRUNCATE TABLE tm_object_type_aud;
--TRUNCATE TABLE tm_object_attribute_aud;
--TRUNCATE TABLE tm_object_file_aud;
--TRUNCATE TABLE tm_object_method_validator_aud;
--TRUNCATE TABLE tm_object_file_method_aud;
--TRUNCATE TABLE tm_object_attribute_option_aud;
--TRUNCATE TABLE tm_object_method_parameter_aud;
--TRUNCATE TABLE tm_object_creator_aud;
--TRUNCATE TABLE tm_object_reader_aud;


-- 0 FK
INSERT INTO tm_object_file_type_aud (rev, revtype, id, last_changed, last_modifier_id, description, keyword, extensions) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, keyword, extensions from  tm_object_file_type where id not in (SELECT a.id from tm_object_file_type a, tm_object_file_type_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_instance_validation_aud (rev, revtype, id, last_changed, last_modifier_id, description, value) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, value from  tm_object_instance_validation where id not in (SELECT a.id from tm_object_instance_validation a, tm_object_instance_validation_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_parameter_validator_aud (rev, revtype, parameter_id, last_changed, last_modifier_id, description, value) SELECT 1 as rev , 0 as revtype, parameter_id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, value from  tm_object_parameter_validator where parameter_id not in (SELECT a.parameter_id from tm_object_parameter_validator a, tm_object_parameter_validator_aud aa where a.parameter_id = aa.parameter_id and aa.revtype = 0 );
INSERT INTO tm_object_type_status_aud (rev, revtype, id, last_changed, last_modifier_id, description, keyword, label_to_display) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, keyword, label_to_display from  tm_object_type_status where id not in (SELECT a.id from tm_object_type_status a, tm_object_type_status_aud aa where a.id = aa.id and aa.revtype = 0 );

-- 1 FK
INSERT INTO tm_object_class_validator_aud (rev, revtype, validator_class_id, last_changed, last_modifier_id, description, name, value, file_type_id) SELECT 1 as rev , 0 as revtype, validator_class_id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, name, value, file_type_id from  tm_object_class_validator where validator_class_id not in (SELECT a.validator_class_id from tm_object_class_validator a, tm_object_class_validator_aud aa where a.validator_class_id = aa.validator_class_id and aa.revtype = 0 );
INSERT INTO tm_object_type_aud (rev, revtype, id, last_changed, last_modifier_id, default_desc, description, instructions, keyword, object_type_status_id) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, default_desc, description, instructions, keyword, object_type_status_id from  tm_object_type where id not in (SELECT a.id from tm_object_type a, tm_object_type_aud aa where a.id = aa.id and aa.revtype = 0 );

-- 2 FK
INSERT INTO tm_object_attribute_aud (rev, revtype, id, last_changed, last_modifier_id, description, keyword, object_id) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, keyword, object_id from  tm_object_attribute where id not in (SELECT a.id from tm_object_attribute a, tm_object_attribute_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_file_aud (rev, revtype, id, last_changed, last_modifier_id, description, object_id, type_id, max, min, uploader) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, object_id, type_id, max, min, uploader from  tm_object_file where id not in (SELECT a.id from tm_object_file a, tm_object_file_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_method_validator_aud (rev, revtype, method_id, last_changed, last_modifier_id, description, name, value, validator_class_id) SELECT 1 as rev , 0 as revtype, method_id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, name, value, validator_class_id from  tm_object_method_validator where method_id not in (SELECT a.method_id from tm_object_file_method a, tm_object_file_method_aud aa where a.method_id = aa.method_id and aa.revtype = 0 );

-- 3 FK
INSERT INTO tm_object_file_method_aud (rev, revtype, id, method_id) SELECT 1 as rev , 0 as revtype, id, method_id from  tm_object_file_method where id not in (SELECT a.id from tm_object_file_method a, tm_object_file_method_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_attribute_option_aud (rev, revtype, id, last_changed, last_modifier_id, description, keyword, attribue_id) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, keyword, attribue_id from  tm_object_attribute_option where id not in (SELECT a.id from tm_object_attribute_option a, tm_object_attribute_option_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_method_parameter_aud (rev, revtype, method_id, parameter_id) SELECT 1 as rev , 0 as revtype, method_id, parameter_id from  tm_object_method_parameter where method_id not in (SELECT a.method_id from tm_object_method_parameter a, tm_object_method_parameter_aud aa where a.method_id = aa.method_id and aa.revtype = 0 );

-- 4 FK
INSERT INTO tm_object_creator_aud (rev, revtype, id, last_changed, last_modifier_id, description, aipo_id, object_id) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, aipo_id, object_id from  tm_object_creator where id not in (SELECT a.id from tm_object_creator a, tm_object_creator_aud aa where a.id = aa.id and aa.revtype = 0 );
INSERT INTO tm_object_reader_aud (rev, revtype, id, last_changed, last_modifier_id, description, aipo_id, object_id) SELECT 1 as rev , 0 as revtype, id, '2008-04-01 00:00:00.0' as last_changed, '0' as last_modifier_id, description, aipo_id, object_id from  tm_object_reader where id not in (SELECT a.id from tm_object_reader a, tm_object_reader_aud aa where a.id = aa.id and aa.revtype = 0 );



