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 APP_ROLE_ASSOCIATION and ROLE_SCOPE tables #4936

Merged
merged 11 commits into from
Oct 16, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ CREATE TABLE IDN_SCIM_GROUP (
ROLE_NAME VARCHAR(255) NOT NULL,
ATTR_NAME VARCHAR(1024) NOT NULL,
ATTR_VALUE VARCHAR(1024),
UNIQUE(TENANT_ID,ROLE_NAME,ATTR_NAME),
AUDIENCE_REF_ID INTEGER NOT NULL DEFAULT -1,
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME, AUDIENCE_REF_ID),
PRIMARY KEY (ID)) IN TS32K
/

Expand Down Expand Up @@ -1992,6 +1993,21 @@ CREATE TRIGGER SCOPE_TRIG NO CASCADE
END
/

CREATE TABLE APP_ROLE_ASSOCIATION (
APP_ID CHAR(36) NOT NULL,
ROLE_ID VARCHAR(255) NOT NULL,
PRIMARY KEY (APP_ID, ROLE_ID),
FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
)/

CREATE TABLE ROLE_SCOPE (
ROLE_ID VARCHAR(255) NOT NULL,
SCOPE_NAME VARCHAR(255) NOT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT ROLE_SCOPE_UNIQUE UNIQUE (ROLE_ID, SCOPE_NAME, TENANT_ID),
FOREIGN KEY (SCOPE_NAME, TENANT_ID) REFERENCES SCOPE(NAME, TENANT_ID) ON DELETE CASCADE
)/

-- --------------------------- INDEX CREATION -----------------------------
-- IDN_OAUTH2_ACCESS_TOKEN --
CREATE INDEX IDX_TC ON IDN_OAUTH2_ACCESS_TOKEN(TIME_CREATED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ CREATE TABLE IF NOT EXISTS IDN_SCIM_GROUP (
ROLE_NAME VARCHAR(255) NOT NULL,
ATTR_NAME VARCHAR(1024) NOT NULL,
ATTR_VALUE VARCHAR(1024),
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME),
AUDIENCE_REF_ID INTEGER DEFAULT -1 NOT NULL,
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME, AUDIENCE_REF_ID),
PRIMARY KEY (ID)
);

Expand Down Expand Up @@ -1330,6 +1331,21 @@ CREATE TABLE IF NOT EXISTS SCOPE (
CONSTRAINT SCOPE_UNIQUE UNIQUE (NAME, TENANT_ID)
);

CREATE TABLE IF NOT EXISTS APP_ROLE_ASSOCIATION (
APP_ID CHAR(36) NOT NULL,
ROLE_ID VARCHAR(255) NOT NULL,
PRIMARY KEY (APP_ID, ROLE_ID),
FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS ROLE_SCOPE (
ROLE_ID VARCHAR(255) NOT NULL,
SCOPE_NAME VARCHAR(255) NOT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT ROLE_SCOPE_UNIQUE UNIQUE (ROLE_ID, SCOPE_NAME, TENANT_ID),
FOREIGN KEY (SCOPE_NAME, TENANT_ID) REFERENCES SCOPE(NAME, TENANT_ID) ON DELETE CASCADE
);

-- --------------------------- INDEX CREATION -----------------------------
-- IDN_OAUTH2_ACCESS_TOKEN --
CREATE INDEX IDX_TC ON IDN_OAUTH2_ACCESS_TOKEN(TIME_CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ CREATE TABLE IDN_SCIM_GROUP (
ROLE_NAME VARCHAR(255) NOT NULL,
ATTR_NAME VARCHAR(1024) NOT NULL,
ATTR_VALUE VARCHAR(1024),
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME),
AUDIENCE_REF_ID INTEGER DEFAULT -1 NOT NULL,
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME, AUDIENCE_REF_ID),
PRIMARY KEY (ID)
);

Expand Down Expand Up @@ -1474,6 +1475,23 @@ CREATE TABLE SCOPE (
CONSTRAINT SCOPE_UNIQUE UNIQUE (NAME, TENANT_ID)
);

IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APP_ROLE_ASSOCIATION]') AND TYPE IN (N'U'))
CREATE TABLE APP_ROLE_ASSOCIATION (
APP_ID CHAR(36) NOT NULL,
ROLE_ID VARCHAR(255) NOT NULL,
PRIMARY KEY (APP_ID, ROLE_ID),
FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
);

IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[ROLE_SCOPE]') AND TYPE IN (N'U'))
CREATE TABLE ROLE_SCOPE (
ROLE_ID VARCHAR(255) NOT NULL,
SCOPE_NAME VARCHAR(255) NOT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT ROLE_SCOPE_UNIQUE UNIQUE (ROLE_ID, SCOPE_NAME, TENANT_ID),
FOREIGN KEY (SCOPE_NAME, TENANT_ID) REFERENCES SCOPE(NAME, TENANT_ID) ON DELETE CASCADE
);

