Choose alternatives for CockroachDB for referenced computed columns (#12991)

This commit is contained in:
Alexander Schwartz 2022-07-13 20:31:21 +02:00 committed by GitHub
parent f2d71cd1c7
commit d4c97bd3a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 15 deletions

View file

@ -58,6 +58,12 @@ limitations under the License.
<ext:column jsonColumn="metadata" jsonProperty="fGrantedTimestamp"/> <ext:column jsonColumn="metadata" jsonProperty="fGrantedTimestamp"/>
</ext:createJsonIndex> </ext:createJsonIndex>
<addUniqueConstraint columnNames="realmid, resourceserverid, scopeid, resourceid, owner, requester" tableName="kc_authz_permission"/> <addUniqueConstraint columnNames="realmid, resourceserverid, scopeid, resourceid, owner, requester" tableName="kc_authz_permission"/>
</changeSet>
<!-- unimplemented on CockroachDB: computed column "XXX" cannot reference a foreign key
See: https://go.crdb.dev/issue-v/46672/v21.2 -->
<changeSet author="keycloak" id="authz-permission-2" dbms="postgresql">
<addForeignKeyConstraint constraintName="authz_permission_fk_root_fkey" <addForeignKeyConstraint constraintName="authz_permission_fk_root_fkey"
baseTableName="kc_authz_permission" baseTableName="kc_authz_permission"
baseColumnNames="resourceserverid" baseColumnNames="resourceserverid"
@ -67,4 +73,11 @@ limitations under the License.
</changeSet> </changeSet>
<changeSet author="keycloak" id="authz-permission-3" dbms="cockroachdb">
<!-- placeholder for foreign key on computed column to allow fast looking by resourceserverid -->
<createIndex tableName="kc_authz_permission" indexName="authz_permission_fk_root_fkey">
<column name="resourceserverid"/>
</createIndex>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View file

@ -52,12 +52,6 @@ limitations under the License.
<createIndex tableName="kc_authz_policy" indexName="authz_policy_type"> <createIndex tableName="kc_authz_policy" indexName="authz_policy_type">
<column name="type"/> <column name="type"/>
</createIndex> </createIndex>
<addForeignKeyConstraint constraintName="authz_policy_fk_root_fkey"
baseTableName="kc_authz_policy"
baseColumnNames="resourceserverid"
referencedTableName="kc_authz_resource_server"
referencedColumnNames="id"
onDelete="CASCADE"/>
<createTable tableName="kc_authz_policy_scope"> <createTable tableName="kc_authz_policy_scope">
<column name="policy_id" type="UUID"> <column name="policy_id" type="UUID">
@ -118,8 +112,6 @@ limitations under the License.
<column name="fk_root"/> <column name="fk_root"/>
<column name="name"/> <column name="name"/>
</createIndex> </createIndex>
<!-- this is deferrable and initiallyDeferred as hibernate will first insert new entries and then delete the old by default -->
<addUniqueConstraint tableName="kc_authz_policy_config" columnNames="fk_root, name" deferrable="true" initiallyDeferred="true" />
</changeSet> </changeSet>
<changeSet author="keycloak" id="authz-policy-2" dbms="postgresql"> <changeSet author="keycloak" id="authz-policy-2" dbms="postgresql">
@ -129,5 +121,25 @@ limitations under the License.
<addUniqueConstraint tableName="kc_authz_policy_scope" columnNames="policy_id, scope_id" deferrable="true" initiallyDeferred="true" /> <addUniqueConstraint tableName="kc_authz_policy_scope" columnNames="policy_id, scope_id" deferrable="true" initiallyDeferred="true" />
<addUniqueConstraint tableName="kc_authz_policy_resource" columnNames="policy_id, resource_id" deferrable="true" initiallyDeferred="true" /> <addUniqueConstraint tableName="kc_authz_policy_resource" columnNames="policy_id, resource_id" deferrable="true" initiallyDeferred="true" />
<addUniqueConstraint tableName="kc_authz_policy_associated_policy" columnNames="policy_id, associated_policy_id" deferrable="true" initiallyDeferred="true" /> <addUniqueConstraint tableName="kc_authz_policy_associated_policy" columnNames="policy_id, associated_policy_id" deferrable="true" initiallyDeferred="true" />
<!-- this is deferrable and initiallyDeferred as hibernate will first insert new entries and then delete the old by default -->
<addUniqueConstraint tableName="kc_authz_policy_config" columnNames="fk_root, name" deferrable="true" initiallyDeferred="true" />
<!-- unimplemented on CockroachDB: computed column "XXX" cannot reference a foreign key
See: https://go.crdb.dev/issue-v/46672/v21.2 -->
<addForeignKeyConstraint constraintName="authz_policy_fk_root_fkey"
baseTableName="kc_authz_policy"
baseColumnNames="resourceserverid"
referencedTableName="kc_authz_resource_server"
referencedColumnNames="id"
onDelete="CASCADE"/>
</changeSet> </changeSet>
<changeSet author="keycloak" id="authz-policy-3" dbms="cockroachdb">
<!-- placeholder for foreign key on computed column to allow fast looking by resourceserverid -->
<createIndex tableName="kc_authz_policy" indexName="authz_policy_fk_root_fkey">
<column name="resourceserverid"/>
</createIndex>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View file

@ -56,12 +56,6 @@ limitations under the License.
<column name="name"/> <column name="name"/>
</createIndex> </createIndex>
<addUniqueConstraint tableName="kc_authz_resource" columnNames="realmid, resourceserverid, name, owner"/> <addUniqueConstraint tableName="kc_authz_resource" columnNames="realmid, resourceserverid, name, owner"/>
<addForeignKeyConstraint constraintName="authz_resource_fk_root_fkey"
baseTableName="kc_authz_resource"
baseColumnNames="resourceserverid"
referencedTableName="kc_authz_resource_server"
referencedColumnNames="id"
onDelete="CASCADE"/>
<createTable tableName="kc_authz_resource_scope"> <createTable tableName="kc_authz_resource_scope">
<column name="resource_id" type="UUID"> <column name="resource_id" type="UUID">
@ -117,6 +111,22 @@ limitations under the License.
<!-- see https://go.crdb.dev/issue-v/31632/v21.2 for the current status of the implementation --> <!-- see https://go.crdb.dev/issue-v/31632/v21.2 for the current status of the implementation -->
<addUniqueConstraint tableName="kc_authz_resource_scope" columnNames="resource_id, scope_id" deferrable="true" initiallyDeferred="true" /> <addUniqueConstraint tableName="kc_authz_resource_scope" columnNames="resource_id, scope_id" deferrable="true" initiallyDeferred="true" />
<addUniqueConstraint tableName="kc_authz_resource_attribute" columnNames="fk_root, name, value" deferrable="true" initiallyDeferred="true" /> <addUniqueConstraint tableName="kc_authz_resource_attribute" columnNames="fk_root, name, value" deferrable="true" initiallyDeferred="true" />
<!-- unimplemented on CockroachDB: computed column "XXX" cannot reference a foreign key
See: https://go.crdb.dev/issue-v/46672/v21.2 -->
<addForeignKeyConstraint constraintName="authz_resource_fk_root_fkey"
baseTableName="kc_authz_resource"
baseColumnNames="resourceserverid"
referencedTableName="kc_authz_resource_server"
referencedColumnNames="id"
onDelete="CASCADE"/>
</changeSet> </changeSet>
<changeSet author="keycloak" id="authz-resource-3" dbms="cockroachdb">
<!-- placeholder for foreign key on computed column to allow fast looking by resourceserverid -->
<createIndex tableName="kc_authz_resource" indexName="authz_resource_fk_root_fkey">
<column name="resourceserverid"/>
</createIndex>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View file

@ -48,6 +48,11 @@ limitations under the License.
<column name="resourceserverid"/> <column name="resourceserverid"/>
<column name="name"/> <column name="name"/>
</createIndex> </createIndex>
</changeSet>
<!-- unimplemented on CockroachDB: computed column "XXX" cannot reference a foreign key
See: https://go.crdb.dev/issue-v/46672/v21.2 -->
<changeSet author="keycloak" id="authz-scope-2" dbms="postgresql">
<addForeignKeyConstraint constraintName="authz_scope_fk_root_fkey" <addForeignKeyConstraint constraintName="authz_scope_fk_root_fkey"
baseTableName="kc_authz_scope" baseTableName="kc_authz_scope"
baseColumnNames="resourceserverid" baseColumnNames="resourceserverid"
@ -57,4 +62,11 @@ limitations under the License.
</changeSet> </changeSet>
<changeSet author="keycloak" id="authz-scope-3" dbms="cockroachdb">
<!-- placeholder for foreign key on computed column to allow fast looking by resourceserverid -->
<createIndex tableName="kc_authz_scope" indexName="authz_scope_fk_root_fkey">
<column name="resourceserverid"/>
</createIndex>
</changeSet>
</databaseChangeLog> </databaseChangeLog>