[TRUNK-3884] My code patch has runtime error. Help!

0 views
Skip to first unread message

Susan Tan

unread,
Jun 15, 2013, 12:00:11 PM6/15/13
to d...@openmrs.org
https://gist.github.com/onceuponatimeforever/5788549 

I included this above code patch at end of liquibase-update-to-latest.xml on my local and remote branch.
See above gist and pull request. Removing the code patch removes the error. Are there any syntax errors?  I'm confused why I'm getting this error when I run mvn jetty:run to start the webapp. Code compiles successfully.

Also in the ticket, I'm not sure why a change to the liquibase-schema-only.xml file is needed, since the change will already be in liquibase-update-to-latest.xml.

Ben Wolfe

unread,
Jun 15, 2013, 8:31:42 PM6/15/13
to Developers

I commented on your commit in github: you have an extra double quote hanging out at the end of the line.

As far as the schema file, I agree with you. The schema only file should be auto generated when someone decides to update all those files in the releases.

--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org
Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/
 
 

Susan Tan

unread,
Jun 16, 2013, 3:10:43 AM6/16/13
to d...@openmrs.org
Thanks for the syntax correction, Ben. I corrected and pushed the new syntax change, so the new code change is on the same pull request (here: https://github.com/openmrs/openmrs-core/pull/343/files).  However, there are additional errors when I run the application and after I login: 

  • ??? Caused By: Error executing SQL ALTER TABLE `encounter_provider` ADD CONSTRAINT `creator_fk` FOREIGN KEY (`creator`) REFERENCES `users` (`user_id`): Can't write; duplicate key in table '#sql-a4a_fb':???
  • ??? Caused By: Can't write; duplicate key in table '#sql-a4a_fb'???
  • ??? Reason: liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE `encounter_provider` ADD CONSTRAINT `creator_fk` FOREIGN KEY (`creator`) REFERENCES `users` (`user_id`): Can't write; duplicate key in table '#sql-a4a_fb':???
  • Unable to update the database. See server error logs for the full stacktrace.
Not sure how to fix this. Is the new changeSet logic in the pull request incorrect? 

Daniel Kayiwa

unread,
Jun 16, 2013, 3:19:20 AM6/16/13
to dev
Ben,

Do you mind giving some more clarification about your comment concerning the liquibase-schema-only.xml? (Just to make sure i get this right and never mislead any one else again. :)

I have all along thought that whenever we make schema changes to liquibase-update-to-latest.xml, we do also change the
liquibase-schema-only.xml
For instance, if we create a changeset in liquibase-update-to-latest.xml that adds a new column to an existing person table, we also add this column to the create table changeset in the liquibase-schema-only.xml file.

Here is an example:

liquibase-update-to-latest.xml

<changeSet id="20090402-1515-38-cohort" author="bwolfe" dbms="mysql">
        <preConditions onFail="MARK_RAN"><not><columnExists tableName="cohort" columnName="uuid"/></not></preConditions>
        <comment>Adding "uuid" column to cohort table</comment>
        <addColumn tableName="cohort">
            <column name="uuid" type="char(38)" />
        </addColumn>
    </changeSet>



liquibase-schema-only.xml:

<createTable tableName="cohort">
    ......
    <column name="uuid" type="char(38)" />
</createTable>


--
If we keep uppermost in our minds the unkind and unjust acts of others, we shall find it impossible to love them as Christ has loved us; but if our thoughts dwell upon the wondrous love and pity of Christ for us, the same spirit will flow out to others.

Daniel Kayiwa

unread,
Jun 16, 2013, 3:26:57 AM6/16/13
to dev
That is because your foreign key constraint names are already in use: e.g constraintName="creator_fk" is in use.

You can change those names to something else. For instance you could instead use something like: constraintName="fk_creator_encounter_provider", constraintName="fk_changed_by_encounter_provider", constraintName="fk_voided_by_encounter_provider"


--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org
Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/
 
 

Susan Tan

unread,
Jun 16, 2013, 3:48:46 AM6/16/13
to d...@openmrs.org
TRUNK-3884 ticket is resolved and tested successfully. See PR here: https://github.com/openmrs/openmrs-core/pull/343/files 
Feel free to merge to upstream master whenever you're ready. Thanks Daniel and Ben for helping me fix this ticket. I learned quite a lot about liquibase in the process.

Daniel--I can answer why it's technically possible to put the changeSet logic in update-to-latest and not in schema-only. 

In the update-to-latest.xml, in line 5899,  the encounter_provider table is created with the following changeSet logic:

<createTable tableName="encounter_provider">
            <column name="encounter_provider_id" type="int" autoIncrement="true">
                 <constraints primaryKey="true" nullable="false" />
            </column>
             <column name="encounter_id" type="int"><constraints nullable="false" /></column>
             ...... 
</createTable>

rather than the ChangeSet logic of 

<addColumn tableName="encounter_provider">
            <column name="encounter_id" type="int" />
</addColumn>




Daniel Kayiwa

unread,
Jun 16, 2013, 3:51:55 AM6/16/13
to dev
Susan, that's because the table did not exist. So it could not just add a column to a non existing table. :)


--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org
Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/
 
 

Susan Tan

unread,
Jun 16, 2013, 4:03:31 AM6/16/13
to d...@openmrs.org
The intention of the schema-only.xml is to create tables, while update-to-latest.xml makes modifications on those existing tables that are created in schema-only.xml. Is that correct? 

Ben Wolfe

unread,
Jun 16, 2013, 11:10:11 AM6/16/13
to Developers

Right, so at initial install time the files run are:
Schema-only
Core data
Demo data (optional)
Update to latest

So everyone will get the changes regardless of whether they are just upgrading bit by bit or installing fresh.

There is a liquibase build file that builds a temp inmemory database this way then exports liquibase xml for committing/pushing as the new schema-only file. We usually run this every other release so that new installations are a little faster.

Ben

On Jun 16, 2013 4:03 AM, "Susan Tan" <onceuponat...@gmail.com> wrote:
The intention of the schema-only.xml is to create tables, while update-to-latest.xml makes modifications on those existing tables that are created in schema-only.xml. Is that correct? 

--
Reply all
Reply to author
Forward
0 new messages