Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit 9c722a2

Browse files
authored
Merge pull request #7 from builtamont-oss/fix/migration_info_class_cast_exception
Fix - Migration info class cast exception
2 parents 8a74bac + a5826b6 commit 9c722a2

File tree

7 files changed

+118
-30
lines changed

7 files changed

+118
-30
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!-- NOTE: Uncomment the template you wish to use -->
2+
3+
<!-- -------------------------------------------------------------- -->
4+
<!-- FEATURE / ENHANCEMENT TEMPLATE -->
5+
<!-- -------------------------------------------------------------- -->
6+
<!--
7+
## Outcome Desired
8+
9+
*<Write what outcome would be achieved through the completion of this story.>*
10+
11+
<hr>
12+
13+
## Definition of Done
14+
15+
*<Write some conditions that marks this feature as done.>*
16+
17+
<hr>
18+
19+
## Out of Scope
20+
21+
*<Write the items / activities that are out of scope for this feature (which may be included in future features).>*
22+
23+
<hr>
24+
25+
## How to Demo
26+
27+
*<Describe, in steps, how to demo the completed feature.>*
28+
-->
29+
30+
<!-- -------------------------------------------------------------- -->
31+
<!-- ISSUE TEMPLATE -->
32+
<!-- -------------------------------------------------------------- -->
33+
<!--
34+
## Expected Behaviour
35+
36+
*<Describe the expected behaviour.>*
37+
38+
<hr>
39+
40+
## Actual Behaviour
41+
42+
*<Describe what actually happens. Include relevant information where possible (e.g. error logs).>*
43+
44+
<hr>
45+
46+
## Steps to Reproduce
47+
48+
*<Describe, in steps, how to reproduce the problem.>*
49+
-->
50+
51+
<!-- -------------------------------------------------------------- -->
52+
<!-- CHORE TEMPLATE -->
53+
<!-- -------------------------------------------------------------- -->
54+
<!--
55+
## Context
56+
57+
*<Write some contextual information about the chore.>*
58+
59+
<hr>
60+
61+
## Definition of Done
62+
63+
*<Write some conditions that marks this chore as done.>*
64+
-->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Summary
2+
3+
<!-- NOTE: Remove as necessary -->
4+
Completes feature #*<GitHub issue number>*
5+
Completes chore #*<GitHub issue number>*
6+
Fixes issue #*<GitHub issue number>*
7+
8+
Related tickets: #*<GitHub issue number>*
9+
10+
*<Write a short summary of your changes.>*
11+
12+
<hr>
13+
14+
## Pull Request (PR) Checklist
15+
16+
### Documentation
17+
- [ ] Documentation in `README.md` or Wiki updated
18+
19+
### Code Review
20+
- [ ] Self code review -- take another pass through the changes yourself
21+
- [ ] Completed all relevant `TODO`s, or call them out in the PR comments
22+
23+
### Tests
24+
- [ ] All tests passes

scripts/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# limitations under the License.
1919
###
2020

21-
mvn deploy --settings settings.xml -DskipTests=true -B
21+
mvn source:jar javadoc:jar deploy --settings settings.xml -DskipTests=true -B

