Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added note about not using DELIMITER

...

For the core, this is done in lams_common/db/insert_types_data.sql:

No Format

-- initialise db version
INSERT INTO patches VALUES ('lams', 13, NOW(), 'F');

For the tools, this is done by the tool deployer in tool/db/db_version_insert.sql:

No Format

INSERT INTO patches VALUES ('@signature@', '@tool_version@', NOW(), 'F');

...

For the core, database update scripts go in lams_common/src/java/org/lamsfoundation/lams/dbupdates. This is simply a file containing SQL statements, but it must be named according to its patch level:

Code Block

patch0013_updateFrom21.sql

...

Patches can also be written as java classes - they need to extend the MigrationTaskSupport class. Patch0011Alter21Integration.java This is an example of a patch implemented as a java class - it's a converted version of an actual patch used to update from 2.0.4 to 2.1.

Stored Procedures / Functions

Stored procedures cannot be included in a script with other items. Autopatch only handles the stored procedure if it is in a patch file all by itself. Do not include the usual autocommit and foriegn_key calls - that will cause the patch to fail. Have exactly one stored procedure and comments and nothing else. Examples of how stored procedures have been used are in lams_forum, patches 20150224.sql to 20150228.sql (see https://github.com/lamsfoundation/lams/commit/2ff38cdf504d51a2590b113023d885069d32645e#diff-3cff6d0dc09dc0cca85733428c2e6a08).

Do not use "DELIMITER $$" as that is notation for a SQL Client. Just put a ";" in the place of the delimiter. So "END$$" becomes "END;"

Problems with current patch levels

...

For the LAMS core, Autopatch is invoked as a servlet listener (in order to be called before any Spring beans that will cache from the database):

No Format
titleweb.xml

...

<context-param>
    <param-name>migration.systemname</param-name>
    <param-value>lams</param-value>
</context-param>
<context-param>
    <param-name>migration.databasetype</param-name>
    <param-value>mysql</param-value>
</context-param>
<context-param>
    <param-name>migration.patchpath</param-name>
    <param-value>org/lamsfoundation/lams/dbupdates</param-value>
</context-param>
<context-param>
    <param-name>migration.datasource</param-name>
    <param-value>java:jdbc/lams-ds</param-value>
</context-param>

...

<listener>
    <listener-class>com.tacitknowledge.util.migration.jdbc.WebAppJNDIMigrationLauncher</listener-class>
</listener>
<listener>
	<listener-class>
		org.springframework.web.context.ContextLoaderListener
	</listener-class>
</listener>

For the tools, Autopatch is invoked as a Spring bean on application startup:

No Format
titleweb.xml

...

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>
				...

				classpath:/org/lamsfoundation/lams/tool/chat/dbupdates/autopatchContext.xml

	                        ...
	</param-value>
</context-param>

...
No Format
titleautopatchContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<!-- Autopatch service -->
	<bean id="autopatchService" init-method="patch" class="com.tacitknowledge.util.migration.jdbc.AutoPatchService">
		<property name="systemName" value="lachat11"/>
		<property name="databaseType" value="mysql"/>
		<property name="patchPath" value="org/lamsfoundation/lams/tool/chat/dbupdates" />
		<property name="dataSource" ref="dataSource"/>
	</bean>
</beans>

...

No Format
build.xml
build.xml

	<target name="compile-java" depends="clean-build" description="compile java sources">
		<javac srcdir="${src.java.dir}" compiler="modern" destdir="${build.classes.java}" deprecation="on" debug="on">
			<compilerarg value="-Xlint:unchecked"/>
			<classpath>
				<path refid="project.classpath" />
			</classpath>
		</javac>
		<copy overwrite="yes" todir="${build.classes.java}/${package}">
			<fileset dir="${src.java.dir}/${package}">
				<include name="*.xml" />
				<include name="*.properties" />
				<!-- Autopatch -->
				<include name="dbupdates/*.sql" />
				<include name="dbupdates/autopatchContext.xml" />
			</fileset>
		</copy>
		<copy overwrite="yes" todir="${build.classes.java}/${package}/web">
			<fileset dir="${src.java.dir}/${package}/web">
				<include name="*.properties" />
			</fileset>
		</copy>
	</target>