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

[KEYCLOAK-7985] fix the table name error, from RESOURCE_URI to RESOURCE_URIS #5433

Merged
merged 1 commit into from Aug 2, 2018

Conversation

miricy
Copy link
Contributor

@miricy miricy commented Aug 2, 2018

Signed-off-by: alva.huang alva@izhiju.cn

Database table names do not match

The file :
"./model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/AuthzResourceUseMoreURIs.java "
database table names do not match with
file:“./model/jpa/src/main/resources/META-INF/jpa-changelog-authz-4.2.0.Final.xml"

Table name ‘RESOURCE_URI’ not match ‘RESOURCE_URIS’

./model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/custom/AuthzResourceUseMoreURIs.java:

public class AuthzResourceUseMoreURIs extends CustomKeycloakTask {
    @Override
    protected void generateStatementsImpl() throws CustomChangeException {
        try {
            PreparedStatement statement = jdbcConnection.prepareStatement("select ID,URI from " + getTableName("RESOURCE_SERVER_RESOURCE"));

            try {
                ResultSet resultSet = statement.executeQuery();
                try {
                    while (resultSet.next()) {
                        String resourceId = resultSet.getString(1);
                        String resourceUri = resultSet.getString(2);

                        InsertStatement insertComponent = new InsertStatement(null, null, database.correctObjectName("RESOURCE_URI", Table.class))
                                .addColumnValue("RESOURCE_ID", resourceId)
                                .addColumnValue("VALUE", resourceUri);

                        statements.add(insertComponent);
                    }
                } finally {
                    resultSet.close();
                }
            } finally {
                statement.close();
            }

            confirmationMessage.append("Moved " + statements.size() + " records from RESOURCE_SERVER_RESOURCE to RESOURCE_URI table");
        } catch (Exception e) {
            throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
        }
    }

    @Override
    protected String getTaskId() {
        return "Update 4.2.0.Final";
    }
}

./model/jpa/src/main/resources/META-INF/jpa-changelog-authz-4.2.0.Final.xml :


<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">
    <changeSet author="mhajas@redhat.com" id="authz-4.2.0.Final">
        <createTable tableName="RESOURCE_URIS">
            <column name="RESOURCE_ID" type="VARCHAR(36)">
                <constraints nullable="false"/>
            </column>
            <column name="VALUE" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
        </createTable>

        <addForeignKeyConstraint baseColumnNames="RESOURCE_ID" baseTableName="RESOURCE_URIS" constraintName="FK_RESOURCE_SERVER_URIS" referencedColumnNames="ID" referencedTableName="RESOURCE_SERVER_RESOURCE"/>

        <customChange class="org.keycloak.connections.jpa.updater.liquibase.custom.AuthzResourceUseMoreURIs"/>

        <dropColumn columnName="URI" tableName="RESOURCE_SERVER_RESOURCE"/>
    </changeSet>
</databaseChangeLog>

@pedroigor pedroigor requested a review from mhajas August 2, 2018 03:54
@hmlnarik
Copy link
Contributor

hmlnarik commented Aug 2, 2018

@miricy Thank you for the PR! Could you please file a JIRA and include the JIRA number in commit message?

@miricy miricy changed the title fix the table name error, from RESOURCE_URI to RESOURCE_URIS [KEYCLOAK-7985] fix the table name error, from RESOURCE_URI to RESOURCE_URIS Aug 2, 2018
@miricy
Copy link
Contributor Author

miricy commented Aug 2, 2018

@hmlnarik Ok, I have already submitted。

@hmlnarik
Copy link
Contributor

hmlnarik commented Aug 2, 2018

@miricy Please update the commit message (by overriding via git commit --amend), not just the PR title. PR title is not visible in the final git log, only commit message is.

…CE_URIS

Signed-off-by: alva.huang <alva@izhiju.cn>
Copy link
Contributor

@mhajas mhajas left a comment

Choose a reason for hiding this comment

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

@miricy Thank you for PR and for creating JIRA. I have no idea how it is possible our tests didn't catch this one but your fix looks good and tests are passing. Also it looks like there is no other occurrence of "RESOURCE_URI" in whole project so I believe this should be enough.

@mildis
Copy link
Contributor

mildis commented Aug 2, 2018

👍 for what its worth

@miricy
Copy link
Contributor Author

miricy commented Aug 2, 2018

@hmlnarik @mildis @mhajas Thank you for your guidance, I'm very happy to do some small things for the project.

@pedroigor pedroigor merged commit 3380fdc into keycloak:master Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants