DBModel.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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 = 'wafer_data') then
  34. CREATE TABLE "wafer_data"
  35. (
  36. "guid" text NOT NULL,
  37. "create_time" timestamp without time zone,
  38. "delete_time" timestamp without time zone,
  39. "carrier_data_guid" text,
  40. "create_station" text,
  41. "create_slot" text,
  42. "process_data_guid" text,
  43. "wafer_id" text,
  44. "lasermarker1" text,
  45. "lasermarker2" text,
  46. "lasermarker3" text,
  47. "t7code1" text,
  48. "t7code2" text,
  49. "t7code3" text,
  50. "pj_data_guid" text,
  51. "lot_data_guid" text,
  52. "lot_id" text,
  53. "notch_angle" real,
  54. "sequence_name" text,
  55. "process_status" text,
  56. CONSTRAINT "wafer_data_pkey" PRIMARY KEY ("guid" )
  57. )
  58. WITH (
  59. OIDS=FALSE
  60. );
  61. ALTER TABLE "wafer_data"
  62. OWNER TO postgres;
  63. GRANT SELECT ON TABLE "wafer_data" TO postgres;
  64. end if;
  65. ------------------------------------------------------------------------------------------------
  66. --
  67. if not exists(select * from information_schema.tables
  68. where
  69. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  70. and table_name = 'event_data') then
  71. CREATE TABLE "event_data"
  72. (
  73. "gid" serial NOT NULL,
  74. "event_id" integer,
  75. "event_enum" text,
  76. "type" text,
  77. "source" text,
  78. "description" text,
  79. "level" text,
  80. "occur_time" timestamp without time zone,
  81. CONSTRAINT "event_data_pkey" PRIMARY KEY ("gid" )
  82. )
  83. WITH (
  84. OIDS=FALSE
  85. );
  86. --ALTER TABLE "EventManager"
  87. --OWNER TO postgres;
  88. GRANT ALL ON TABLE "event_data" TO postgres;
  89. GRANT SELECT ON TABLE "event_data" TO postgres;
  90. CREATE INDEX "event_data_occur_time_event_id_idx"
  91. ON "event_data"
  92. USING btree
  93. ("occur_time" , "event_id" );
  94. end if;
  95. ------------------------------------------------------------------------------------------------
  96. --
  97. if not exists(select * from information_schema.tables
  98. where
  99. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  100. and table_name = 'wafer_move_history') then
  101. CREATE TABLE "wafer_move_history"
  102. (
  103. "gid" serial NOT NULL,
  104. "wafer_data_guid" text,
  105. "arrive_time" timestamp without time zone,
  106. "station" text,
  107. "slot" text,
  108. "status" text,
  109. CONSTRAINT "wafer_move_history_pkey" PRIMARY KEY ("gid" )
  110. )
  111. WITH (
  112. OIDS=FALSE
  113. );
  114. ALTER TABLE "wafer_move_history"
  115. OWNER TO postgres;
  116. GRANT SELECT ON TABLE "wafer_move_history" TO postgres;
  117. end if;
  118. ------------------------------------------------------------------------------------------------
  119. --
  120. if not exists(select * from information_schema.tables
  121. where
  122. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  123. and table_name = 'process_data') then
  124. CREATE TABLE "process_data"
  125. (
  126. "gid"serial NOT NULL,
  127. "guid" text NOT NULL,
  128. "process_begin_time" timestamp without time zone,
  129. "process_end_time" timestamp without time zone,
  130. "recipe_name" text,
  131. "process_status" text,
  132. "wafer_data_guid" text,
  133. "slot_id"text,
  134. "lot_id" text,
  135. "process_in" text,
  136. CONSTRAINT "process_data_pkey" PRIMARY KEY ("gid" )
  137. )
  138. WITH (
  139. OIDS=FALSE
  140. );
  141. ALTER TABLE "process_data"
  142. OWNER TO postgres;
  143. GRANT SELECT ON TABLE "process_data" TO postgres;
  144. end if;
  145. ------------------------------------------------------------------------------------------------
  146. --
  147. if not exists(select * from information_schema.tables
  148. where
  149. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  150. and table_name = 'stats_data') then
  151. CREATE TABLE "stats_data"
  152. (
  153. "name" text,
  154. "value" integer,
  155. "total" integer,
  156. "description" text,
  157. "last_update_time" timestamp without time zone,
  158. "last_reset_time" timestamp without time zone,
  159. "last_total_reset_time" timestamp without time zone,
  160. "is_visible" boolean,
  161. "enable_warning" boolean,
  162. "warning_value" integer,
  163. "enable_alarm" boolean,
  164. "alarm_value" integer,
  165. CONSTRAINT "stats_data_pkey" PRIMARY KEY ("name" )
  166. )
  167. WITH (
  168. OIDS=FALSE
  169. );
  170. ALTER TABLE "stats_data"
  171. OWNER TO postgres;
  172. GRANT SELECT ON TABLE "stats_data" TO postgres;
  173. end if;
  174. ------------------------------------------------------------------------------------------------
  175. --
  176. if not exists(select * from information_schema.tables
  177. where
  178. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  179. and table_name = 'PM_statsData') then
  180. CREATE TABLE "PM_statsData"
  181. (
  182. "chamber" text,
  183. "name" text,
  184. "partsNo" text,
  185. "current_cycle" text,
  186. "target_cycle" text,
  187. "current_value" text,
  188. "warning_value" text,
  189. "target_value" text,
  190. "install_Date" timestamp without time zone,
  191. CONSTRAINT "PM_statsData_pkey" PRIMARY KEY ("name" )
  192. )
  193. WITH (
  194. OIDS=FALSE
  195. );
  196. ALTER TABLE "PM_statsData"
  197. OWNER TO postgres;
  198. GRANT SELECT ON TABLE "PM_statsData" TO postgres;
  199. end if;
  200. ------------------------------------------------------------------------------------------------
  201. --
  202. if not exists(select * from information_schema.tables
  203. where
  204. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  205. and table_name = 'PM_statsHistory') then
  206. CREATE TABLE "PM_statsHistory"
  207. (
  208. "id" serial,
  209. "chamber" text,
  210. "name" text,
  211. "partsNo" text,
  212. "current_cycle" text,
  213. "target_cycle" text,
  214. "current_value" text,
  215. "warning_value" text,
  216. "target_value" text,
  217. "install_Date" timestamp without time zone,
  218. CONSTRAINT "PM_statsHistory_pkey" PRIMARY KEY ("id" )
  219. )
  220. WITH (
  221. OIDS=FALSE
  222. );
  223. ALTER TABLE "PM_statsHistory"
  224. OWNER TO postgres;
  225. GRANT SELECT ON TABLE "PM_statsHistory" TO postgres;
  226. end if;
  227. ------------------------------------------------------------------------------------------------
  228. --
  229. if not exists(select * from information_schema.tables
  230. where
  231. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  232. and table_name = 'stats_data_rf_pump') then
  233. CREATE TABLE "stats_data_rf_pump"
  234. (
  235. "name" text,
  236. "description" text,
  237. "last_pm_time" timestamp without time zone,
  238. "from_last_pm" real,
  239. "total" real,
  240. "pm_interval" real,
  241. "enable_alarm" boolean,
  242. CONSTRAINT "stats_data_rf_pump_pkey" PRIMARY KEY ("name" )
  243. )
  244. WITH (
  245. OIDS=FALSE
  246. );
  247. ALTER TABLE "stats_data_rf_pump"
  248. OWNER TO postgres;
  249. GRANT SELECT ON TABLE "stats_data_rf_pump" 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. "carrier_data_guid" text,
  315. "cj_data_guid" text,
  316. "name" text,
  317. "input_port" text,
  318. "output_port" text,
  319. "total_wafer_count" integer,
  320. "abort_wafer_count" integer,
  321. "unprocessed_wafer_count" integer,
  322. CONSTRAINT "pj_data_pkey" PRIMARY KEY ("guid" )
  323. )
  324. WITH (
  325. OIDS=FALSE
  326. );
  327. ALTER TABLE "pj_data"
  328. OWNER TO postgres;
  329. GRANT SELECT ON TABLE "pj_data" TO postgres;
  330. end if;
  331. ------------------------------------------------------------------------------------------------
  332. --
  333. if not exists(select * from information_schema.tables
  334. where
  335. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  336. and table_name = 'lot_data') then
  337. CREATE TABLE lot_data
  338. (
  339. "guid" text NOT NULL,
  340. "start_time" timestamp without time zone,
  341. "end_time" timestamp without time zone,
  342. "carrier_data_guid" text,
  343. "cj_data_guid" text,
  344. "name" text,
  345. "input_port" text,
  346. "output_port" text,
  347. "total_wafer_count" integer,
  348. "abort_wafer_count" integer,
  349. "unprocessed_wafer_count" integer,
  350. CONSTRAINT "lot_data_pkey" PRIMARY KEY ("guid" )
  351. )
  352. WITH (
  353. OIDS=FALSE
  354. );
  355. ALTER TABLE "lot_data"
  356. OWNER TO postgres;
  357. GRANT SELECT ON TABLE "lot_data" TO postgres;
  358. end if;
  359. ------------------------------------------------------------------------------------------------
  360. --
  361. if not exists(select * from information_schema.tables
  362. where
  363. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  364. and table_name = 'lot_wafer_data') then
  365. CREATE TABLE lot_wafer_data
  366. (
  367. "guid" text NOT NULL,
  368. "create_time" timestamp without time zone,
  369. "lot_data_guid" text,
  370. "wafer_data_guid" text,
  371. CONSTRAINT "lot_wafer_data_pkey" PRIMARY KEY ("guid" )
  372. )
  373. WITH (
  374. OIDS=FALSE
  375. );
  376. ALTER TABLE "lot_wafer_data"
  377. OWNER TO postgres;
  378. GRANT SELECT ON TABLE "lot_wafer_data" TO postgres;
  379. CREATE INDEX "lot_wafer_data_idx1"
  380. ON "lot_wafer_data"
  381. USING btree
  382. ("lot_data_guid" , "wafer_data_guid" );
  383. end if;
  384. ------------------------------------------------------------------------------------------------
  385. --
  386. if not exists(select * from information_schema.tables
  387. where
  388. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  389. and table_name = 'recipe_step_data') then
  390. CREATE TABLE "recipe_step_data"
  391. (
  392. "guid" text NOT NULL,
  393. "step_begin_time" timestamp without time zone,
  394. "step_end_time" timestamp without time zone,
  395. "step_name" text,
  396. "step_time" real,
  397. "process_data_guid" text,
  398. "step_number" integer,
  399. CONSTRAINT "recipe_step_data_pkey" PRIMARY KEY ("guid" )
  400. )
  401. WITH (
  402. OIDS=FALSE
  403. );
  404. ALTER TABLE "recipe_step_data"
  405. OWNER TO postgres;
  406. GRANT SELECT ON TABLE "recipe_step_data" TO postgres;
  407. CREATE INDEX "recipe_step_data_idx1"
  408. ON "recipe_step_data"
  409. USING btree
  410. ("process_data_guid" , "step_number" );
  411. end if;
  412. ------------------------------------------------------------------------------------------------
  413. --
  414. if not exists(select * from information_schema.tables
  415. where
  416. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  417. and table_name = 'mfc_verification_data') then
  418. CREATE TABLE "mfc_verification_data"
  419. (
  420. "module" text,
  421. "name" text,
  422. "operate_time" timestamp without time zone,
  423. "percent10_setpoint" real,
  424. "percent10_calculate" real,
  425. "percent20_setpoint" real,
  426. "percent20_calculate" real,
  427. "percent30_setpoint" real,
  428. "percent30_calculate" real,
  429. "percent40_setpoint" real,
  430. "percent40_calculate" real,
  431. "percent50_setpoint" real,
  432. "percent50_calculate" real,
  433. "percent60_setpoint" real,
  434. "percent60_calculate" real,
  435. "percent70_setpoint" real,
  436. "percent70_calculate" real,
  437. "percent80_setpoint" real,
  438. "percent80_calculate" real,
  439. "percent90_setpoint" real,
  440. "percent90_calculate" real,
  441. "percent100_setpoint" real,
  442. "percent100_calculate" real,
  443. "setpoint" real,
  444. "calculate" real,
  445. CONSTRAINT "mfc_verification_data_pkey" PRIMARY KEY ("operate_time" )
  446. )
  447. WITH (
  448. OIDS=FALSE
  449. );
  450. ALTER TABLE "mfc_verification_data"
  451. OWNER TO postgres;
  452. GRANT SELECT ON TABLE "mfc_verification_data" TO postgres;
  453. end if;
  454. ------------------------------------------------------------------------------------------------
  455. --
  456. end;
  457. $$
  458. language 'plpgsql';
  459. select update_db_model();
  460. CREATE OR REPLACE FUNCTION batch_delete_tables(text)
  461. RETURNS int AS
  462. $$
  463. DECLARE
  464. r RECORD;
  465. count int;
  466. BEGIN
  467. count := 0;
  468. FOR r IN SELECT tablename FROM pg_tables where tablename like $1 || '%' LOOP
  469. RAISE NOTICE 'tablename: %', r.tablename;
  470. EXECUTE 'DROP TABLE "' || r.tablename || '" CASCADE';
  471. count := count + 1;
  472. END LOOP;
  473. RETURN count;
  474. END;
  475. $$
  476. LANGUAGE 'plpgsql' VOLATILE;