/*
* Автор: Галкин А.И.
* Дата: 2013-06-20
* Задача: http://jira.softage.ru/jira/browse/SDFO-54
* Назначение: Добавление синонимов к таблицам и представлениям для того что бы отвязать код от схемы "KFM"
* Изменяются объекты:
		create synonym for all tables,views
*/

/*
  ****** Инструкции для SQLPlus (обязательно) ******
  Для печати сообщений:
  DBMS_OUTPUT.put_line('<Message>');
*/
whenever sqlerror exit 1;
set serveroutput on;
set echo off;

declare
	filename      varchar2(256) := 'sfm.database-update.2013-06-20.CreateSynonyms.sql';
	purpose       varchar2(4000) := 'Добавление синонимов к таблицам и представлениям для того что бы отвязать код от схемы "KFM"';
	script_exists number := 0;
begin

	--delete from KFM.DB_Update_History where script_name = filename;	commit;
	select count(*)
		into script_exists
		from KFM.DB_Update_History
	 where script_name = filename;

	if (script_exists > 0) then
		RAISE_APPLICATION_ERROR(-20001,
														'"' || filename || '" уже присутствует в базе');
	else
		insert into KFM.DB_Update_History
			(script_name, purpose)
		values
			(filename, purpose);
	end if;

	/*
  ****** Begin update script ******
  */
	-- Транзакционный апдейт
	-- execute immediate '';
	/*
  ****** End update script ******
  */
	commit;

exception
	when others then
		rollback;
		raise;
end;

/* Извлечение объектов:
 * select OBJECT_NAME from SYS.ALL_OBJECTS where UPPER(OWNER)='KFM' and UPPER(OBJECT_TYPE) in ('VIEW', 'TABLE', 'PACKAGE') order by OWNER, OBJECT_TYPE, OBJECT_NAME;
 */

/

