DBModel.sql 16 KB

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