Skip to content

Commit c79dd22

Browse files
authored
Merge pull request #143 from ebean-orm/wip/91-early-checksum-2
Reduce columns selected for existing migrations to id, type, version and checksum
2 parents 6ad439e + f8a654f commit c79dd22

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

ebean-migration/src/main/java/io/ebean/migration/runner/MigrationMetaRow.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/**
1010
* Bean holding migration execution details stored in the migration table.
1111
*/
12+
@SuppressWarnings("SqlSourceToSinkFlow")
1213
final class MigrationMetaRow {
1314

1415
private final int id;
15-
//private String status;
1616
private final String type;
1717
private final String version;
18-
private final String comment;
18+
private String comment;
1919
private int checksum;
2020
private Timestamp runOn;
2121
private String runBy;
@@ -41,18 +41,13 @@ final class MigrationMetaRow {
4141
MigrationMetaRow(ResultSet row) throws SQLException {
4242
id = row.getInt(1);
4343
type = row.getString(2);
44-
//status = row.getString(3);
45-
version = row.getString(4);
46-
comment = row.getString(5);
47-
checksum = row.getInt(6);
48-
runOn = row.getTimestamp(7);
49-
runBy = row.getString(8);
50-
runTime = row.getLong(9);
44+
version = row.getString(3);
45+
checksum = row.getInt(4);
5146
}
5247

5348
@Override
5449
public String toString() {
55-
return "id:" + id + " type:" + type + " checksum:" + checksum + " runVersion:" + version + " comment:" + comment + " runOn:" + runOn + " runBy:" + runBy;
50+
return "id:" + id + " type:" + type + " checksum:" + checksum + " version:" + version;
5651
}
5752

5853
/**
@@ -111,17 +106,15 @@ private void bindUpdate(PreparedStatement update) throws SQLException {
111106
*/
112107
static String insertSql(String table) {
113108
return "insert into " + table
114-
+ " (id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time)"
115-
+ " values (?,?,?,?,?,?,?,?,?)";
109+
+ " (id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time) values (?,?,?,?,?,?,?,?,?)";
116110
}
117111

118112
/**
119113
* Return the SQL insert given the table migration meta data is stored in.
120114
*/
121115
static String updateSql(String table) {
122116
return "update " + table
123-
+ " set mchecksum=?, run_on=?, run_by=?, run_time=? "
124-
+ " where id = ?";
117+
+ " set mchecksum=?, run_on=?, run_by=?, run_time=? where id = ?";
125118
}
126119

127120
/**

ebean-migration/src/main/java/io/ebean/migration/runner/MigrationPlatform.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MigrationPlatform {
1818
private static final System.Logger log = MigrationTable.log;
1919

2020
private static final String BASE_SELECT_ID = "select id from ";
21-
private static final String BASE_SELECT_ALL = "select id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time from ";
21+
private static final String BASE_SELECT = "select id, mtype, mversion, mchecksum from ";
2222

2323
/**
2424
* Standard row locking for db migration table.
@@ -105,7 +105,7 @@ String sqlSelectForUpdate(String table) {
105105
* Return the SQL to read the db migration table.
106106
*/
107107
String sqlSelectForReading(String table) {
108-
return BASE_SELECT_ALL + table + forUpdateSuffix;
108+
return BASE_SELECT + table + forUpdateSuffix;
109109
}
110110

111111
static final class LogicalLock extends MigrationPlatform {

ebean-migration/src/test/java/io/ebean/migration/runner/MigrationMetaRowTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
import static org.assertj.core.api.Assertions.assertThat;
66

77

8-
public class MigrationMetaRowTest {
8+
class MigrationMetaRowTest {
99

1010
@Test
1111
void testSelectSql() {
1212

1313
final MigrationPlatform sqlServer = new MigrationPlatform.SqlServer();
1414
String sql = sqlServer.sqlSelectForReading("someTable");
15-
assertThat(sql).isEqualTo("select id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time from someTable with (updlock) order by id");
15+
assertThat(sql).isEqualTo("select id, mtype, mversion, mchecksum from someTable with (updlock) order by id");
1616

1717
final MigrationPlatform noLocking = new MigrationPlatform.NoLocking();
1818
sql = noLocking.sqlSelectForReading("someTable");
19-
assertThat(sql).isEqualTo("select id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time from someTable order by id");
19+
assertThat(sql).isEqualTo("select id, mtype, mversion, mchecksum from someTable order by id");
2020

2121
final MigrationPlatform postgres = new MigrationPlatform.Postgres();
2222
sql = postgres.sqlSelectForReading("someTable");
23-
assertThat(sql).isEqualTo("select id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time from someTable order by id for update");
23+
assertThat(sql).isEqualTo("select id, mtype, mversion, mchecksum from someTable order by id for update");
2424

2525
final MigrationPlatform defaultPlatform = new MigrationPlatform();
2626
sql = defaultPlatform.sqlSelectForReading("someTable");
27-
assertThat(sql).isEqualTo("select id, mtype, mstatus, mversion, mcomment, mchecksum, run_on, run_by, run_time from someTable order by id for update");
27+
assertThat(sql).isEqualTo("select id, mtype, mversion, mchecksum from someTable order by id for update");
2828
}
2929

3030
}

0 commit comments

Comments
 (0)