DBModel.sql 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. "pj_id" text,
  160. CONSTRAINT "process_data_pkey" PRIMARY KEY ("guid" )
  161. )
  162. WITH (
  163. OIDS=FALSE
  164. );
  165. ALTER TABLE "process_data"
  166. OWNER TO postgres;
  167. GRANT SELECT ON TABLE "process_data" TO postgres;
  168. end if;
  169. ------------------------------------------------------------------------------------------------
  170. --
  171. if not exists(select * from information_schema.tables
  172. where
  173. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  174. and table_name = 'stats_data') then
  175. CREATE TABLE "stats_data"
  176. (
  177. "name" text,
  178. "value" integer,
  179. "total" integer,
  180. "description" text,
  181. "last_update_time" timestamp without time zone,
  182. "last_reset_time" timestamp without time zone,
  183. "last_total_reset_time" timestamp without time zone,
  184. "is_visible" boolean,
  185. "enable_alarm" boolean,
  186. "alarm_value" integer,
  187. "warning_value" integer,
  188. CONSTRAINT "stats_data_pkey" PRIMARY KEY ("name" )
  189. )
  190. WITH (
  191. OIDS=FALSE
  192. );
  193. ALTER TABLE "stats_data"
  194. OWNER TO postgres;
  195. GRANT SELECT ON TABLE "stats_data" TO postgres;
  196. end if;
  197. ------------------------------------------------------------------------------------------------
  198. --
  199. if not exists(select * from information_schema.tables
  200. where
  201. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  202. and table_name = 'PM_statsData') then
  203. CREATE TABLE "PM_statsData"
  204. (
  205. "chamber" text,
  206. "name" text,
  207. "partsNo" text,
  208. "current_cycle" text,
  209. "target_cycle" text,
  210. "current_value" text,
  211. "warning_value" text,
  212. "target_value" text,
  213. "install_Date" timestamp without time zone,
  214. CONSTRAINT "PM_statsData_pkey" PRIMARY KEY ("name" )
  215. )
  216. WITH (
  217. OIDS=FALSE
  218. );
  219. ALTER TABLE "PM_statsData"
  220. OWNER TO postgres;
  221. GRANT SELECT ON TABLE "PM_statsData" TO postgres;
  222. end if;
  223. ------------------------------------------------------------------------------------------------
  224. --
  225. if not exists(select * from information_schema.tables
  226. where
  227. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  228. and table_name = 'PM_statsHistory') then
  229. CREATE TABLE "PM_statsHistory"
  230. (
  231. "id" serial,
  232. "chamber" text,
  233. "name" text,
  234. "partsNo" text,
  235. "current_cycle" text,
  236. "target_cycle" text,
  237. "current_value" text,
  238. "warning_value" text,
  239. "target_value" text,
  240. "install_Date" timestamp without time zone,
  241. CONSTRAINT "PM_statsHistory_pkey" PRIMARY KEY ("id" )
  242. )
  243. WITH (
  244. OIDS=FALSE
  245. );
  246. ALTER TABLE "PM_statsHistory"
  247. OWNER TO postgres;
  248. GRANT SELECT ON TABLE "PM_statsHistory" TO postgres;
  249. end if;
  250. ------------------------------------------------------------------------------------------------
  251. --
  252. if not exists(select * from information_schema.tables
  253. where
  254. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  255. and table_name = 'leak_check_data') then
  256. CREATE TABLE "leak_check_data"
  257. (
  258. "guid" text NOT NULL,
  259. "operate_time" timestamp without time zone,
  260. "status" text,
  261. "leak_rate" real,
  262. "start_pressure" real,
  263. "stop_pressure" real,
  264. "mode" text,
  265. "leak_check_time" integer,
  266. CONSTRAINT "leak_check_data_pkey" PRIMARY KEY ("guid" )
  267. )
  268. WITH (
  269. OIDS=FALSE
  270. );
  271. ALTER TABLE "leak_check_data"
  272. OWNER TO postgres;
  273. GRANT SELECT ON TABLE "leak_check_data" TO postgres;
  274. end if;
  275. ------------------------------------------------------------------------------------------------
  276. --
  277. if not exists(select * from information_schema.tables
  278. where
  279. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  280. and table_name = 'cj_data') then
  281. CREATE TABLE cj_data
  282. (
  283. "guid" text NOT NULL,
  284. "start_time" timestamp without time zone,
  285. "end_time" timestamp without time zone,
  286. "carrier_data_guid" text,
  287. "name" text,
  288. "input_port" text,
  289. "output_port" text,
  290. "total_wafer_count" integer,
  291. "abort_wafer_count" integer,
  292. "unprocessed_wafer_count" integer,
  293. CONSTRAINT "cj_data_pkey" PRIMARY KEY ("guid" )
  294. )
  295. WITH (
  296. OIDS=FALSE
  297. );
  298. ALTER TABLE "cj_data"
  299. OWNER TO postgres;
  300. GRANT SELECT ON TABLE "cj_data" TO postgres;
  301. end if;
  302. ------------------------------------------------------------------------------------------------
  303. --
  304. if not exists(select * from information_schema.tables
  305. where
  306. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  307. and table_name = 'pj_data') then
  308. CREATE TABLE pj_data
  309. (
  310. "guid" text NOT NULL,
  311. "start_time" timestamp without time zone,
  312. "end_time" timestamp without time zone,
  313. "job_name" text,
  314. "batch_id" text,
  315. "recipe_name" text,
  316. "layout_name" text,
  317. "layout_data" text,
  318. "wafer_data" text,
  319. "form" text,
  320. "carrier_data_guid" text,
  321. "cj_data_guid" text,
  322. "name" text,
  323. "input_port" text,
  324. "output_port" text,
  325. "total_wafer_count" integer,
  326. "abort_wafer_count" integer,
  327. "unprocessed_wafer_count" integer,
  328. CONSTRAINT "pj_data_pkey" PRIMARY KEY ("guid" )
  329. )
  330. WITH (
  331. OIDS=FALSE
  332. );
  333. ALTER TABLE "pj_data"
  334. OWNER TO postgres;
  335. GRANT SELECT ON TABLE "pj_data" TO postgres;
  336. end if;
  337. ------------------------------------------------------------------------------------------------
  338. --
  339. if not exists(select * from information_schema.tables
  340. where
  341. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  342. and table_name = 'lot_data') then
  343. CREATE TABLE lot_data
  344. (
  345. "guid" text NOT NULL,
  346. "start_time" timestamp without time zone,
  347. "end_time" timestamp without time zone,
  348. "carrier_data_guid" text,
  349. "cj_data_guid" text,
  350. "name" text,
  351. "input_port" text,
  352. "output_port" text,
  353. "total_wafer_count" integer,
  354. "abort_wafer_count" integer,
  355. "unprocessed_wafer_count" integer,
  356. CONSTRAINT "lot_data_pkey" PRIMARY KEY ("guid" )
  357. )
  358. WITH (
  359. OIDS=FALSE
  360. );
  361. ALTER TABLE "lot_data"
  362. OWNER TO postgres;
  363. GRANT SELECT ON TABLE "lot_data" TO postgres;
  364. end if;
  365. ------------------------------------------------------------------------------------------------
  366. --
  367. if not exists(select * from information_schema.tables
  368. where
  369. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  370. and table_name = 'lot_wafer_data') then
  371. CREATE TABLE lot_wafer_data
  372. (
  373. "guid" text NOT NULL,
  374. "create_time" timestamp without time zone,
  375. "lot_data_guid" text,
  376. "wafer_data_guid" text,
  377. CONSTRAINT "lot_wafer_data_pkey" PRIMARY KEY ("guid" )
  378. )
  379. WITH (
  380. OIDS=FALSE
  381. );
  382. ALTER TABLE "lot_wafer_data"
  383. OWNER TO postgres;
  384. GRANT SELECT ON TABLE "lot_wafer_data" TO postgres;
  385. CREATE INDEX "lot_wafer_data_idx1"
  386. ON "lot_wafer_data"
  387. USING btree
  388. ("lot_data_guid" , "wafer_data_guid" );
  389. end if;
  390. ------------------------------------------------------------------------------------------------
  391. --
  392. if not exists(select * from information_schema.tables
  393. where
  394. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  395. and table_name = 'recipe_step_data') then
  396. CREATE TABLE "recipe_step_data"
  397. (
  398. "guid" text NOT NULL,
  399. "step_begin_time" timestamp without time zone,
  400. "step_end_time" timestamp without time zone,
  401. "step_name" text,
  402. "step_time" real,
  403. "process_data_guid" text,
  404. "step_number" integer,
  405. CONSTRAINT "recipe_step_data_pkey" PRIMARY KEY ("guid" )
  406. )
  407. WITH (
  408. OIDS=FALSE
  409. );
  410. ALTER TABLE "recipe_step_data"
  411. OWNER TO postgres;
  412. GRANT SELECT ON TABLE "recipe_step_data" TO postgres;
  413. CREATE INDEX "recipe_step_data_idx1"
  414. ON "recipe_step_data"
  415. USING btree
  416. ("process_data_guid" , "step_number" );
  417. end if;
  418. ------------------------------------------------------------------------------------------------
  419. --
  420. if not exists(select * from information_schema.tables
  421. where
  422. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  423. and table_name = 'Recipe_History') then
  424. CREATE TABLE "Recipe_History"
  425. (
  426. "guid" text NOT NULL,
  427. "createdBy" text,
  428. "creationTime" timestamp without time zone,
  429. "lastRevisedBy" text,
  430. "lastRevisionTime" timestamp without time zone,
  431. "recipe_description" text,
  432. "recipe_type" text,
  433. "recipe_name" text,
  434. "recipe_path" text,
  435. "recipe_version" text,
  436. "recipe_level" text,
  437. "recipe_premission" text,
  438. "recipe_compare" text,
  439. "recipe_content" text,
  440. CONSTRAINT "Recipe_History_pkey" PRIMARY KEY ("guid" )
  441. )
  442. WITH (
  443. OIDS=FALSE
  444. );
  445. ALTER TABLE "Recipe_History"
  446. OWNER TO postgres;
  447. GRANT SELECT ON TABLE "Recipe_History" TO postgres;
  448. end if;
  449. ------------------------------------------------------------------------------------------------
  450. --
  451. if not exists(select * from information_schema.tables
  452. where
  453. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  454. and table_name = 'schedule_maintenance') then
  455. CREATE TABLE "schedule_maintenance"
  456. (
  457. "maintenance_item" text,
  458. "maintenance_display" text,
  459. "current_value" text,
  460. "scheduling_start_value" text,
  461. "maintenance_limit_value" text,
  462. "maintenance_processing" text,
  463. "unit" text,
  464. "path" text,
  465. "addition_information_name" text,
  466. "addition_information_display" text,
  467. CONSTRAINT "schedule_maintenance_pkey" PRIMARY KEY ("maintenance_item" )
  468. )
  469. WITH (
  470. OIDS=FALSE
  471. );
  472. ALTER TABLE "schedule_maintenance"
  473. OWNER TO postgres;
  474. GRANT SELECT ON TABLE "schedule_maintenance" TO postgres;
  475. end if;
  476. ------------------------------------------------------------------------------------------------
  477. --
  478. end;
  479. $$
  480. language 'plpgsql';
  481. select update_db_model();
  482. CREATE OR REPLACE FUNCTION batch_delete_tables(text)
  483. RETURNS int AS
  484. $$
  485. DECLARE
  486. r RECORD;
  487. count int;
  488. BEGIN
  489. count := 0;
  490. FOR r IN SELECT tablename FROM pg_tables where tablename like $1 || '%' LOOP
  491. RAISE NOTICE 'tablename: %', r.tablename;
  492. EXECUTE 'DROP TABLE "' || r.tablename || '" CASCADE';
  493. count := count + 1;
  494. END LOOP;
  495. RETURN count;
  496. END;
  497. $$
  498. LANGUAGE 'plpgsql' VOLATILE;