DBModel.sql 16 KB

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