create or replace public synonym ANALYTICCODES for KFM.ANALYTICCODES;
create or replace public synonym ANALYTICTYPES for KFM.ANALYTICTYPES;
create or replace public synonym ANALYTICTYPES_COLUMN_DEPEND for KFM.ANALYTICTYPES_COLUMN_DEPEND;
create or replace public synonym ANALYTICTYPES_DATACODES for KFM.ANALYTICTYPES_DATACODES;
create or replace public synonym ANALYTICTYPES_VERS_DEPEND for KFM.ANALYTICTYPES_VERS_DEPEND;
create or replace public synonym COUNTRYCODES for KFM.COUNTRYCODES;
create or replace public synonym CURRCODES for KFM.CURRCODES;
create or replace public synonym ERRORS for KFM.ERRORS;
create or replace public synonym EXCEPTIONSTABLE for KFM.EXCEPTIONSTABLE;
create or replace public synonym FOUNDERS_CFM for KFM.FOUNDERS_CFM;
create or replace public synonym IMPORTSOURCES for KFM.IMPORTSOURCES;
create or replace public synonym IMPORTSOURCETYPES for KFM.IMPORTSOURCETYPES;
create or replace public synonym IMPORTTASKFIELDSMAP for KFM.IMPORTTASKFIELDSMAP;
create or replace public synonym IMPORTTASKS for KFM.IMPORTTASKS;
create or replace public synonym IMPORTTASKSHISTORY for KFM.IMPORTTASKSHISTORY;
create or replace public synonym IMPORTTASKSLOG for KFM.IMPORTTASKSLOG;
create or replace public synonym IMPORTTASKTYPES for KFM.IMPORTTASKTYPES;
create or replace public synonym IMP_ACCOUNTS for KFM.IMP_ACCOUNTS;
create or replace public synonym IMP_AUDIT for KFM.IMP_AUDIT;
create or replace public synonym IMP_FOUND for KFM.IMP_FOUND;
create or replace public synonym IMP_MEMBERS for KFM.IMP_MEMBERS;
create or replace public synonym IMP_MESSINFO for KFM.IMP_MESSINFO;
create or replace public synonym IMP_REFER for KFM.IMP_REFER;
create or replace public synonym KATO for KFM.KATO;
create or replace public synonym KATO_AREA_VIEW for KFM.KATO_AREA_VIEW;
create or replace public synonym KATO_CITY_VIEW for KFM.KATO_CITY_VIEW;
create or replace public synonym KATO_REGION_VIEW for KFM.KATO_REGION_VIEW;
create or replace public synonym LOGWORKTAB for KFM.LOGWORKTAB;
create or replace public synonym MESSAGES_CFM_RELATIONS for KFM.MESSAGES_CFM_RELATIONS;
create or replace public synonym MESSAGES_CFM_XML for KFM.MESSAGES_CFM_XML;
create or replace public synonym MESSAGES_FIELD_DIC for KFM.MESSAGES_FIELD_DIC;
create or replace public synonym MESSAGES_LIST_DESCR for KFM.MESSAGES_LIST_DESCR;
create or replace public synonym MESSAGES_LIST_DIC for KFM.MESSAGES_LIST_DIC;
create or replace public synonym MESSAGES_LIST_SETUP for KFM.MESSAGES_LIST_SETUP;
create or replace public synonym MESSAGES_ROOT_PREFIXES for KFM.MESSAGES_ROOT_PREFIXES;
create or replace public synonym MESSAGES_TEMPLATES for KFM.MESSAGES_TEMPLATES;
create or replace public synonym MESSAGES_TYPES for KFM.MESSAGES_TYPES;
create or replace public synonym MESSAGES_VERSIONS for KFM.MESSAGES_VERSIONS;
create or replace public synonym MESS_CFM for KFM.MESS_CFM;
create or replace public synonym MESS_CFM_ANNOUNCE_ACCOUNTS for KFM.MESS_CFM_ANNOUNCE_ACCOUNTS;
create or replace public synonym MESS_CFM_ANNOUNCE_CONT for KFM.MESS_CFM_ANNOUNCE_CONT;
create or replace public synonym MESS_CFM_ANNOUNCE_FOUND for KFM.MESS_CFM_ANNOUNCE_FOUND;
create or replace public synonym MESS_CFM_ANNOUNCE_INFO for KFM.MESS_CFM_ANNOUNCE_INFO;
create or replace public synonym MESS_CFM_ANNOUNCE_MEMB for KFM.MESS_CFM_ANNOUNCE_MEMB;
create or replace public synonym MESS_CFM_ANNOUNCE_OPER for KFM.MESS_CFM_ANNOUNCE_OPER;
create or replace public synonym MESS_CFM_ANNOUNCE_SUBJ for KFM.MESS_CFM_ANNOUNCE_SUBJ;
create or replace public synonym MESS_CFM_CHECK for KFM.MESS_CFM_CHECK;
create or replace public synonym MESS_CFM_DOPINF for KFM.MESS_CFM_DOPINF;
create or replace public synonym MESS_CFM_DOPINF_ANSW for KFM.MESS_CFM_DOPINF_ANSW;
create or replace public synonym MESS_CFM_EXEC for KFM.MESS_CFM_EXEC;
create or replace public synonym MESS_CFM_GARBAGE for KFM.MESS_CFM_GARBAGE;
create or replace public synonym MESS_CFM_REFER for KFM.MESS_CFM_REFER;
create or replace public synonym MESS_CFM_UPDATE_INFO for KFM.MESS_CFM_UPDATE_INFO;
create or replace public synonym MESS_CFM_XML for KFM.MESS_CFM_XML;
create or replace public synonym MESS_LISTDIC_ROLEDEST for KFM.MESS_LISTDIC_ROLEDEST;
create or replace public synonym MESS_STATUS_LOGS for KFM.MESS_STATUS_LOGS;
create or replace public synonym MESS_VERIFY_CONDITION for KFM.MESS_VERIFY_CONDITION;
create or replace public synonym MESS_VERIFY_PROCS for KFM.MESS_VERIFY_PROCS;
create or replace public synonym MESS_VERIFY_SETUP for KFM.MESS_VERIFY_SETUP;
create or replace public synonym MESS_VERIFY_SETUP_CFM for KFM.MESS_VERIFY_SETUP_CFM;
create or replace public synonym MESS_VERIFY_SETUP_CONTROLS for KFM.MESS_VERIFY_SETUP_CONTROLS;
create or replace public synonym MESS_VERIFY_SETUP_FIELDDIC for KFM.MESS_VERIFY_SETUP_FIELDDIC;
create or replace public synonym MESS_VERIFY_XPATH for KFM.MESS_VERIFY_XPATH;
create or replace public synonym OKED2AC for KFM.OKED2AC;
create or replace public synonym OKSMT2AC for KFM.OKSMT2AC;
create or replace public synonym PASSPORT_CFM for KFM.PASSPORT_CFM;
create or replace public synonym PASSPORT_CFM_HISTORY for KFM.PASSPORT_CFM_HISTORY;
create or replace public synonym PASSPORT_CFM_STAGES_HISTORY for KFM.PASSPORT_CFM_STAGES_HISTORY;
create or replace public synonym PASSPORT_KEY_PARAMETERS for KFM.PASSPORT_KEY_PARAMETERS;
create or replace public synonym PITAORGS for KFM.PITAORGS;
create or replace public synonym PITAPERSONS for KFM.PITAPERSONS;
create or replace public synonym PKG_ANALYTIC for KFM.PKG_ANALYTIC;
create or replace public synonym PKG_AUDITS for KFM.PKG_AUDITS;
create or replace public synonym PKG_COMMON for KFM.PKG_COMMON;
create or replace public synonym PKG_COUNTER_REPORT_CFM for KFM.PKG_COUNTER_REPORT_CFM;
create or replace public synonym PKG_EXCEPTIONS for KFM.PKG_EXCEPTIONS;
create or replace public synonym PKG_FOUNDERS for KFM.PKG_FOUNDERS;
create or replace public synonym PKG_HDBK for KFM.PKG_HDBK;
create or replace public synonym PKG_IMPORT for KFM.PKG_IMPORT;
create or replace public synonym PKG_IMPORTSOURCES for KFM.PKG_IMPORTSOURCES;
create or replace public synonym PKG_IMPORTSOURCETYPES for KFM.PKG_IMPORTSOURCETYPES;
create or replace public synonym PKG_IMPORTTASKFIELDSMAP for KFM.PKG_IMPORTTASKFIELDSMAP;
create or replace public synonym PKG_IMPORTTASKS for KFM.PKG_IMPORTTASKS;
create or replace public synonym PKG_IMPORTTASKSLOG for KFM.PKG_IMPORTTASKSLOG;
create or replace public synonym PKG_KATOHOLDING for KFM.PKG_KATOHOLDING;
create or replace public synonym PKG_MAIN for KFM.PKG_MAIN;
create or replace public synonym PKG_MESSAGES_CFM for KFM.PKG_MESSAGES_CFM;
create or replace public synonym PKG_MESSAGES_XML for KFM.PKG_MESSAGES_XML;
create or replace public synonym PKG_MESSVERIFYPROCS for KFM.PKG_MESSVERIFYPROCS;
create or replace public synonym PKG_MESSVERIFYSETUP for KFM.PKG_MESSVERIFYSETUP;
create or replace public synonym PKG_MESS_CFM_1 for KFM.PKG_MESS_CFM_1;
create or replace public synonym PKG_MESS_CFM_2 for KFM.PKG_MESS_CFM_2;
create or replace public synonym PKG_MESS_CFM_2_1 for KFM.PKG_MESS_CFM_2_1;
create or replace public synonym PKG_PASSPORT_CFM for KFM.PKG_PASSPORT_CFM;
create or replace public synonym PKG_PITAHOLDING for KFM.PKG_PITAHOLDING;
create or replace public synonym PKG_REPORTS for KFM.PKG_REPORTS;
create or replace public synonym PKG_ROLES for KFM.PKG_ROLES;
create or replace public synonym PKG_RQST_CFM for KFM.PKG_RQST_CFM;
create or replace public synonym PKG_RQST_CNTR_CFM for KFM.PKG_RQST_CNTR_CFM;
create or replace public synonym PKG_SLC for KFM.PKG_SLC;
create or replace public synonym PKG_TEMPLATE for KFM.PKG_TEMPLATE;
create or replace public synonym PKG_TEMPLATE_CFM for KFM.PKG_TEMPLATE_CFM;
create or replace public synonym PKG_UPDATES_CFM for KFM.PKG_UPDATES_CFM;
create or replace public synonym PKG_USERS for KFM.PKG_USERS;
create or replace public synonym PKG_UTIL for KFM.PKG_UTIL;
create or replace public synonym READFILECOMMENTS for KFM.READFILECOMMENTS;
create or replace public synonym READFILES for KFM.READFILES;
create or replace public synonym REPORTS for KFM.REPORTS;
create or replace public synonym ROLES for KFM.ROLES;
create or replace public synonym ROLE_FORMS_DIC for KFM.ROLE_FORMS_DIC;
create or replace public synonym ROLE_MAINTASK_DIC for KFM.ROLE_MAINTASK_DIC;
create or replace public synonym ROLE_METHODS_DIC for KFM.ROLE_METHODS_DIC;
create or replace public synonym ROLE_MODULES_DIC for KFM.ROLE_MODULES_DIC;
create or replace public synonym ROLE_TASKS for KFM.ROLE_TASKS;
create or replace public synonym RUN_STATUS for KFM.RUN_STATUS;
create or replace public synonym SESSIONS for KFM.SESSIONS;
create or replace public synonym SOFT for KFM.SOFT;
create or replace public synonym SOFT_VERSIONS for KFM.SOFT_VERSIONS;
create or replace public synonym SUSPCRITERIAS_VIEW for KFM.SUSPCRITERIAS_VIEW;
create or replace public synonym SWIFT_CODES for KFM.SWIFT_CODES;
create or replace public synonym TABLE_UPDATES_TEMP for KFM.TABLE_UPDATES_TEMP;
create or replace public synonym TASKS for KFM.TASKS;
create or replace public synonym TMP_MESS_VERSION for KFM.TMP_MESS_VERSION;
create or replace public synonym UPDATES_CFM_DONE for KFM.UPDATES_CFM_DONE;
create or replace public synonym UPDATES_CFM_HIST for KFM.UPDATES_CFM_HIST;
create or replace public synonym UPDATES_CFM_HIST_MOD for KFM.UPDATES_CFM_HIST_MOD;
create or replace public synonym UPDATES_CFM_MODULENAMES for KFM.UPDATES_CFM_MODULENAMES;
create or replace public synonym UPDATES_MODULENAMES for KFM.UPDATES_MODULENAMES;
create or replace public synonym USERS for KFM.USERS;
create or replace public synonym USERSHISTORY for KFM.USERSHISTORY;
create or replace public synonym USER_AUDITS_LOGS for KFM.USER_AUDITS_LOGS;
create or replace public synonym USER_AUDIT_LOGS_SETUP for KFM.USER_AUDIT_LOGS_SETUP;
create or replace public synonym USER_ROLES for KFM.USER_ROLES;
create or replace public synonym USER_TASKS for KFM.USER_TASKS;
create or replace public synonym WORK_STAGES_DIC for KFM.WORK_STAGES_DIC;
create or replace public synonym WORK_STATUS_DIC for KFM.WORK_STATUS_DIC;
create or replace public synonym XML for KFM.XML;
create or replace public synonym XPATH for KFM.XPATH;
