CREATE TABLE DEPLOY_STEP (
  ID                 NUMBER NOT NULL,
  PRODUCT_ID         NUMBER NOT NULL,
  PRODUCT_VERSION_ID NUMBER NOT NULL,
  CDCLIENTE          VARCHAR2(21) NOT NULL,
  DEPLOY_DATE        DATE,
  DESCRIPTION        VARCHAR2(500),
  STATUS             VARCHAR2(1) DEFAULT 'P' NOT NULL,
  IS_ACTIVE          VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  
  ORGANIZATION_ID NUMBER NOT NULL,
  CREATED_BY      NUMBER,
  CREATED         DATE DEFAULT SYSDATE NOT NULL,
  UPDATED_BY      NUMBER,
  UPDATED         DATE DEFAULT SYSDATE NOT NULL,
  
  CONSTRAINT PK_DEPLOY_STEP            PRIMARY KEY(ID),
  CONSTRAINT FK_DEPLOY_STEP_PRODUCT    FOREIGN KEY (PRODUCT_ID) REFERENCES PRODUCT (ID),
  CONSTRAINT CKC_DEPLOY_STEP_STATUS    CHECK (STATUS IN ('D', 'E', 'A', 'P')),
  CONSTRAINT CKC_DEPLOY_STEP_IS_ACTIVE CHECK (IS_ACTIVE IN ('Y', 'N'))
)
/
CREATE SEQUENCE DEPLOY_STEP_ID_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1
/
CREATE TABLE DEPLOY_STEP_SERVER (
  ID                NUMBER NOT NULL,
  DEPLOY_STEP_ID    NUMBER NOT NULL,
  PRODUCT_SERVER_ID NUMBER NOT NULL,
  SERVER_ORDER      NUMBER NOT NULL,
  DEPLOY_ID         NUMBER,
  IS_ACTIVE         VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  
  ORGANIZATION_ID NUMBER NOT NULL,
  CREATED_BY      NUMBER,
  CREATED         DATE DEFAULT SYSDATE NOT NULL,
  UPDATED_BY      NUMBER,
  UPDATED         DATE DEFAULT SYSDATE NOT NULL,
  
  CONSTRAINT PK_DEPLOY_STEP_SERVER       PRIMARY KEY(ID),
  CONSTRAINT FK_DEP_ST_SERVER_DEPLOY     FOREIGN KEY (DEPLOY_ID)         REFERENCES DEPLOY (ID),
  CONSTRAINT FK_DEP_ST_SERVER_DEP_ST     FOREIGN KEY (DEPLOY_STEP_ID)    REFERENCES DEPLOY_STEP (ID),
  CONSTRAINT FK_DEP_ST_SERVER_PROD_SRV   FOREIGN KEY (PRODUCT_SERVER_ID) REFERENCES PRODUCT_SERVER (ID),
  CONSTRAINT CKC_DEP_ST_SERVER_IS_ACTIVE CHECK (IS_ACTIVE IN ('Y', 'N'))
)
/
CREATE SEQUENCE DEPLOY_STEP_SERVER_ID_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1
/
ALTER TABLE DEPLOY ADD IS_DEPLOY_STEP VARCHAR2(1) DEFAULT 'N' NOT NULL
/
ALTER TABLE DEPLOY ADD DEPLOY_STEP_SRV_ID NUMBER
/
ALTER TABLE DEPLOY ADD CONSTRAINT FK_DEPLOY_DEP_ST_SRV FOREIGN KEY (DEPLOY_STEP_SRV_ID) REFERENCES DEPLOY_STEP_SERVER (ID)