oracle ecommerce (atg) database best practices

25
ATG DB BEST PRACTICES BY KATE SEMIZHON

Upload: kate-semizhon

Post on 08-Aug-2015

97 views

Category:

Software


14 download

TRANSCRIPT

Page 1: Oracle eCommerce (ATG) Database  Best Practices

ATG DB BEST PRACTICES

BY KATE SEMIZHON

Page 2: Oracle eCommerce (ATG) Database  Best Practices

2

Page 3: Oracle eCommerce (ATG) Database  Best Practices

3

ATG

OO

TB

DB

SC

HEM

AS

Page 4: Oracle eCommerce (ATG) Database  Best Practices

TABLE TYPES

• ATG OOTB• New item-descriptors

Primary

• Extending OOTB tables

Auxiliary

• One-to-many• Many-to-many

Multi

Page 5: Oracle eCommerce (ATG) Database  Best Practices

AUXILIARY TABLES

1. In ATG, VARCHAR2 is almost always used as a data type for primary key column. Auxiliary tables should use the same data type length for referencing primary table.

2.  Auxiliary table MUST reference PRIMARY table but not any other auxiliary table.

Page 6: Oracle eCommerce (ATG) Database  Best Practices

AUXILIARY TABLESCREATE TABLE PRIMARY (

    ID VARCHAR2 (40) NOT NULL, 

    NAME VARCHAR2 (40) NOT NULL, 

    CONSTRAINT PRIMARY_PK PRIMARY KEY (ID)

);

CREATE TABLE AUX1(

    ID VARCHAR2 (40) NOT NULL, 

    SOME_PROP VARCHAR2 (400), 

    CONSTRAINT AUX1_PK PRIMARY KEY (ID), 

    CONSTRAINT AUX1_FK FOREIGN KEY (ID) REFERENCES PRIMARY (ID)

);

CREATE TABLE AUX2 (

    ID VARCHAR2 (40) NOT NULL, 

    SOME_PROP VARCHAR2 (40), 

    CONSTRAINT AUX2_PK PRIMARY KEY (ID), 

    CONSTRAINT AUX2_FK FOREIGN KEY (ID) REFERENCES PRIMARY(ID) -- THIS IS CORRECT!

 );

Page 7: Oracle eCommerce (ATG) Database  Best Practices

MULTI TABLES

Page 8: Oracle eCommerce (ATG) Database  Best Practices

Confidential 8

Primary table

Primary table

multi

Primary key

Page 9: Oracle eCommerce (ATG) Database  Best Practices

Confidential 9

Primary table

Primary table

multi Primary key

Page 10: Oracle eCommerce (ATG) Database  Best Practices

Confidential 10

Primary table

Primary table

multi Primary key

Page 11: Oracle eCommerce (ATG) Database  Best Practices

11

one-to-many from both sides

CREATE TABLE CONTENT(

    CONTENT_ID VARCHAR2 (40) NOT NULL, 

    DESCRIPTION VARCHAR2 (254) NULL , 

    CONSTRAINT CONTENT_IMAGES_PK PRIMARY KEY (CONTENT_ID)

);

CREATE TABLE IMAGES (

    IMAGE_ID VARCHAR2 (40) NOT NULL, 

    URL VARCHAR2 (254) NULL , 

    CONSTRAINT CONTENT_IMAGES_PK PRIMARY KEY (IMAGE_ID)

);

CREATE TABLE CONTENT_IMAGES (

    CONTENT_ID VARCHAR2 (40) NOT NULL REFERENCES CONTENT(CONTENT_ID), 

    IMAGE_ID VARCHAR2 (254) NOT NULL REFERENCES IMAGES(IMAGE_ID) , 

    CONSTRAINT CONTENT_IMAGES_PK PRIMARY KEY (CONTENT_ID , IMAGE_ID)

);

MANY-TO-MANY RELATIONSHIPS

Page 12: Oracle eCommerce (ATG) Database  Best Practices

VERSIONED SCHEMA

Page 13: Oracle eCommerce (ATG) Database  Best Practices

Confidential 13

PRIMARY TABLES

1) The following columns should be added to every table that represents a primary table for an item descriptor:

asset_version INTEGER NOT NULL

workspace_id varchar2(254) NULL

branch_id varchar2(254) NULL

is_head number(1) NULL

version_deleted varchar2(254) NULL

version_editable varchar2(254) NULL

pred_version INT NULL

checkin_date DATE NULL

Page 14: Oracle eCommerce (ATG) Database  Best Practices

PRIMARY TABLES

2) Primary key

Original Primary Key + ASSET_VERSION

3) Remove from all tables:

• All foreign key references.

• All unique constraints on columns.

• All unique indexes on columns.

Page 15: Oracle eCommerce (ATG) Database  Best Practices

PRIMARY TABLES

