In the project, if we use activiti workflow engine, it must be supported by the database, if one day we intend to upgrade the Activiti workflow engine, then the corresponding database table or view also need to upgrade, because there may be table structure adjustment, Example: Activiti 5.14 when There is no tenant_id_ fieldin the Act_re_deployment table,a Ctiviti 5.19 has this field, then we upgrade, we must upgrade the database, the following detailed explanation of how to upgrade the database.
1.1.1.
first way of manual sql
We first open our download of aCtiviti project, the directory structure is as follows:
Open the database directory, as shown in the structure:
Catalogue Description:
CREATE DATABASE, table view, index creation script.
Drop Database, table view, index Delete script. ( removal of the engine is best this way to remove the relatively clean )
Upgrade The database, table view, index upgrade script.
SQL naming conventions in the directory:
Activiti.db2.create.history.sql
Activiti:activiti The work flow is marked.
db2 name of the database manufacturer ( can be mysql , h2 , oracle postgres etc For example, I'm using postgres database, then select the beginning.
Create: The meaning of creating a database, the corresponding must have drop,upgradestep Identifier, the operation of the time to select the corresponding can.
The last identifier of the history , because SQL created the table when the time is divided into three large SQL scripts.
The 1.engine Core creates table statements, mainly ru* tables, and so on.
2.history a hi* table that primarily creates workflows .
3.identity the user tables,id* , and user information tables that are primarily created for the workflow ( You can not use this when you extend the table, and the following permission building chapters will explain in detail )
The above is an introduction to the table of contents, the next step into the upgrade directory, as shown in the upgrade tables in the partial SQL script:
When upgrading the database, for example, when the 53TO.43.XX.SQLL upgrade is the current version of activiti, Indicate which version you want to upgrade to. Select the SQL corresponding version of the database table that you want to upgrade .
Activiti corresponding version information is as follows:
1.1.2.
Second mode of configuration
is primarily to configure some of the property information that is customized by the activiti workflow engine.
<bean id= "Processengineconfiguration" class= " Org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration ">property name=" databaseschemaupdate "value = "Drop-create" ></property></bean><bean id= "Processengine" class= " Org.activiti.spring.ProcessEngineFactoryBean "><property name=" processengineconfiguration "ref=" Processengineconfiguration "/></bean>
here is a description of the main workflow objects we use are processengine, to get each xxxservice from this object ,processengine is required processengineconfiguration The attributes in the object, it's like you're looking for a job, you always have to raise your property, change your clothes, shave your beard, and so on.
Let's take a look at the source code in Processengineimpl next. The main view is the database creation, deletion, update operation how the bottom is implemented.
The Processengineimpl inheritance relationship is as follows:
The Processengineimpl class is constructed as follows:
Public Processengineimpl (Processengineconfigurationimpl processengineconfiguration) {... commandexecutor.execute ( Processengineconfiguration.getschemacommandconfig (), New Schemaoperationsprocessenginebuild ()); ...}
Let's take a look at Commandexecutor.execute (Processengineconfiguration.getschemacommandconfig (), New Schemaoperationsprocessenginebuild ()); method, which is to create, update, and delete the database tables. To see how this method obtains the configuration file and then operates the database, we not only need to know how to configure it, but more importantly to know how the configuration is parsed in Activiti.
This is a typical command pattern, here we take a look at how this schemaoperationsprocessenginebuild command is used, about Activiti command mode we will explain in detail in the following article
Public final class Schemaoperationsprocessenginebuild implements command<object> {public Object execute ( Commandcontext commandcontext) { commandcontext . GetSession (Dbsqlsession.class) . Performschemaoperationsprocessenginebuild (); return null;} }
Let's take a look at the actions in the Performschemaoperationsprocessenginebuild method:
Open the class org. Activiti. engine. Impl. db. The Performschemaoperationsprocessenginebuild method in Dbsqlsession is as follows:
public static final String db_schema_update_create = "CREATE";p ublic static final String db_schema_update_drop_create = " Drop-create ";p ublic void Performschemaoperationsprocessenginebuild () {//This method is to get the <bean id= above" Processengineconfiguration "class=" Org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration "> Property name= configuration information in "Databaseschemaupdate" value= "Drop-create" ></property></bean> is not configured by default is falsestring databaseschemaupdate = Context.getprocessengineconfiguration (). Getdatabaseschemaupdate ();// Drop-create Delete Table re-create if (ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals (databaseschemaupdate)) {try {//delete operation Dbschemadrop (); } catch (RuntimeException e) {///Ignore}}//is configured with any of the Create-drop drop-create create three if (Org.activiti. Engine. ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP.equals (databaseschemaupdate) | | ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals (DatabaseSChemaupdate) | | ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_CREATE.equals (databaseschemaupdate)) {//Create operation Dbschemacreate (); } else if (Org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE.equals (databaseschemaupdate)) { Check version dbschemacheckversion (); } else if (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE.equals (databaseschemaupdate)) {//Set TRUE to update operation Dbschemaupdate (); } }
At this point we have been very clear about the meaning of the parameter configuration and the processing of the engine after configuration parameters. about how to open the database Operations table in the Activiti workflow engine, how to update the table, because this place is responsible for design mybstis content, this is also explained in the following chapters, and then extrapolate the principle to say.
Finally, we summarize the pros and cons of both approaches:
1. The first approach is best,SQL runs directly, and operates at the database level faster.
2. The second way, which needs to be configured, is to operate at the program level, and must also open the database connection operation, which compares consumption performance if opening a database connection. If you extend the table of the activti Workflow yourself, it can cause unnecessary trouble.
3. Personal recommendation to use the first way to run SQL directly to upgrade.
Activiti Database Upgrade Upgrade