-- --------------------------- INDEX CREATION -----------------------------
-- IDN_OAUTH2_ACCESS_TOKEN --
CREATE INDEX IDX_TC ON IDN_OAUTH2_ACCESS_TOKEN(TIME_CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ CREATE TABLE IF NOT EXISTS IDN_SCIM_GROUP (
ROLE_NAME VARCHAR(255) NOT NULL,
ATTR_NAME VARCHAR(1024) NOT NULL,
ATTR_VALUE VARCHAR(1024),
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME),
AUDIENCE_REF_ID INTEGER DEFAULT -1 NOT NULL,
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME, AUDIENCE_REF_ID),
PRIMARY KEY (ID)
)
ENGINE NDB;
Expand Down Expand Up @@ -1501,6 +1502,21 @@ CREATE TABLE IF NOT EXISTS SCOPE (
CONSTRAINT SCOPE_UNIQUE UNIQUE (NAME, TENANT_ID)
)ENGINE NDB;

CREATE TABLE IF NOT EXISTS APP_ROLE_ASSOCIATION (
APP_ID CHAR(36) NOT NULL,
ROLE_ID VARCHAR(255) NOT NULL,
PRIMARY KEY (APP_ID, ROLE_ID),
FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
)ENGINE NDB;

CREATE TABLE IF NOT EXISTS ROLE_SCOPE (
ROLE_ID VARCHAR(255) NOT NULL,
SCOPE_NAME VARCHAR(255) NOT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT ROLE_SCOPE_UNIQUE UNIQUE (ROLE_ID, SCOPE_NAME, TENANT_ID),
FOREIGN KEY (SCOPE_NAME, TENANT_ID) REFERENCES SCOPE(NAME, TENANT_ID) ON DELETE CASCADE
)ENGINE NDB;

-- --------------------------- INDEX CREATION -----------------------------
-- IDN_OAUTH2_ACCESS_TOKEN --
CREATE INDEX IDX_TC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ CREATE TABLE IF NOT EXISTS IDN_SCIM_GROUP (
ROLE_NAME VARCHAR(255) NOT NULL,
ATTR_NAME VARCHAR(1024) NOT NULL,
ATTR_VALUE VARCHAR(1024),
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME),
AUDIENCE_REF_ID INTEGER DEFAULT -1 NOT NULL,
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME, AUDIENCE_REF_ID),
PRIMARY KEY (ID)
)DEFAULT CHARACTER SET latin1 ENGINE INNODB;

Expand Down Expand Up @@ -1356,6 +1357,21 @@ CREATE TABLE IF NOT EXISTS SCOPE (
CONSTRAINT SCOPE_UNIQUE UNIQUE (NAME, TENANT_ID)
)ENGINE INNODB;

CREATE TABLE IF NOT EXISTS APP_ROLE_ASSOCIATION (
APP_ID CHAR(36) NOT NULL,
ROLE_ID VARCHAR(255) NOT NULL,
PRIMARY KEY (APP_ID, ROLE_ID),
FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
)DEFAULT CHARACTER SET latin1 ENGINE INNODB;

CREATE TABLE IF NOT EXISTS ROLE_SCOPE (
ROLE_ID VARCHAR(255) NOT NULL,
SCOPE_NAME VARCHAR(255) NOT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT ROLE_SCOPE_UNIQUE UNIQUE (ROLE_ID, SCOPE_NAME, TENANT_ID),
shashimalcse marked this conversation as resolved.
Show resolved Hide resolved
FOREIGN KEY (SCOPE_NAME, TENANT_ID) REFERENCES SCOPE(NAME, TENANT_ID) ON DELETE CASCADE
)DEFAULT CHARACTER SET latin1 ENGINE INNODB;

-- --------------------------- INDEX CREATION -----------------------------
-- IDN_OAUTH2_ACCESS_TOKEN --
CREATE INDEX IDX_TC ON IDN_OAUTH2_ACCESS_TOKEN(TIME_CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ CREATE TABLE IDN_SCIM_GROUP (
ROLE_NAME VARCHAR(255) NOT NULL,
ATTR_NAME VARCHAR(1024) NOT NULL,
ATTR_VALUE VARCHAR(1024),
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME),
AUDIENCE_REF_ID INTEGER DEFAULT -1 NOT NULL,
UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME, AUDIENCE_REF_ID),
PRIMARY KEY (ID)
);

Expand Down Expand Up @@ -1582,6 +1583,23 @@ CREATE TABLE SCOPE (
CONSTRAINT SCOPE_UNIQUE UNIQUE (NAME, TENANT_ID)
);

DROP TABLE IF EXISTS APP_ROLE_ASSOCIATION;
CREATE TABLE APP_ROLE (
APP_ID CHAR(36) NOT NULL,
ROLE_ID VARCHAR(255) NOT NULL,
PRIMARY KEY (APP_ID, ROLE_ID),
FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE
);

DROP TABLE IF EXISTS ROLE_SCOPE;
CREATE TABLE ROLE_SCOPE (
ROLE_ID VARCHAR(255) NOT NULL,
SCOPE_NAME VARCHAR(255) NOT NULL,
TENANT_ID INT NOT NULL,
CONSTRAINT ROLE_SCOPE_UNIQUE UNIQUE (ROLE_ID, SCOPE_NAME, TENANT_ID),
FOREIGN KEY (SCOPE_NAME, TENANT_ID) REFERENCES SCOPE(NAME, TENANT_ID) ON DELETE CASCADE
);

-- --------------------------- INDEX CREATION -----------------------------
-- IDN_OAUTH2_ACCESS_TOKEN --
CREATE INDEX IDX_TC ON IDN_OAUTH2_ACCESS_TOKEN(TIME_CREATED);
Expand Down