SqlUpdate.sql 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. create or replace function update_susceptor_db() returns void as
  2. $$
  3. begin
  4. if not exists(select * from information_schema.tables
  5. where
  6. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  7. and table_name = 'SusceptorData') then
  8. CREATE TABLE "SusceptorData"
  9. (
  10. "Id" serial NOT NULL,
  11. "Time" timestamp without time zone,
  12. "SusceptorId" text,
  13. "ItemType" text,
  14. "ItemData" text,
  15. "ItemRemark" text,
  16. CONSTRAINT "SusceptorData_pkey" PRIMARY KEY ("Id" )
  17. )
  18. WITH (
  19. OIDS=FALSE
  20. );
  21. ALTER TABLE "SusceptorData"
  22. OWNER TO postgres;
  23. GRANT SELECT ON TABLE "SusceptorData" TO postgres;
  24. end if;
  25. if not exists(select * from information_schema.tables
  26. where
  27. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  28. and table_name = 'SusceptorList') then
  29. CREATE TABLE "SusceptorList"
  30. (
  31. "SusceptorId" text NOT NULL,
  32. "UserDefinedId" text,
  33. "CreateTime" timestamp without time zone,
  34. "DeleteTime" timestamp without time zone,
  35. "ProcessBeginTime" timestamp without time zone,
  36. "ProcessEndTime" timestamp without time zone,
  37. "ProcessIn" text,
  38. "RecipeName" text,
  39. "SusceptorStatus" text,
  40. "WafersOnSusceptor" text,
  41. "Description" text,
  42. CONSTRAINT "SusceptorList_pkey" PRIMARY KEY ("SusceptorId" )
  43. )
  44. WITH (
  45. OIDS=FALSE
  46. );
  47. ALTER TABLE "SusceptorList"
  48. OWNER TO postgres;
  49. GRANT SELECT ON TABLE "SusceptorList" TO postgres;
  50. end if;
  51. if not exists(select * from information_schema.tables
  52. where
  53. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  54. and table_name = 'EventManager') then
  55. CREATE TABLE "EventManager"
  56. (
  57. "PID" serial NOT NULL,
  58. "ID" integer,
  59. "EventEnum" text,
  60. "Type" text,
  61. "Source" text,
  62. "Description" text,
  63. "Level" text,
  64. "OccurTime" timestamp without time zone,
  65. CONSTRAINT "EventManager_pkey" PRIMARY KEY ("PID" )
  66. )
  67. WITH (
  68. OIDS=FALSE
  69. );
  70. --ALTER TABLE "EventManager"
  71. --OWNER TO postgres;
  72. GRANT ALL ON TABLE "EventManager" TO postgres;
  73. GRANT SELECT ON TABLE "EventManager" TO postgres;
  74. CREATE INDEX "EventManager_OccurTime_ID_idx"
  75. ON "EventManager"
  76. USING btree
  77. ("OccurTime" , "ID" );
  78. end if;
  79. if not exists(select * from information_schema.tables
  80. where
  81. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  82. and table_name = 'RecipeRunHistory') then
  83. CREATE TABLE "RecipeRunHistory"
  84. (
  85. "RecipeRunGuid" text NOT NULL,
  86. "SusceptorId" text,
  87. "ProcessBeginTime" timestamp without time zone,
  88. "ProcessEndTime" timestamp without time zone,
  89. "ProcessIn" text,
  90. "RecipeName" text,
  91. "SusceptorStatus" text,
  92. "UserDefinedId" text,
  93. "Description" text,
  94. "WafersOnSusceptor" text,
  95. CONSTRAINT "RecipeRunHistory_pkey" PRIMARY KEY ("RecipeRunGuid" )
  96. )
  97. WITH (
  98. OIDS=FALSE
  99. );
  100. ALTER TABLE "RecipeRunHistory"
  101. OWNER TO postgres;
  102. GRANT SELECT ON TABLE "RecipeRunHistory" TO postgres;
  103. end if;
  104. if not exists(select * from "RecipeRunHistory" where "Description" = 'DUMMY_RECORD_USED_FOR_UPDATING_ONLY') then
  105. INSERT INTO "RecipeRunHistory"("RecipeRunGuid", "Description") Values('DUMMY_RECORD_USED_FOR_UPDATING_ONLY','DUMMY_RECORD_USED_FOR_UPDATING_ONLY');
  106. INSERT INTO "RecipeRunHistory"(
  107. "RecipeRunGuid", "SusceptorId", "UserDefinedId", "ProcessBeginTime", "ProcessEndTime", "ProcessIn",
  108. "RecipeName", "SusceptorStatus", "Description")
  109. SELECT "SusceptorId", "SusceptorId", "UserDefinedId", "ProcessBeginTime", "ProcessEndTime", "ProcessIn",
  110. "RecipeName", "SusceptorStatus", "Description" from "SusceptorList" where ("RecipeName" <> '');
  111. end if;
  112. if not exists(select * from information_schema.tables
  113. where
  114. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  115. and table_name = 'VirtualDevice') then
  116. CREATE TABLE "VirtualDevice"
  117. (
  118. "ID" serial NOT NULL,
  119. "ChamberID" text,
  120. "DeviceName" character varying,
  121. "State" integer,
  122. "LastModifyDate" timestamp without time zone,
  123. "FunctionBlock" text,
  124. CONSTRAINT "VirtualDevice_pkey" PRIMARY KEY ("ID" )
  125. )
  126. WITH (
  127. OIDS=TRUE
  128. );
  129. ALTER TABLE "VirtualDevice"
  130. OWNER TO postgres;
  131. GRANT SELECT ON TABLE "VirtualDevice" TO postgres;
  132. end if;
  133. if not exists(select * from information_schema.tables
  134. where
  135. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  136. and table_name = 'ApplicationRunInfo') then
  137. CREATE TABLE "ApplicationRunInfo"
  138. (
  139. "ActTime" timestamp with time zone,
  140. "Type" text,
  141. "Info" text,
  142. "ChamberInfo" text,
  143. bak2 text,
  144. "ID" serial NOT NULL,
  145. "LastUpdateTime" timestamp with time zone,
  146. CONSTRAINT "ApplicationRunInfo_pkey" PRIMARY KEY ("ID" )
  147. )
  148. WITH (
  149. OIDS=FALSE
  150. );
  151. ALTER TABLE "ApplicationRunInfo"
  152. OWNER TO postgres;
  153. GRANT SELECT ON TABLE "ApplicationRunInfo" TO postgres;
  154. end if;
  155. if not exists(select * from information_schema.tables
  156. where
  157. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  158. and table_name = 'WaferDisplayIndex') then
  159. CREATE TABLE "WaferDisplayIndex"
  160. (
  161. "Id" text NOT NULL,
  162. "DisplayIndex" text,
  163. CONSTRAINT "WaferDisplayIndex_pkey" PRIMARY KEY ("Id" )
  164. )
  165. WITH (
  166. OIDS=FALSE
  167. );
  168. ALTER TABLE "WaferDisplayIndex"
  169. OWNER TO postgres;
  170. GRANT SELECT ON TABLE "WaferDisplayIndex" TO postgres;
  171. end if;
  172. end;
  173. $$
  174. language 'plpgsql';
  175. select update_susceptor_db();
  176. CREATE OR REPLACE FUNCTION batch_delete_tables(text)
  177. RETURNS int AS
  178. $$
  179. DECLARE
  180. r RECORD;
  181. count int;
  182. BEGIN
  183. count := 0;
  184. FOR r IN SELECT tablename FROM pg_tables where tablename like $1 || '%' LOOP
  185. RAISE NOTICE 'tablename: %', r.tablename;
  186. EXECUTE 'DROP TABLE "' || r.tablename || '" CASCADE';
  187. count := count + 1;
  188. END LOOP;
  189. RETURN count;
  190. END;
  191. $$
  192. LANGUAGE 'plpgsql' VOLATILE;