/* <TRANS_COMMAND>
  ALTER TABLE LAYERS
      ADD isMultiBudget SMALLINT
  /
  ALTER TABLE LAYERDATA
    ADD BUDGETREF NUMBER(10,0);
  /
  ALTER TABLE LAYERDATA ADD(
    CHECK((BUDGETREF<=2147483647)AND(BUDGETREF>-2147483648))
  );
  /
  CREATE INDEX IDX_LAYERDATA_BUDGETREF ON LAYERDATA (BUDGETREF);
  /
  COMMIT WORK
/
*/
-- <TRANS_IGNORE>

DECLARE 
  v_exists integer;
BEGIN
  SELECT count(*) 
    INTO v_exists
    FROM USER_TAB_COLUMNS 
    WHERE TABLE_NAME='LAYERDATA' AND COLUMN_NAME='BUDGETREF';
  IF (v_exists=0) THEN
    EXECUTE IMMEDIATE 'ALTER TABLE LAYERDATA
      ADD BUDGETREF NUMBER(10,0)';
    EXECUTE IMMEDIATE 'ALTER TABLE LAYERS
      ADD isMultiBudget SMALLINT';
    EXECUTE IMMEDIATE 'ALTER TABLE LAYERDATA ADD(
      CHECK((BUDGETREF<=2147483647)AND(BUDGETREF>-2147483648))
    )';
    EXECUTE IMMEDIATE 'CREATE INDEX IDX_LAYERDATA_BUDGETREF ON LAYERDATA (BUDGETREF)';
    EXECUTE IMMEDIATE 'COMMIT WORK';
  END IF;
END;