DBModel.sql 18 KB

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