src/main/java/com/builtamont/cassandra/migration/CassandraMigration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CassandraMigration : CassandraMigrationConfiguration {
5959
/**
6060
* The Cassandra migration configuration.
6161
*/
62-
val configs: MigrationConfigs
62+
lateinit var configs: MigrationConfigs
6363

6464
/**
6565
* CassandraMigration initialization.

src/main/java/com/builtamont/cassandra/migration/internal/command/Migrate.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ class Migrate(
7272

7373
// Initialise `firstRun` and `currentSchemaVersion` variables
7474
val firstRun = migrationSuccessCount == 0
75-
var currentSchemaVersion = MigrationVersion.EMPTY
76-
if (infoService.current() != null) {
77-
currentSchemaVersion = infoService.current()!!.version
78-
}
75+
val currentSchemaVersion = infoService.current()?.version ?: MigrationVersion.CURRENT
7976

8077
// First run only
8178
// ~~~~~
@@ -93,7 +90,7 @@ class Migrate(
9390
// Log future migrations and warn users if there are no resolved migrations, or
9491
// if there current version migration is newer than what is available
9592
val future = infoService.future()
96-
if (future.size > 0) {
93+
if (future.isNotEmpty()) {
9794
val resolvedLogMsg = "Keyspace $keyspaceName has version $currentSchemaVersion"
9895
val resolved = infoService.resolved()
9996
if (resolved.size == 0) {
@@ -108,7 +105,7 @@ class Migrate(
108105
// ~~~~~
109106
// Log failed future migrations and throw `CassandraMigrationException` for everything else
110107
val failed = infoService.failed()
111-
if (failed.size > 0) {
108+
if (failed.isNotEmpty()) {
112109
val isFutureFailed = failed[0].state === MigrationState.FUTURE_FAILED
113110
val failedVersion = failed[0].version
114111
if (failed.size == 1 && isFutureFailed) {
@@ -122,14 +119,17 @@ class Migrate(
122119

123120
// Pending migrations
124121
// ~~~~~
125-
// Early return if there are no pending migrations, otherwise
126-
// apply pending migrations and exit when error is thrown
127-
val pendingMigrations = infoService.pending() as Array<MigrationInfoImpl>
128-
if (pendingMigrations.size == 0) {
122+
// Apply pending migrations
123+
val pendingMigrations = infoService.pending()
124+
if (pendingMigrations.isNotEmpty()) {
125+
if (pendingMigrations[0] is MigrationInfoImpl) {
126+
val isOutOfOrder = pendingMigrations[0].version.compareTo(currentSchemaVersion) < 0
127+
applyMigration(pendingMigrations[0] as MigrationInfoImpl, isOutOfOrder) ?: break
128+
}
129+
} else {
130+
// Exit if there are no more pending migrations
129131
break
130132
}
131-
val isOutOfOrder = pendingMigrations[0].version.compareTo(currentSchemaVersion) < 0
132-
applyMigration(pendingMigrations[0], isOutOfOrder) ?: break
133133

134134
migrationSuccessCount++
135135
}
@@ -184,9 +184,9 @@ class Migrate(
184184
stopWatch.start()
185185

186186
var isMigrationSuccess = false
187-
val migrationExecutor = migration.resolvedMigration?.executor
188187
try {
189-
migrationExecutor!!.execute(session)
188+
val executor = migration.resolvedMigration!!.executor!!
189+
executor.execute(session)
190190
isMigrationSuccess = true
191191
LOG.debug("$logMsg success!")
192192
} catch (e: Exception) {

src/main/java/com/builtamont/cassandra/migration/internal/info/MigrationInfoImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import java.util.*
3434
* @param context The current context.
3535
*/
3636
class MigrationInfoImpl(
37-
val resolvedMigration: ResolvedMigration?,
38-
val appliedMigration: AppliedMigration?,
39-
private val context: MigrationInfoContext
37+
val resolvedMigration: ResolvedMigration?,
38+
val appliedMigration: AppliedMigration?,
39+
private val context: MigrationInfoContext
4040
) : MigrationInfo {
4141

4242
/**

src/main/java/com/builtamont/cassandra/migration/internal/info/MigrationInfoServiceImpl.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class MigrationInfoServiceImpl(
4848
/**
4949
* The migrations infos calculated at the last refresh.
5050
*/
51-
private var migrationInfos: List<MigrationInfoImpl>? = null
51+
private var migrationInfos: List<MigrationInfoImpl> = emptyList()
5252

5353
/**
5454
* Refreshes the info about all known migrations from both the classpath and the DB.
@@ -60,7 +60,7 @@ class MigrationInfoServiceImpl(
6060
migrationInfos = mergeAvailableAndAppliedMigrations(availableMigrations, appliedMigrations)
6161

6262
if (MigrationVersion.CURRENT === target) {
63-
target = current()!!.version
63+
target = current()?.version
6464
}
6565
}
6666

@@ -70,7 +70,7 @@ class MigrationInfoServiceImpl(
7070
* @return The error message, or `null` if everything is fine.
7171
*/
7272
override fun validate(): String? {
73-
migrationInfos?.forEach { it.validate()?.let { return it } }
73+
migrationInfos.forEach { it.validate()?.let { return it } }
7474
return null
7575
}
7676

@@ -80,14 +80,14 @@ class MigrationInfoServiceImpl(
8080
* @return The migrations.
8181
*/
8282
override fun all(): Array<MigrationInfo> {
83-
return migrationInfos?.toTypedArray<MigrationInfo>() ?: emptyArray()
83+
return migrationInfos.toTypedArray()
8484
}
8585

8686
/**
8787
* @return Current migration to be run.
8888
*/
8989
override fun current(): MigrationInfo? {
90-
return migrationInfos?.lastOrNull { it.state.isApplied }
90+
return migrationInfos.lastOrNull { it.state.isApplied }
9191
}
9292

9393
/**
@@ -96,7 +96,7 @@ class MigrationInfoServiceImpl(
9696
* @return The pending migrations. An empty array if none.
9797
*/
9898
override fun pending(): Array<MigrationInfo> {
99-
return migrationInfos?.filter { it.state === MigrationState.PENDING }.orEmpty<MigrationInfo>().toTypedArray()
99+
return migrationInfos.filter { it.state === MigrationState.PENDING }.orEmpty().toTypedArray()
100100
}
101101

102102
/**
@@ -105,7 +105,7 @@ class MigrationInfoServiceImpl(
105105
* @return The applied migrations. An empty array if none.
106106
*/
107107
override fun applied(): Array<MigrationInfo> {
108-
return migrationInfos?.filter { it.state.isApplied }.orEmpty<MigrationInfo>().toTypedArray()
108+
return migrationInfos.filter { it.state.isApplied }.orEmpty().toTypedArray()
109109
}
110110

111111
/**
@@ -114,7 +114,7 @@ class MigrationInfoServiceImpl(
114114
* @return The resolved migrations. An empty array if none.
115115
*/
116116
override fun resolved(): Array<MigrationInfo> {
117-
return migrationInfos?.filter { it.state.isResolved }.orEmpty<MigrationInfo>().toTypedArray()
117+
return migrationInfos.filter { it.state.isResolved }.orEmpty().toTypedArray()
118118
}
119119

120120
/**
@@ -123,7 +123,7 @@ class MigrationInfoServiceImpl(
123123
* @return The failed migrations. An empty array if none.
124124
*/
125125
override fun failed(): Array<MigrationInfo> {
126-
return migrationInfos?.filter { it.state.isFailed }.orEmpty<MigrationInfo>().toTypedArray()
126+
return migrationInfos.filter { it.state.isFailed }.orEmpty().toTypedArray()
127127
}
128128

129129
/**
@@ -132,7 +132,7 @@ class MigrationInfoServiceImpl(
132132
* @return The future migrations. An empty array if none.
133133
*/
134134
override fun future(): Array<MigrationInfo> {
135-
return migrationInfos?.filter { it.state === MigrationState.FUTURE_SUCCESS }.orEmpty<MigrationInfo>().toTypedArray()
135+
return migrationInfos.filter { it.state === MigrationState.FUTURE_SUCCESS }.orEmpty().toTypedArray()
136136
}
137137

138138
/**
@@ -141,7 +141,7 @@ class MigrationInfoServiceImpl(
141141
* @return The out of order migrations. An empty array if none.
142142
*/
143143
override fun outOfOrder(): Array<MigrationInfo> {
144-
return migrationInfos?.filter { it.state === MigrationState.OUT_OF_ORDER }.orEmpty<MigrationInfo>().toTypedArray()
144+
return migrationInfos.filter { it.state === MigrationState.OUT_OF_ORDER }.orEmpty().toTypedArray()
145145
}
146146

147147
/**

0 commit comments

Comments
 (0)