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
Add local version field in snapshots #294
Changes from 1 commit
a0dacb4
4cec1b2
5fa19a7
fd8a2db
94cbef6
29d7de6
cfc154b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
|
||
when: | ||
def jsonText = javers.jsonConverter.toJson(snapshot) | ||
println jsonText | ||
|
||
then: | ||
def json = new JsonSlurper().parseText(jsonText) | ||
|
@@ -41,6 +40,7 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
json.globalId.entity == "org.javers.core.model.DummyUser" | ||
json.globalId.cdoId == "kaz" | ||
json.type == "INITIAL" | ||
json.version == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to test it in a different (minimal) way. |
||
} | ||
|
||
def "should serialize state with primitive values in CdoSnapshot"() { | ||
|
@@ -148,8 +148,8 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
state { | ||
} | ||
changedProperties changed | ||
version "1" | ||
} | ||
println json.toString() | ||
|
||
when: | ||
def snapshot = javersTestAssembly().jsonConverter.fromJson(json.toString(), CdoSnapshot) | ||
|
@@ -159,6 +159,7 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
snapshot.globalId == instanceId("kaz",DummyUser) | ||
snapshot.initial == true | ||
snapshot.changed.collect{it} as Set == ["name", "age"] as Set | ||
snapshot.version == 1L | ||
} | ||
|
||
def "should deserialize CdoSnapshot state with primitive values"() { | ||
|
@@ -181,6 +182,7 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
age 1 | ||
flag true | ||
} | ||
version "1" | ||
} | ||
|
||
when: | ||
|
@@ -216,6 +218,7 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
cdoId 1 | ||
} | ||
} | ||
version "1" | ||
} | ||
|
||
when: | ||
|
@@ -251,6 +254,7 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
} | ||
id 1 | ||
} | ||
version "1" | ||
} | ||
|
||
when: | ||
|
@@ -289,6 +293,7 @@ class CdoSnapshotTypeAdapterTest extends Specification { | |
dateTimes "2000-01-01T12:00:00", "2000-01-01T12:00:00" | ||
name "kaz" | ||
} | ||
version "1" | ||
} | ||
|
||
when: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ public class FixedSchemaFactory { | |
public static final String SNAPSHOT_COMMIT_FK = "commit_fk"; | ||
public static final String SNAPSHOT_GLOBAL_ID_FK = "global_id_fk"; | ||
public static final String SNAPSHOT_TYPE = "type"; | ||
public static final String VERSION = "version"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately, there is no db schema update in PolyJDBC (the tool we use to manage sql), So we need a new method which checks if column not exists and then runs DDL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I went this way but I'm a bit stuck on how to serialize the CdoSnapshotState including the new version field. Currently it is serialized as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, there is no elegant way to serialize version in CdoSnapshotState. Looks like we need to come back to your original solution and write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two possible solutions. We can write generic addColumnIfNotExists() method. Better place for this is PollyJDBC, but easier way is to write it in JaVers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will be a problem with the previously stored snapshots, because they would have to all be traversed and assigned versions in incrementing order..This might not be that easy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that one sub-select could be removed:
This query will be slow, but maybe good enough for migration script. So PR is now ready to merge? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it should be, I separated the test according what we discussed. As a note to the query from your last comment - I also tried it at first, but it gives an error in MySQL ("You can't specify target table 's' for update in FROM clause", as well as in PostgreSQL("ERROR: column "s" of relation "employees" does not exist") and I haven't tested it on the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, give us a few more days for merge and release There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @milanov there are few bugs here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see 12a8aff |
||
public static final String SNAPSHOT_TABLE_PK_SEQ = "jv_snapshot_pk_seq"; | ||
public static final String SNAPSHOT_STATE = "state"; | ||
public static final String SNAPSHOT_CHANGED = "changed_properties"; //since v.1.2 | ||
|
@@ -48,6 +49,7 @@ private Schema snapshotTableSchema(Dialect dialect, String tableName){ | |
RelationBuilder relationBuilder = schema.addRelation(tableName); | ||
primaryKey(tableName, SNAPSHOT_PK, schema, relationBuilder); | ||
relationBuilder.withAttribute().string(SNAPSHOT_TYPE).withMaxLength(200).and() | ||
.withAttribute().longAttr(VERSION).and() | ||
.withAttribute().text(SNAPSHOT_STATE).and() | ||
.withAttribute().text(SNAPSHOT_CHANGED).and(); | ||
foreignKey(tableName, SNAPSHOT_GLOBAL_ID_FK, GLOBAL_ID_TABLE_NAME, GLOBAL_ID_PK, relationBuilder, schema); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we dont want version to be null, so maybe primitive long?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll change that. Do you prefer for me to simply commit this change or to squash it with the previous (I didn't find contribution guidelines)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, we need to write contribution guidelines. Just push another commit but wait a while, i will take a deeper look at this PR at the evening