Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add versioning, created updated times for notification templates schema #6171

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,9 @@ CREATE TABLE IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -2034,6 +2037,9 @@ CREATE TABLE IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -2058,6 +2064,9 @@ CREATE TABLE IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -1331,6 +1334,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -1346,6 +1352,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,9 @@ CREATE TABLE IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT DATETIME NOT NULL,
UPDATED_AT DATETIME NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -1477,6 +1480,9 @@ CREATE TABLE IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT DATETIME NOT NULL,
UPDATED_AT DATETIME NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -1493,6 +1499,9 @@ CREATE TABLE IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT DATETIME NOT NULL,
UPDATED_AT DATETIME NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -1494,6 +1497,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -1509,6 +1515,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -1362,6 +1365,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -1377,6 +1383,9 @@ CREATE TABLE IF NOT EXISTS IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,9 @@ CREATE TABLE IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -2093,6 +2096,9 @@ CREATE TABLE IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -2119,6 +2125,9 @@ CREATE TABLE IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,9 @@ CREATE TABLE IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -2026,6 +2029,9 @@ CREATE TABLE IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -2052,6 +2058,9 @@ CREATE TABLE IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,9 @@ CREATE TABLE IDN_NOTIFICATION_TYPE (
NAME VARCHAR(255) NOT NULL,
CHANNEL VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
Copy link
Contributor

@Thumimku Thumimku Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CREATED_AT TIMESTAMP NOT NULL,
CREATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UPDATED_AT TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

Some DB support have DEFAULT and ON_UPDATE support, we can use that if applicable?

Copy link
Contributor Author

@darshanasbg darshanasbg Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether these values needs to be managed from the db side or the application side is something we have to decide here..

I also thought to handle this from the db level as per ee52c3c

But bit further check on things, I choose maintaining these values at the application level due to following reasons:

  1. There as data format difference between databases.. But this is a minor reason, since the difference was only at the millisecond levels
  2. Different db impls have their own way of doing this, there is no constant one way to do across this in different db types and versions.. and when consider an example on how these going to be effected with the data replications with the things like DR or multi-regions is something we don't have in-depth expertise with the various database types we need to support...

So going down with the path of depending on db to maintain these records increase the complexity of the solution, reduce the maintainability product. So selected the handling at the application level data handling to make things simple.

If we are concerned about, each developer to having to handle this at each of their DAO impls, we can avoid such duplicated efforts by centralizing maintaining this logic in a place like jdbcTemplates.

Copy link
Member

@omindu omindu Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the approach suggested initially in this PR based on @darshanasbg's reasoning

How were we historically handling the created times? The above concerns should be there for those as well

UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
Expand All @@ -1595,6 +1598,9 @@ CREATE TABLE IDN_NOTIFICATION_ORG_TEMPLATE (
CONTENT_TYPE VARCHAR(50),
TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
Expand All @@ -1613,6 +1619,9 @@ CREATE TABLE IDN_NOTIFICATION_APP_TEMPLATE (
TYPE_ID INTEGER NOT NULL,
APP_ID VARCHAR(255) NOT NULL,
TENANT_ID INTEGER NOT NULL,
VERSION VARCHAR(15) NOT NULL,
CREATED_AT TIMESTAMP NOT NULL,
UPDATED_AT TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
Expand Down
Loading