4) Indexes

all primary tables in the versioned schema have indexes on workspace_id and checkin_date

create index type_x_workspace_id on type_x (workspace_id);

create index type_x_checkin_date_id on type_x (checkin_date);

Page 16: Oracle eCommerce (ATG) Database  Best Practices

PRIMARY TABLES. EXAMPLEcreate table type_x (

       type_x_id          VARCHAR2(16)    NOT NULL,

       asset_version      INT            NOT NULL,

       branch_id          VARCHAR2(40)    NULL,

       is_head            NUMERIC(1)     NULL,

       version_deleted    NUMERIC(1)     NULL,

       version_editable   NUMERIC(1)     NULL,

       workspace_id       VARCHAR(40)    NULL,

       pred_version       INT            NULL,

       checkin_date       TIMESTAMP      NULL,

       name               VARCHAR2(128)   NULL,

       type_y_ref_id      VARCHAR2(16)    NULL,

       PRIMARY KEY (type_x_id, asset_version)

);

create index type_x_workspace_id on type_x (workspace_id);

create index type_x_checkin_date_id on type_x (checkin_date);

Page 17: Oracle eCommerce (ATG) Database  Best Practices

AUXILIARY TABLES

1) The following column should be added to every table that represents an auxiliary or multi table in an item descriptor:

asset_version   INT   NOT NULL

2) Primary key

Original Primary Key + ASSET_VERSION

Page 18: Oracle eCommerce (ATG) Database  Best Practices

AUXILIARY TABLES

3) Remove from all tables:

• All foreign key references.

• All unique constraints on columns.

• All unique indexes on columns

Page 19: Oracle eCommerce (ATG) Database  Best Practices

AUXILIARY TABLES. EXAMPLE

Original DDL:

CREATE TABLE dcs_cat_media (

    category_id varchar2(254) NOT NULL REFERENCES dcs_category(category_id),

    template_id varchar2(254) NULL REFERENCES dcs_media(media_id),

    PRIMARY KEY(category_id)

);

Versioned Schema DDL:

CREATE TABLE dcs_cat_media (

    category_id         varchar2(254)   NOT NULL,

    asset_version       INTEGER NOT NULL,

    template_id         varchar2(254)   NULL,

    PRIMARY KEY(category_id, asset_version)

);

Page 20: Oracle eCommerce (ATG) Database  Best Practices

MULTI TABLES1) The following column should be added to every table that

represents an auxiliary or multi table in an item descriptor:

asset_version   INT   NOT NULL

sec_asset_version   INT   NOT NULL

2) Primary key

Original Primary Key + asset_version + sec_asset_version

Page 21: Oracle eCommerce (ATG) Database  Best Practices

MULTI TABLES

3) Remove from all tables:

• All foreign key references.

• All unique constraints on columns.

• All unique indexes on columns

Page 22: Oracle eCommerce (ATG) Database  Best Practices

ONE-TO-MANY. EXAMPLE Original DDLCREATE TABLE dcs_cat_chldprd (

    category_id         varchar2(254)   NOT NULL REFERENCES dcs_category(category_id),

    sequence_num        INTEGER NOT NULL,

    child_prd_id        varchar2(254)   NULL REFERENCES dcs_product(product_id),

    PRIMARY KEY(category_id, sequence_num)

);

Versioned DDLCREATE TABLE dcs_cat_chldprd (

    category_id         varchar2(254)   NOT NULL,

    asset_version       INTEGER NOT NULL,

    sequence_num        INTEGER NOT NULL,

    child_prd_id        varchar2(254)   NULL,

    sec_asset_version   INTEGER NOT NULL,

    PRIMARY KEY(category_id, sequence_num, asset_version, sec_asset_version)

);

Page 23: Oracle eCommerce (ATG) Database  Best Practices

MANY-TO-MANY. EXAMPLEOriginal DDL

CREATE TABLE dcs_catfol_chld (

    catalog_id      varchar2(254)   NOT NULL REFERENCES dcs_catalog(catalog_id),

    catfol_id       varchar2(254)   NOT NULL REFERENCES dcs_gen_fol_cat(folder_id),

    sequence_num        INTEGER NOT NULL,

    PRIMARY KEY(catalog_id, catfol_id, sequence_num)

);

Versioned DDL

CREATE TABLE dcs_catfol_chld (

    catalog_id      varchar2(254)   NOT NULL,

    sec_asset_version   INTEGER NOT NULL,

    catfol_id       varchar2(254)   NOT NULL,

    sequence_num        INTEGER NOT NULL,

    asset_version       INTEGER NOT NULL,

    PRIMARY KEY(catalog_id, catfol_id, sequence_num, asset_version, sec_asset_version)

);

Page 24: Oracle eCommerce (ATG) Database  Best Practices

THANK YOU!

QUESTIONS?