DBModel.sql 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. --
  143. if not exists(select * from information_schema.tables
  144. where
  145. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  146. and table_name = 'stats_data') then
  147. CREATE TABLE "stats_data"
  148. (
  149. "name" text,
  150. "value" integer,
  151. "total" integer,
  152. "description" text,
  153. "last_update_time" timestamp without time zone,
  154. "last_reset_time" timestamp without time zone,
  155. "last_total_reset_time" timestamp without time zone,
  156. "is_visible" boolean,
  157. "enable_alarm" boolean,
  158. "alarm_value" integer,
  159. CONSTRAINT "stats_data_pkey" PRIMARY KEY ("name" )
  160. )
  161. WITH (
  162. OIDS=FALSE
  163. );
  164. ALTER TABLE "stats_data"
  165. OWNER TO postgres;
  166. GRANT SELECT ON TABLE "stats_data" TO postgres;
  167. end if;
  168. ------------------------------------------------------------------------------------------------
  169. --
  170. if not exists(select * from information_schema.tables
  171. where
  172. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  173. and table_name = 'leak_check_data') then
  174. CREATE TABLE "leak_check_data"
  175. (
  176. "guid" text NOT NULL,
  177. "operate_time" timestamp without time zone,
  178. "status" text,
  179. "leak_rate" real,
  180. "start_pressure" real,
  181. "stop_pressure" real,
  182. "mode" text,
  183. "leak_check_time" integer,
  184. CONSTRAINT "leak_check_data_pkey" PRIMARY KEY ("guid" )
  185. )
  186. WITH (
  187. OIDS=FALSE
  188. );
  189. ALTER TABLE "leak_check_data"
  190. OWNER TO postgres;
  191. GRANT ALL ON TABLE "leak_check_data" TO postgres;
  192. GRANT SELECT ON TABLE "leak_check_data" TO postgres;
  193. end if;
  194. ------------------------------------------------------------------------------------------------
  195. --
  196. if not exists(select * from information_schema.tables
  197. where
  198. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  199. and table_name = 'cj_data') then
  200. CREATE TABLE cj_data
  201. (
  202. "guid" text NOT NULL,
  203. "start_time" timestamp without time zone,
  204. "end_time" timestamp without time zone,
  205. "carrier_data_guid" text,
  206. "name" text,
  207. "input_port" text,
  208. "output_port" text,
  209. CONSTRAINT "cj_data_pkey" PRIMARY KEY ("guid" )
  210. )
  211. WITH (
  212. OIDS=FALSE
  213. );
  214. ALTER TABLE "cj_data"
  215. OWNER TO postgres;
  216. GRANT SELECT ON TABLE "cj_data" TO postgres;
  217. end if;
  218. ------------------------------------------------------------------------------------------------
  219. --
  220. if not exists(select * from information_schema.tables
  221. where
  222. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  223. and table_name = 'mfc_verification_data') then
  224. CREATE TABLE mfc_verification_data
  225. (
  226. "module" text,
  227. "name" text,
  228. "operate_time" timestamp without time zone,
  229. "percent10_setpoint" real,
  230. "percent10_calculate" real,
  231. "percent20_setpoint" real,
  232. "percent20_calculate" real,
  233. "percent30_setpoint" real,
  234. "percent30_calculate" real,
  235. "percent40_setpoint" real,
  236. "percent40_calculate" real,
  237. "percent50_setpoint" real,
  238. "percent50_calculate" real,
  239. "percent60_setpoint" real,
  240. "percent60_calculate" real,
  241. "percent70_setpoint" real,
  242. "percent70_calculate" real,
  243. "percent80_setpoint" real,
  244. "percent80_calculate" real,
  245. "percent90_setpoint" real,
  246. "percent90_calculate" real,
  247. "percent100_setpoint" real,
  248. "percent100_calculate" real,
  249. "setpoint" real,
  250. "calculate" real,
  251. CONSTRAINT "mfc_verification_data_pkey" PRIMARY KEY ("operate_time" )
  252. )
  253. WITH (
  254. OIDS=FALSE
  255. );
  256. ALTER TABLE "mfc_verification_data"
  257. OWNER TO postgres;
  258. GRANT SELECT ON TABLE "mfc_verification_data" TO postgres;
  259. end if;
  260. ------------------------------------------------------------------------------------------------
  261. --
  262. if not exists(select * from information_schema.tables
  263. where
  264. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  265. and table_name = 'mfc_verification_data_onepoint') then
  266. CREATE TABLE mfc_verification_data_onepoint
  267. (
  268. "module" text,
  269. "name" text,
  270. "operate_time" timestamp without time zone,
  271. "setpoint" real,
  272. "calculate" real,
  273. CONSTRAINT "mfc_verification_data_onepoint_pkey" PRIMARY KEY ("operate_time" )
  274. )
  275. WITH (
  276. OIDS=FALSE
  277. );
  278. ALTER TABLE "mfc_verification_data_onepoint"
  279. OWNER TO postgres;
  280. GRANT SELECT ON TABLE "mfc_verification_data_onepoint" TO postgres;
  281. end if;
  282. ------------------------------------------------------------------------------------------------
  283. --
  284. if not exists(select * from information_schema.tables
  285. where
  286. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  287. and table_name = 'mfc_verification_data_tenpoints') then
  288. CREATE TABLE mfc_verification_data_tenpoints
  289. (
  290. "module" text,
  291. "name" text,
  292. "operate_time" timestamp without time zone,
  293. "percent10_setpoint" real,
  294. "percent10_calculate" real,
  295. "percent20_setpoint" real,
  296. "percent20_calculate" real,
  297. "percent30_setpoint" real,
  298. "percent30_calculate" real,
  299. "percent40_setpoint" real,
  300. "percent40_calculate" real,
  301. "percent50_setpoint" real,
  302. "percent50_calculate" real,
  303. "percent60_setpoint" real,
  304. "percent60_calculate" real,
  305. "percent70_setpoint" real,
  306. "percent70_calculate" real,
  307. "percent80_setpoint" real,
  308. "percent80_calculate" real,
  309. "percent90_setpoint" real,
  310. "percent90_calculate" real,
  311. "percent100_setpoint" real,
  312. "percent100_calculate" real,
  313. CONSTRAINT "mfc_verification_data_tenpoints_pkey" PRIMARY KEY ("operate_time" )
  314. )
  315. WITH (
  316. OIDS=FALSE
  317. );
  318. ALTER TABLE "mfc_verification_data_tenpoints"
  319. OWNER TO postgres;
  320. GRANT SELECT ON TABLE "mfc_verification_data_tenpoints" TO postgres;
  321. end if;
  322. ------------------------------------------------------------------------------------------------
  323. --
  324. if not exists(select * from information_schema.tables
  325. where
  326. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  327. and table_name = 'pj_data') then
  328. CREATE TABLE pj_data
  329. (
  330. "guid" text NOT NULL,
  331. "start_time" timestamp without time zone,
  332. "end_time" timestamp without time zone,
  333. "carrier_data_guid" text,
  334. "cj_data_guid" text,
  335. "name" text,
  336. "input_port" text,
  337. "output_port" text,
  338. "total_wafer_count" integer,
  339. "abort_wafer_count" integer,
  340. "unprocessed_wafer_count" integer,
  341. CONSTRAINT "pj_data_pkey" PRIMARY KEY ("guid" )
  342. )
  343. WITH (
  344. OIDS=FALSE
  345. );
  346. ALTER TABLE "pj_data"
  347. OWNER TO postgres;
  348. GRANT SELECT ON TABLE "pj_data" TO postgres;
  349. end if;
  350. ------------------------------------------------------------------------------------------------
  351. --
  352. if not exists(select * from information_schema.tables
  353. where
  354. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  355. and table_name = 'offset_data') then
  356. CREATE TABLE "offset_data"
  357. (
  358. "guid" text NOT NULL,
  359. "source_module" text NOT NULL,
  360. "source_slot" integer NOT NULL,
  361. "destination_module" text NOT NULL,
  362. "destination_slot" integer NOT NULL,
  363. "origin_module" text NOT NULL,
  364. "origin_slot" integer NOT NULL,
  365. "arm_position" text NOT NULL,
  366. "arm_pan" text NOT NULL,
  367. "offset_x" real NOT NULL,
  368. "offset_y" real NOT NULL,
  369. "offset_d" real NOT NULL,
  370. "start_time" timestamp without time zone,
  371. "end_time" timestamp without time zone,
  372. CONSTRAINT "offset_data_pkey" PRIMARY KEY ("guid","start_time","end_time")
  373. )
  374. WITH (
  375. OIDS=FALSE
  376. );
  377. ALTER TABLE "offset_data"
  378. OWNER TO postgres;
  379. GRANT SELECT ON TABLE "offset_data" TO postgres;
  380. end if;
  381. ------------------------------------------------------------------------------------------------
  382. --
  383. if not exists(select * from information_schema.tables
  384. where
  385. table_catalog = CURRENT_CATALOG and table_schema = CURRENT_SCHEMA
  386. and table_name = 'stats_data_rf_pump') then
  387. CREATE TABLE "stats_data_rf_pump"
  388. (
  389. "name" text,
  390. "description" text,
  391. "last_pm_time" timestamp without time zone,
  392. "from_last_pm" real,
  393. "total" real,
  394. "pm_interval" real,
  395. "enable_alarm" boolean,
  396. CONSTRAINT "stats_data_rf_pump_pkey" PRIMARY KEY ("name" )
  397. )
  398. WITH (
  399. OIDS=FALSE
  400. );
  401. ALTER TABLE "stats_data_rf_pump"
  402. OWNER TO postgres;
  403. GRANT SELECT ON TABLE "stats_data_rf_pump" TO postgres;
  404. end if;
  405. ------------------------------------------------------------------------------------------------
  406. --
  407. end;
  408. $$
  409. language 'plpgsql';
  410. select update_db_model();
  411. CREATE OR REPLACE FUNCTION batch_delete_tables(text)
  412. RETURNS int AS
  413. $$
  414. DECLARE
  415. r RECORD;
  416. count int;
  417. BEGIN
  418. count := 0;
  419. FOR r IN SELECT tablename FROM pg_tables where tablename like $1 || '%' LOOP
  420. RAISE NOTICE 'tablename: %', r.tablename;
  421. EXECUTE 'DROP TABLE "' || r.tablename || '" CASCADE';
  422. count := count + 1;
  423. END LOOP;
  424. RETURN count;
  425. END;
  426. $$
  427. LANGUAGE 'plpgsql' VOLATILE;