4. TABLE TYPES
• ATG OOTB
• New item-descriptors
Primary
• Extending OOTB tables
Auxiliary
• One-to-many
• Many-to-many
Multi
5. 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.
6. AUXILIARY TABLES
CREATE 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!
);
13. PRIMARY TABLES
1) The following columns should be added to every table
that represents a primary table for an item descriptor:
Confidential
13
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
14. 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.
15. 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);
16. PRIMARY TABLES.
EXAMPLE
create 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);
17. 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
18. AUXILIARY TABLES
3) Remove from all tables:
• All foreign key references.
• All unique constraints on columns.
• All unique indexes on columns
19. 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)
);
20. MULTI 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
sec_asset_version INT NOT NULL
2) Primary key
Original Primary Key + asset_version +
sec_asset_version
21. MULTI TABLES
3) Remove from all tables:
• All foreign key references.
• All unique constraints on columns.
• All unique indexes on columns
22. ONE-TO-MANY.
EXAMPLE
Original DDL
CREATE 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 DDL
CREATE 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)
);
23. MANY-TO-MANY.
EXAMPLE
Original 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)
);
We review DB changes often
This presentation is only about ATG(!) DB best practice
Configuring a Repository connection to a SQL database or an LDAP directory requires no Java coding at all.
This course will focus specifically on the most common type of repository: a SQL repository. But the principles covered apply to repositories that connect to LDAP and other data sources as well. Note that ATG supplies support for SQL and LDAP. You can add custom support for other data sources.
The relationship between ATG repository components and databases is not necessarily one-to-one. Administrators can choose to model several repositories from one schema of one database (which is what Dynamusic is doing -- the Songs, Events, and Profile repositories are all accessing the same schema in Solid). Alternatively, a single repository item can be made up of data from multiple databases using a composite repository. In fact, these databases don't even need to be the same type -- one could be SQL, and one LDAP. ATG's repository layer does all the necessary assembling and splitting of queries and commands to the various data sources. For more on composite repositories, see the “Composite Repositories” chapter of the Repository Guide.
Column Name Description
asset_version Counter that specifies the version of the asset.
branch_id ID used to persist the branch of a version.
is_head Flag that determines whether a version is the head of a branch.
checkin_date Stores the check-in date of a version. Null for working versions of assets.
version_deleted Flag that indicates whether the asset version is a deleted version.
version_editable Flag that indicates whether the asset version is an editable version. That is, the version is a working version in a workspace, where modifications to it can be made.
pred_version The asset version upon which this version was based. For example, if you create version 2 by checking out version 1, version 2’s predecessor version is version 1.
workspace_id The ID of the workspace where the asset version was initially created.