--UPDATE FROM 8.8.4.5 TO 8.8.4.6


DROP TABLE VERSION_8_8_4_5;


/*  VERSION_8_8_4_6  */
CREATE TABLE VERSION_8_8_4_6 (
	 DUMMY	NUMBER	    NULL
)
;


CREATE TABLE WINT (
  WINT_ID NUMBER(30) NOT NULL
  ,WINT_INTERVAL NUMBER(3) NOT NULL
  ,WINT_INTERVALTYPE NUMBER(1) NOT NULL
  ,WINT_SNAP NUMBER(1) NOT NULL
  ,CONSTRAINT WINT_PK PRIMARY KEY (WINT_ID) USING INDEX TABLESPACE V8INDEX) TABLESPACE V8MAIN;

CREATE SEQUENCE SEQ_WINT INCREMENT BY 1 START WITH 1000 NOMAXVALUE NOCYCLE NOCACHE NOORDER;

COMMENT ON TABLE WINT IS 'interval table for table reservations';

COMMENT ON COLUMN WINT.WINT_ID IS 'ID';

COMMENT ON COLUMN WINT.WINT_INTERVAL IS 'interval';

COMMENT ON COLUMN WINT.WINT_INTERVALTYPE IS 'interval type; 0 - minutes; 1 - hours; 2 - days; 3 - weeks; 4 - months';

COMMENT ON COLUMN WINT.WINT_SNAP IS 'used as snap also';

INSERT INTO WINT(WINT_ID, WINT_INTERVAL, WINT_INTERVALTYPE, WINT_SNAP) (SELECT SEQ_WINT.NEXTVAL, 30, 0, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM WINT WHERE WINT_INTERVAL = 30 AND WINT_INTERVALTYPE = 0 AND WINT_SNAP = 1));

INSERT INTO WINT(WINT_ID, WINT_INTERVAL, WINT_INTERVALTYPE, WINT_SNAP) (SELECT SEQ_WINT.NEXTVAL, 1, 1, 0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM WINT WHERE WINT_INTERVAL = 1 AND WINT_INTERVALTYPE = 1 AND WINT_SNAP = 0));

INSERT INTO WINT(WINT_ID, WINT_INTERVAL, WINT_INTERVALTYPE, WINT_SNAP) (SELECT SEQ_WINT.NEXTVAL, 4, 1, 0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM WINT WHERE WINT_INTERVAL = 4 AND WINT_INTERVALTYPE = 1 AND WINT_SNAP = 0));

INSERT INTO WINT(WINT_ID, WINT_INTERVAL, WINT_INTERVALTYPE, WINT_SNAP) (SELECT SEQ_WINT.NEXTVAL, 1, 3, 0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM WINT WHERE WINT_INTERVAL = 1 AND WINT_INTERVALTYPE = 3 AND WINT_SNAP = 0));

INSERT INTO WINT(WINT_ID, WINT_INTERVAL, WINT_INTERVALTYPE, WINT_SNAP) (SELECT SEQ_WINT.NEXTVAL, 2, 3, 0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM WINT WHERE WINT_INTERVAL = 2 AND WINT_INTERVALTYPE = 3 AND WINT_SNAP = 0));

INSERT INTO WINT(WINT_ID, WINT_INTERVAL, WINT_INTERVALTYPE, WINT_SNAP) (SELECT SEQ_WINT.NEXTVAL, 1, 4, 0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM WINT WHERE WINT_INTERVAL = 1 AND WINT_INTERVALTYPE = 4 AND WINT_SNAP = 0));

UPDATE WUSS SET WUSS_VALUE=(SELECT MIN(WINT_ID) FROM WINT WHERE NVL(WINT_SNAP, 0) =1 ) WHERE WUSS_NAME='TableReservationSnap';
