Thanks. I didn't think of that. So now I am putting the migrations into my app.
1. I have worked out I need to change the Cayenne Model schema update strategy
in cayenne-project.xml from
schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
to
schema-update-strategy="org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy"
2. I added the generated Datamap0.java into my project.
3. I added a method in my AppModule of my Tapestry project to run at startup to
migrate to latest. Is this the correct way of getting domain?
@Startup
public static void initMigrateToLatest() {
try {
ServerRuntime sr = new ServerRuntime("cayenne-project.xml");
DataDomain domain = sr.getDataDomain();
new Migrator(domain.getDataNode("datanode"),
Datamap0.class.getPackage().getName()).migrateToLatest();
} catch (SQLException e) {
throw new RuntimeException("Unable to migrate database to current
version: " + e.getMessage(), e);
}
}
4. Now I am having a problem with auto_increment fields. For example I have a
table called tbl_company. If it is created using Cayenne's
CreateIfNoSchemaStrategy then it looks like this
mysql> describe tbl_company;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| date_cancel | datetime | YES | | NULL | |
| date_create | datetime | YES | | NULL | |
| id_company | int(11) | NO | PRI | NULL | auto_increment |
| str_company | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
If I create it using cayenne-migrations and Datamap0 it looks like this. (Note
no auto_increment on id).
mysql> describe tbl_company;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| date_cancel | datetime | YES | | NULL | |
| date_create | datetime | YES | | NULL | |
| id_company | int(11) | NO | PRI | NULL | |
| str_company | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
My Datamap0 for this table is
MigrationTableNew tbl_company = db.createTable("tbl_company");
tbl_company.addTimestampColumn("date_cancel", 19);
tbl_company.addTimestampColumn("date_create", 19);
tbl_company.addIntegerColumn("id_company", MANDATORY, null);
tbl_company.addVarcharColumn("str_company", 255);
tbl_company.addPrimaryKey("id_company");
My datamap.map.xml for this table is (Note the isGenerated="true")
<db-entity name="tbl_company">
<db-attribute name="date_cancel" type="TIMESTAMP" length="19"/>
<db-attribute name="date_create" type="TIMESTAMP" length="19"/>
<db-attribute name="id_company" type="INTEGER"
isPrimaryKey="true" isGenerated="true" isMandatory="true" length="10"/>
<db-attribute name="str_company" type="VARCHAR" length="255"/>
</db-entity>
So my question is, how do I get cayenne-migrations to create the auto_increment
in MySQL.
Thanks
Tim
On 25 Mar 2014, at 0:11, John Huss <[email protected]> wrote:
> I usually run MigrationGenerator from eclipse. You can just create a new
> "Java Application" launch configuration for the project and enter
> "org.apache.cayenne.migration.MigrationGenerator" as the main class. And
> then on the arguments tab enter your cayenne project filename and the
> output directory. For example "cayenne-MyDomain.xml ." (dot for the
> current directory).
>
signature.asc
Description: Message signed with OpenPGP using GPGMail
