DBModel.sql 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. create or replace function update_db_model() returns void as
  2. $$
  3. begin
  4. ------------------------------------------------------------------------------------------------
  5. --
  6. if not exists(select * from information_schema.tables
  7. where
  8. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  9. and table_name = 'carrier_data') then
  10. CREATE TABLE "carrier_data"
  11. (
  12. "guid" text NOT NULL,
  13. "load_time" timestamp without time zone,
  14. "unload_time" timestamp without time zone,
  15. "rfid" text,
  16. "lot_id" text,
  17. "product_category" text,
  18. "station" text,
  19. CONSTRAINT "carrier_data_pkey" PRIMARY KEY ("guid" )
  20. )
  21. WITH (
  22. OIDS=FALSE
  23. );
  24. ALTER TABLE "carrier_data"
  25. OWNER TO postgres;
  26. GRANT SELECT ON TABLE "carrier_data" TO postgres;
  27. end if;
  28. ------------------------------------------------------------------------------------------------
  29. --
  30. if not exists(select * from information_schema.tables
  31. where
  32. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  33. and table_name = 'carrier_move_history') then
  34. CREATE TABLE "carrier_move_history"
  35. (
  36. "gid" serial NOT NULL,
  37. "carrier_data_guid" text,
  38. "arrive_time" timestamp without time zone,
  39. "lot_id" text,
  40. "station" text,
  41. "status" text,
  42. CONSTRAINT "carrier_move_history_pkey" PRIMARY KEY ("gid" )
  43. )
  44. WITH (
  45. OIDS=FALSE
  46. );
  47. ALTER TABLE "carrier_move_history"
  48. OWNER TO postgres;
  49. GRANT SELECT ON TABLE "carrier_move_history" TO postgres;
  50. end if;
  51. ------------------------------------------------------------------------------------------------
  52. --
  53. if not exists(select * from information_schema.tables
  54. where
  55. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  56. and table_name = 'wafer_data') then
  57. CREATE TABLE "wafer_data"
  58. (
  59. "guid" text NOT NULL,
  60. "create_time" timestamp without time zone,
  61. "delete_time" timestamp without time zone,
  62. "carrier_data_guid" text,
  63. "create_station" text,
  64. "create_slot" text,
  65. "process_data_guid" text,
  66. "wafer_id" text,
  67. "lasermarker1" text,
  68. "lasermarker2" text,
  69. "lasermarker3" text,
  70. "t7code1" text,
  71. "t7code2" text,
  72. "t7code3" text,
  73. "pj_data_guid" text,
  74. "lot_data_guid" text,
  75. "lot_id" text,
  76. "notch_angle" real,
  77. "sequence_name" text,
  78. "process_status" text,
  79. "use_count" real,
  80. "use_time" real,
  81. "use_thick" real,
  82. CONSTRAINT "wafer_data_pkey" PRIMARY KEY ("guid" )
  83. )
  84. WITH (
  85. OIDS=FALSE
  86. );
  87. ALTER TABLE "wafer_data"
  88. OWNER TO postgres;
  89. GRANT SELECT ON TABLE "wafer_data" TO postgres;
  90. end if;
  91. ------------------------------------------------------------------------------------------------
  92. --
  93. if not exists(select * from information_schema.tables
  94. where
  95. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  96. and table_name = 'event_data') then
  97. CREATE TABLE "event_data"
  98. (
  99. "gid" serial NOT NULL,
  100. "event_id" integer,
  101. "event_enum" text,
  102. "type" text,
  103. "source" text,
  104. "description" text,
  105. "level" text,
  106. "occur_time" timestamp without time zone,
  107. CONSTRAINT "event_data_pkey" PRIMARY KEY ("gid" )
  108. )
  109. WITH (
  110. OIDS=FALSE
  111. );
  112. --ALTER TABLE "EventManager"
  113. --OWNER TO postgres;
  114. GRANT ALL ON TABLE "event_data" TO postgres;
  115. GRANT SELECT ON TABLE "event_data" TO postgres;
  116. CREATE INDEX "event_data_occur_time_event_id_idx"
  117. ON "event_data"
  118. USING btree
  119. ("occur_time" , "event_id" );
  120. end if;
  121. ------------------------------------------------------------------------------------------------
  122. --
  123. if not exists(select * from information_schema.tables
  124. where
  125. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  126. and table_name = 'wafer_move_history') then
  127. CREATE TABLE "wafer_move_history"
  128. (
  129. "gid" serial NOT NULL,
  130. "wafer_data_guid" text,
  131. "arrive_time" timestamp without time zone,
  132. "station" text,
  133. "slot" text,
  134. "status" text,
  135. CONSTRAINT "wafer_move_history_pkey" PRIMARY KEY ("gid" )
  136. )
  137. WITH (
  138. OIDS=FALSE
  139. );
  140. ALTER TABLE "wafer_move_history"
  141. OWNER TO postgres;
  142. GRANT SELECT ON TABLE "wafer_move_history" TO postgres;
  143. end if;
  144. ------------------------------------------------------------------------------------------------
  145. --
  146. if not exists(select * from information_schema.tables
  147. where
  148. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  149. and table_name = 'process_data') then
  150. CREATE TABLE "process_data"
  151. (
  152. "guid" text NOT NULL,
  153. "process_begin_time" timestamp without time zone,
  154. "process_end_time" timestamp without time zone,
  155. "recipe_name" text,
  156. "process_status" text,
  157. "wafer_data_guid" text,
  158. "process_in" text,
  159. CONSTRAINT "process_data_pkey" PRIMARY KEY ("guid" )
  160. )
  161. WITH (
  162. OIDS=FALSE
  163. );
  164. ALTER TABLE "process_data"
  165. OWNER TO postgres;
  166. GRANT SELECT ON TABLE "process_data" TO postgres;
  167. end if;
  168. ------------------------------------------------------------------------------------------------
  169. --
  170. if not exists(select * from information_schema.tables
  171. where
  172. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  173. and table_name = 'stats_data') then
  174. CREATE TABLE "stats_data"
  175. (
  176. "name" text,
  177. "value" integer,
  178. "total" integer,
  179. "description" text,
  180. "last_update_time" timestamp without time zone,
  181. "last_reset_time" timestamp without time zone,
  182. "last_total_reset_time" timestamp without time zone,
  183. "is_visible" boolean,
  184. "enable_alarm" boolean,
  185. "alarm_value" integer,
  186. "warning_value" integer,
  187. CONSTRAINT "stats_data_pkey" PRIMARY KEY ("name" )
  188. )
  189. WITH (
  190. OIDS=FALSE
  191. );
  192. ALTER TABLE "stats_data"
  193. OWNER TO postgres;
  194. GRANT SELECT ON TABLE "stats_data" TO postgres;
  195. end if;
  196. ------------------------------------------------------------------------------------------------
  197. --
  198. if not exists(select * from information_schema.tables
  199. where
  200. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  201. and table_name = 'PM_statsData') then
  202. CREATE TABLE "PM_statsData"
  203. (
  204. "chamber" text,
  205. "name" text,
  206. "partsNo" text,
  207. "current_cycle" text,
  208. "target_cycle" text,
  209. "current_value" text,
  210. "warning_value" text,
  211. "target_value" text,
  212. "install_Date" timestamp without time zone,
  213. CONSTRAINT "PM_statsData_pkey" PRIMARY KEY ("name" )
  214. )
  215. WITH (
  216. OIDS=FALSE
  217. );
  218. ALTER TABLE "PM_statsData"
  219. OWNER TO postgres;
  220. GRANT SELECT ON TABLE "PM_statsData" TO postgres;
  221. end if;
  222. ------------------------------------------------------------------------------------------------
  223. --
  224. if not exists(select * from information_schema.tables
  225. where
  226. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  227. and table_name = 'PM_statsHistory') then
  228. CREATE TABLE "PM_statsHistory"
  229. (
  230. "id" serial,
  231. "chamber" text,
  232. "name" text,
  233. "partsNo" text,
  234. "current_cycle" text,
  235. "target_cycle" text,
  236. "current_value" text,
  237. "warning_value" text,
  238. "target_value" text,
  239. "install_Date" timestamp without time zone,
  240. CONSTRAINT "PM_statsHistory_pkey" PRIMARY KEY ("id" )
  241. )
  242. WITH (
  243. OIDS=FALSE
  244. );
  245. ALTER TABLE "PM_statsHistory"
  246. OWNER TO postgres;
  247. GRANT SELECT ON TABLE "PM_statsHistory" TO postgres;
  248. end if;
  249. ------------------------------------------------------------------------------------------------
  250. --
  251. if not exists(select * from information_schema.tables
  252. where
  253. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  254. and table_name = 'leak_check_data') then
  255. CREATE TABLE "leak_check_data"
  256. (
  257. "guid" text NOT NULL,
  258. "operate_time" timestamp without time zone,
  259. "status" text,
  260. "leak_rate" real,
  261. "start_pressure" real,
  262. "stop_pressure" real,
  263. "mode" text,
  264. "leak_check_time" integer,
  265. CONSTRAINT "leak_check_data_pkey" PRIMARY KEY ("guid" )
  266. )
  267. WITH (
  268. OIDS=FALSE
  269. );
  270. ALTER TABLE "leak_check_data"
  271. OWNER TO postgres;
  272. GRANT SELECT ON TABLE "leak_check_data" TO postgres;
  273. end if;
  274. ------------------------------------------------------------------------------------------------
  275. --
  276. if not exists(select * from information_schema.tables
  277. where
  278. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  279. and table_name = 'cj_data') then
  280. CREATE TABLE cj_data
  281. (
  282. "guid" text NOT NULL,
  283. "start_time" timestamp without time zone,
  284. "end_time" timestamp without time zone,
  285. "carrier_data_guid" text,
  286. "name" text,
  287. "input_port" text,
  288. "output_port" text,
  289. "total_wafer_count" integer,
  290. "abort_wafer_count" integer,
  291. "unprocessed_wafer_count" integer,
  292. CONSTRAINT "cj_data_pkey" PRIMARY KEY ("guid" )
  293. )
  294. WITH (
  295. OIDS=FALSE
  296. );
  297. ALTER TABLE "cj_data"
  298. OWNER TO postgres;
  299. GRANT SELECT ON TABLE "cj_data" TO postgres;
  300. end if;
  301. ------------------------------------------------------------------------------------------------
  302. --
  303. if not exists(select * from information_schema.tables
  304. where
  305. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  306. and table_name = 'pj_data') then
  307. CREATE TABLE pj_data
  308. (
  309. "guid" text NOT NULL,
  310. "start_time" timestamp without time zone,
  311. "end_time" timestamp without time zone,
  312. "job_name" text,
  313. "batch_id" text,
  314. "recipe_name" text,
  315. "layout_name" text,
  316. "layout_data" text,
  317. "wafer_data" text,
  318. "form" text,
  319. "carrier_data_guid" text,
  320. "cj_data_guid" text,
  321. "name" text,
  322. "input_port" text,
  323. "output_port" text,
  324. "total_wafer_count" integer,
  325. "abort_wafer_count" integer,
  326. "unprocessed_wafer_count" integer,
  327. CONSTRAINT "pj_data_pkey" PRIMARY KEY ("guid" )
  328. )
  329. WITH (
  330. OIDS=FALSE
  331. );
  332. ALTER TABLE "pj_data"
  333. OWNER TO postgres;
  334. GRANT SELECT ON TABLE "pj_data" TO postgres;
  335. end if;
  336. ------------------------------------------------------------------------------------------------
  337. --
  338. if not exists(select * from information_schema.tables
  339. where
  340. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  341. and table_name = 'lot_data') then
  342. CREATE TABLE lot_data
  343. (
  344. "guid" text NOT NULL,
  345. "start_time" timestamp without time zone,
  346. "end_time" timestamp without time zone,
  347. "carrier_data_guid" text,
  348. "cj_data_guid" text,
  349. "name" text,
  350. "input_port" text,
  351. "output_port" text,
  352. "total_wafer_count" integer,
  353. "abort_wafer_count" integer,
  354. "unprocessed_wafer_count" integer,
  355. CONSTRAINT "lot_data_pkey" PRIMARY KEY ("guid" )
  356. )
  357. WITH (
  358. OIDS=FALSE
  359. );
  360. ALTER TABLE "lot_data"
  361. OWNER TO postgres;
  362. GRANT SELECT ON TABLE "lot_data" TO postgres;
  363. end if;
  364. ------------------------------------------------------------------------------------------------
  365. --
  366. if not exists(select * from information_schema.tables
  367. where
  368. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  369. and table_name = 'lot_wafer_data') then
  370. CREATE TABLE lot_wafer_data
  371. (
  372. "guid" text NOT NULL,
  373. "create_time" timestamp without time zone,
  374. "lot_data_guid" text,
  375. "wafer_data_guid" text,
  376. CONSTRAINT "lot_wafer_data_pkey" PRIMARY KEY ("guid" )
  377. )
  378. WITH (
  379. OIDS=FALSE
  380. );
  381. ALTER TABLE "lot_wafer_data"
  382. OWNER TO postgres;
  383. GRANT SELECT ON TABLE "lot_wafer_data" TO postgres;
  384. CREATE INDEX "lot_wafer_data_idx1"
  385. ON "lot_wafer_data"
  386. USING btree
  387. ("lot_data_guid" , "wafer_data_guid" );
  388. end if;
  389. ------------------------------------------------------------------------------------------------
  390. --
  391. if not exists(select * from information_schema.tables
  392. where
  393. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  394. and table_name = 'recipe_step_data') then
  395. CREATE TABLE "recipe_step_data"
  396. (
  397. "guid" text NOT NULL,
  398. "step_begin_time" timestamp without time zone,
  399. "step_end_time" timestamp without time zone,
  400. "step_name" text,
  401. "step_time" real,
  402. "process_data_guid" text,
  403. "step_number" integer,
  404. CONSTRAINT "recipe_step_data_pkey" PRIMARY KEY ("guid" )
  405. )
  406. WITH (
  407. OIDS=FALSE
  408. );
  409. ALTER TABLE "recipe_step_data"
  410. OWNER TO postgres;
  411. GRANT SELECT ON TABLE "recipe_step_data" TO postgres;
  412. CREATE INDEX "recipe_step_data_idx1"
  413. ON "recipe_step_data"
  414. USING btree
  415. ("process_data_guid" , "step_number" );
  416. end if;
  417. ------------------------------------------------------------------------------------------------
  418. --
  419. if not exists(select * from information_schema.tables
  420. where
  421. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  422. and table_name = 'Recipe_History') then
  423. CREATE TABLE "Recipe_History"
  424. (
  425. "guid" text NOT NULL,
  426. "createdBy" text,
  427. "creationTime" timestamp without time zone,
  428. "lastRevisedBy" text,
  429. "lastRevisionTime" timestamp without time zone,
  430. "recipe_description" text,
  431. "recipe_type" text,
  432. "recipe_name" text,
  433. "recipe_path" text,
  434. "recipe_version" text,
  435. "recipe_level" text,
  436. "recipe_premission" text,
  437. "recipe_compare" text,
  438. "recipe_content" text,
  439. CONSTRAINT "Recipe_History_pkey" PRIMARY KEY ("guid" )
  440. )
  441. WITH (
  442. OIDS=FALSE
  443. );
  444. ALTER TABLE "Recipe_History"
  445. OWNER TO postgres;
  446. GRANT SELECT ON TABLE "Recipe_History" TO postgres;
  447. end if;
  448. ------------------------------------------------------------------------------------------------
  449. --
  450. if not exists(select * from information_schema.tables
  451. where
  452. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  453. and table_name = 'schedule_maintenance') then
  454. CREATE TABLE "schedule_maintenance"
  455. (
  456. "maintenance_item" text,
  457. "maintenance_display" text,
  458. "current_value" text,
  459. "scheduling_start_value" text,
  460. "maintenance_limit_value" text,
  461. "maintenance_processing" text,
  462. "unit" text,
  463. "path" text,
  464. "addition_information_name" text,
  465. "addition_information_display" text,
  466. CONSTRAINT "schedule_maintenance_pkey" PRIMARY KEY ("maintenance_item" )
  467. )
  468. WITH (
  469. OIDS=FALSE
  470. );
  471. ALTER TABLE "schedule_maintenance"
  472. OWNER TO postgres;
  473. GRANT SELECT ON TABLE "schedule_maintenance" TO postgres;
  474. end if;
  475. ------------------------------------------------------------------------------------------------
  476. --
  477. end;
  478. $$
  479. language 'plpgsql';
  480. select update_db_model();
  481. CREATE OR REPLACE FUNCTION batch_delete_tables(text)
  482. RETURNS int AS
  483. $$
  484. DECLARE
  485. r RECORD;
  486. count int;
  487. BEGIN
  488. count := 0;
  489. FOR r IN SELECT tablename FROM pg_tables where tablename like $1 || '%' LOOP
  490. RAISE NOTICE 'tablename: %', r.tablename;
  491. EXECUTE 'DROP TABLE "' || r.tablename || '" CASCADE';
  492. count := count + 1;
  493. END LOOP;
  494. RETURN count;
  495. END;
  496. $$
  497. LANGUAGE 'plpgsql' VOLATILE;