DBModel.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. CONSTRAINT "wafer_data_pkey" PRIMARY KEY ("guid" )
  53. )
  54. WITH (
  55. OIDS=FALSE
  56. );
  57. ALTER TABLE "wafer_data"
  58. OWNER TO postgres;
  59. GRANT SELECT ON TABLE "wafer_data" TO postgres;
  60. end if;
  61. ------------------------------------------------------------------------------------------------
  62. --
  63. if not exists(select * from information_schema.tables
  64. where
  65. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  66. and table_name = 'event_data') then
  67. CREATE TABLE "event_data"
  68. (
  69. "gid" serial NOT NULL,
  70. "event_id" integer,
  71. "event_enum" text,
  72. "type" text,
  73. "source" text,
  74. "description" text,
  75. "level" text,
  76. "occur_time" timestamp without time zone,
  77. CONSTRAINT "event_data_pkey" PRIMARY KEY ("gid" )
  78. )
  79. WITH (
  80. OIDS=FALSE
  81. );
  82. --ALTER TABLE "EventManager"
  83. --OWNER TO postgres;
  84. GRANT ALL ON TABLE "event_data" TO postgres;
  85. GRANT SELECT ON TABLE "event_data" TO postgres;
  86. CREATE INDEX "event_data_occur_time_event_id_idx"
  87. ON "event_data"
  88. USING btree
  89. ("occur_time" , "event_id" );
  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 = 'wafer_move_history') then
  97. CREATE TABLE "wafer_move_history"
  98. (
  99. "gid" serial NOT NULL,
  100. "wafer_data_guid" text,
  101. "arrive_time" timestamp without time zone,
  102. "station" text,
  103. "slot" text,
  104. "status" text,
  105. CONSTRAINT "wafer_move_history_pkey" PRIMARY KEY ("gid" )
  106. )
  107. WITH (
  108. OIDS=FALSE
  109. );
  110. ALTER TABLE "wafer_move_history"
  111. OWNER TO postgres;
  112. GRANT SELECT ON TABLE "wafer_move_history" TO postgres;
  113. end if;
  114. ------------------------------------------------------------------------------------------------
  115. --
  116. if not exists(select * from information_schema.tables
  117. where
  118. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  119. and table_name = 'process_data') then
  120. CREATE TABLE "process_data"
  121. (
  122. "guid" text NOT NULL,
  123. "process_begin_time" timestamp without time zone,
  124. "process_end_time" timestamp without time zone,
  125. "recipe_name" text,
  126. "chuck_name" text,
  127. "dechuck_name" text,
  128. "process_status" text,
  129. "wafer_data_guid" text,
  130. "process_in" text,
  131. "recipe_type" text,
  132. CONSTRAINT "process_data_pkey" PRIMARY KEY ("guid" )
  133. )
  134. WITH (
  135. OIDS=FALSE
  136. );
  137. ALTER TABLE "process_data"
  138. OWNER TO postgres;
  139. GRANT SELECT ON TABLE "process_data" TO postgres;
  140. end if;
  141. ------------------------------------------------------------------------------------------------
  142. if not exists(select * from information_schema.COLUMNS
  143. where
  144. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  145. and table_name = 'process_data' and column_name = 'recipe_type')
  146. then
  147. ALTER TABLE "process_data" ADD COLUMN "recipe_type" TEXT;
  148. ALTER TABLE "process_data"
  149. OWNER TO postgres;
  150. GRANT SELECT ON TABLE "process_data" TO postgres;
  151. end if ;
  152. ------------------------------------------------------------------------------------------------
  153. --
  154. if not exists(select * from information_schema.tables
  155. where
  156. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  157. and table_name = 'stats_data') then
  158. CREATE TABLE "stats_data"
  159. (
  160. "name" text,
  161. "value" integer,
  162. "total" integer,
  163. "description" text,
  164. "last_update_time" timestamp without time zone,
  165. "last_reset_time" timestamp without time zone,
  166. "last_total_reset_time" timestamp without time zone,
  167. "is_visible" boolean,
  168. "enable_warning" boolean,
  169. "warning_value" integer,
  170. "enable_alarm" boolean,
  171. "alarm_value" integer,
  172. CONSTRAINT "stats_data_pkey" PRIMARY KEY ("name" )
  173. )
  174. WITH (
  175. OIDS=FALSE
  176. );
  177. ALTER TABLE "stats_data"
  178. OWNER TO postgres;
  179. GRANT SELECT ON TABLE "stats_data" TO postgres;
  180. end if;
  181. ------------------------------------------------------------------------------------------------
  182. if not exists(select * from information_schema.COLUMNS
  183. where
  184. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  185. and table_name = 'stats_data' and column_name = 'enable_warning')
  186. then
  187. ALTER TABLE "stats_data" ADD COLUMN "enable_warning" TEXT;
  188. ALTER TABLE "stats_data"
  189. OWNER TO postgres;
  190. GRANT SELECT ON TABLE "stats_data" TO postgres;
  191. end if ;
  192. ------------------------------------------------------------------------------------------------
  193. if not exists(select * from information_schema.COLUMNS
  194. where
  195. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  196. and table_name = 'stats_data' and column_name = 'warning_value')
  197. then
  198. ALTER TABLE "stats_data" ADD COLUMN "warning_value" TEXT;
  199. ALTER TABLE "stats_data"
  200. OWNER TO postgres;
  201. GRANT SELECT ON TABLE "stats_data" TO postgres;
  202. end if ;
  203. ------------------------------------------------------------------------------------------------
  204. --
  205. if not exists(select * from information_schema.tables
  206. where
  207. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  208. and table_name = 'leak_check_data') then
  209. CREATE TABLE "leak_check_data"
  210. (
  211. "guid" text NOT NULL,
  212. "operate_time" timestamp without time zone,
  213. "status" text,
  214. "leak_rate" real,
  215. "start_pressure" real,
  216. "stop_pressure" real,
  217. "mode" text,
  218. "leak_check_time" integer,
  219. CONSTRAINT "leak_check_data_pkey" PRIMARY KEY ("guid" )
  220. )
  221. WITH (
  222. OIDS=FALSE
  223. );
  224. ALTER TABLE "leak_check_data"
  225. OWNER TO postgres;
  226. GRANT ALL ON TABLE "leak_check_data" TO postgres;
  227. GRANT SELECT ON TABLE "leak_check_data" TO postgres;
  228. end if;
  229. ------------------------------------------------------------------------------------------------
  230. --
  231. if not exists(select * from information_schema.tables
  232. where
  233. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  234. and table_name = 'cj_data') then
  235. CREATE TABLE cj_data
  236. (
  237. "guid" text NOT NULL,
  238. "start_time" timestamp without time zone,
  239. "end_time" timestamp without time zone,
  240. "carrier_data_guid" text,
  241. "name" text,
  242. "input_port" text,
  243. "output_port" text,
  244. CONSTRAINT "cj_data_pkey" PRIMARY KEY ("guid" )
  245. )
  246. WITH (
  247. OIDS=FALSE
  248. );
  249. ALTER TABLE "cj_data"
  250. OWNER TO postgres;
  251. GRANT SELECT ON TABLE "cj_data" TO postgres;
  252. end if;
  253. ------------------------------------------------------------------------------------------------
  254. --
  255. if not exists(select * from information_schema.tables
  256. where
  257. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  258. and table_name = 'mfc_verification_data') then
  259. CREATE TABLE mfc_verification_data
  260. (
  261. "module" text,
  262. "name" text,
  263. "operate_time" timestamp without time zone,
  264. "percent10_setpoint" real,
  265. "percent10_calculate" real,
  266. "percent20_setpoint" real,
  267. "percent20_calculate" real,
  268. "percent30_setpoint" real,
  269. "percent30_calculate" real,
  270. "percent40_setpoint" real,
  271. "percent40_calculate" real,
  272. "percent50_setpoint" real,
  273. "percent50_calculate" real,
  274. "percent60_setpoint" real,
  275. "percent60_calculate" real,
  276. "percent70_setpoint" real,
  277. "percent70_calculate" real,
  278. "percent80_setpoint" real,
  279. "percent80_calculate" real,
  280. "percent90_setpoint" real,
  281. "percent90_calculate" real,
  282. "percent100_setpoint" real,
  283. "percent100_calculate" real,
  284. "setpoint" real,
  285. "calculate" real,
  286. CONSTRAINT "mfc_verification_data_pkey" PRIMARY KEY ("operate_time" )
  287. )
  288. WITH (
  289. OIDS=FALSE
  290. );
  291. ALTER TABLE "mfc_verification_data"
  292. OWNER TO postgres;
  293. GRANT SELECT ON TABLE "mfc_verification_data" TO postgres;
  294. end if;
  295. ------------------------------------------------------------------------------------------------
  296. --
  297. if not exists(select * from information_schema.tables
  298. where
  299. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  300. and table_name = 'mfc_verification_data_onepoint') then
  301. CREATE TABLE mfc_verification_data_onepoint
  302. (
  303. "module" text,
  304. "name" text,
  305. "operate_time" timestamp without time zone,
  306. "setpoint" real,
  307. "calculate" real,
  308. CONSTRAINT "mfc_verification_data_onepoint_pkey" PRIMARY KEY ("operate_time" )
  309. )
  310. WITH (
  311. OIDS=FALSE
  312. );
  313. ALTER TABLE "mfc_verification_data_onepoint"
  314. OWNER TO postgres;
  315. GRANT SELECT ON TABLE "mfc_verification_data_onepoint" 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 = 'mfc_verification_data_tenpoints') then
  323. CREATE TABLE mfc_verification_data_tenpoints
  324. (
  325. "module" text,
  326. "name" text,
  327. "operate_time" timestamp without time zone,
  328. "percent10_setpoint" real,
  329. "percent10_calculate" real,
  330. "percent20_setpoint" real,
  331. "percent20_calculate" real,
  332. "percent30_setpoint" real,
  333. "percent30_calculate" real,
  334. "percent40_setpoint" real,
  335. "percent40_calculate" real,
  336. "percent50_setpoint" real,
  337. "percent50_calculate" real,
  338. "percent60_setpoint" real,
  339. "percent60_calculate" real,
  340. "percent70_setpoint" real,
  341. "percent70_calculate" real,
  342. "percent80_setpoint" real,
  343. "percent80_calculate" real,
  344. "percent90_setpoint" real,
  345. "percent90_calculate" real,
  346. "percent100_setpoint" real,
  347. "percent100_calculate" real,
  348. CONSTRAINT "mfc_verification_data_tenpoints_pkey" PRIMARY KEY ("operate_time" )
  349. )
  350. WITH (
  351. OIDS=FALSE
  352. );
  353. ALTER TABLE "mfc_verification_data_tenpoints"
  354. OWNER TO postgres;
  355. GRANT SELECT ON TABLE "mfc_verification_data_tenpoints" TO postgres;
  356. end if;
  357. ------------------------------------------------------------------------------------------------
  358. --
  359. if not exists(select * from information_schema.tables
  360. where
  361. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  362. and table_name = 'pj_data') then
  363. CREATE TABLE pj_data
  364. (
  365. "guid" text NOT NULL,
  366. "start_time" timestamp without time zone,
  367. "end_time" timestamp without time zone,
  368. "carrier_data_guid" text,
  369. "cj_data_guid" text,
  370. "name" text,
  371. "input_port" text,
  372. "output_port" text,
  373. "total_wafer_count" integer,
  374. "abort_wafer_count" integer,
  375. "unprocessed_wafer_count" integer,
  376. CONSTRAINT "pj_data_pkey" PRIMARY KEY ("guid" )
  377. )
  378. WITH (
  379. OIDS=FALSE
  380. );
  381. ALTER TABLE "pj_data"
  382. OWNER TO postgres;
  383. GRANT SELECT ON TABLE "pj_data" TO postgres;
  384. end if;
  385. ------------------------------------------------------------------------------------------------
  386. --
  387. if not exists(select * from information_schema.tables
  388. where
  389. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  390. and table_name = 'offset_data') then
  391. CREATE TABLE "offset_data"
  392. (
  393. "guid" text NOT NULL,
  394. "source_module" text NOT NULL,
  395. "source_slot" integer NOT NULL,
  396. "destination_module" text NOT NULL,
  397. "destination_slot" integer NOT NULL,
  398. "origin_module" text NOT NULL,
  399. "origin_slot" integer NOT NULL,
  400. "arm_position" text NOT NULL,
  401. "arm_pan" text NOT NULL,
  402. "offset_x" real NOT NULL,
  403. "offset_y" real NOT NULL,
  404. "offset_d" real NOT NULL,
  405. "start_time" timestamp without time zone,
  406. "end_time" timestamp without time zone,
  407. CONSTRAINT "offset_data_pkey" PRIMARY KEY ("guid","start_time","end_time")
  408. )
  409. WITH (
  410. OIDS=FALSE
  411. );
  412. ALTER TABLE "offset_data"
  413. OWNER TO postgres;
  414. GRANT SELECT ON TABLE "offset_data" TO postgres;
  415. end if;
  416. ------------------------------------------------------------------------------------------------
  417. --
  418. if not exists(select * from information_schema.tables
  419. where
  420. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  421. and table_name = 'stats_data_rf_pump') then
  422. CREATE TABLE "stats_data_rf_pump"
  423. (
  424. "name" text,
  425. "description" text,
  426. "last_pm_time" timestamp without time zone,
  427. "from_last_pm" real,
  428. "total" real,
  429. "pm_interval" real,
  430. "enable_alarm" boolean,
  431. CONSTRAINT "stats_data_rf_pump_pkey" PRIMARY KEY ("name" )
  432. )
  433. WITH (
  434. OIDS=FALSE
  435. );
  436. ALTER TABLE "stats_data_rf_pump"
  437. OWNER TO postgres;
  438. GRANT SELECT ON TABLE "stats_data_rf_pump" TO postgres;
  439. end if;
  440. ------------------------------------------------------------------------------------------------
  441. --
  442. end;
  443. $$
  444. language 'plpgsql';
  445. select update_db_model();
  446. CREATE OR REPLACE FUNCTION batch_delete_tables(text)
  447. RETURNS int AS
  448. $$
  449. DECLARE
  450. r RECORD;
  451. count int;
  452. BEGIN
  453. count := 0;
  454. FOR r IN SELECT tablename FROM pg_tables where tablename like $1 || '%' LOOP
  455. RAISE NOTICE 'tablename: %', r.tablename;
  456. EXECUTE 'DROP TABLE "' || r.tablename || '" CASCADE';
  457. count := count + 1;
  458. END LOOP;
  459. RETURN count;
  460. END;
  461. $$
  462. LANGUAGE 'plpgsql' VOLATILE;