
/*------ ATD 322599 ------*/
DECLARE v_count NUMBER:=0;

BEGIN

SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CATEGORY_ECOMMERCE';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'create table CATEGORY_ECOMMERCE (ID INT NOT NULL, NAME VARCHAR2(100) NOT NULL)';
EXECUTE IMMEDIATE 'ALTER TABLE CATEGORY_ECOMMERCE ADD CONSTRAINT PK_CATEGORY_ECOMMERCE PRIMARY KEY (ID)';

END IF;

SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'BRAND_ECOMMERCE';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'create table BRAND_ECOMMERCE(ID INT NOT NULL, NAME VARCHAR2(100) NOT NULL)';
EXECUTE IMMEDIATE 'ALTER TABLE BRAND_ECOMMERCE ADD CONSTRAINT PK_BRAND_ECCOMERCE PRIMARY KEY (ID)';

END IF;

SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'PRODUCT_ECOMMERCE';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'create table PRODUCT_ECOMMERCE (
ID INT ,
NAME varchar2(150),
DESCRIPTION  varchar2(254),
DESCRIPTIONSHORT varchar2(254),
CATEGORYID int,
BRANDID int,
REFID varchar2(200),
METATAGDESCRIPTION varchar2(254),
TITLE varchar2(150),
KEYWORDS varchar2(254),
LINKID varchar2(254)
)';
EXECUTE IMMEDIATE 'ALTER TABLE PRODUCT_ECOMMERCE ADD CONSTRAINT PK_PRODUCT_ECOMMERCE PRIMARY KEY (ID)';

END IF;

SELECT Count(1) INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'SKU_ECOMMERCE';

IF v_count = 0 THEN

EXECUTE IMMEDIATE 'create table SKU_ECOMMERCE (
CODPRO CHAR(5) NOT NULL,
SKUID INT,
PRODUCTID int,
REFID varchar2(50),
NAME varchar2(200),
PRICE decimal(18,2),
HEIGHT decimal(18,4),
LENGTH decimal(18,4), 
WIDTH decimal(18,4),
WEIGHTKG decimal(18,4),
CUBICWEIGHT decimal(18,4),
UNITMULTIPLIER decimal(18,4),
MEASUREMENTUNIT varchar(50),
MODALID int,
ISKIT int)';
EXECUTE IMMEDIATE 'ALTER TABLE SKU_ECOMMERCE ADD CONSTRAINT PK_SKU_ECOMMERCE PRIMARY KEY (CODPRO)';

END IF;

END;