Close #1317 Remove migration of lastlogin column from timestamp to bigint

This commit is contained in:
ljacqu 2018-12-04 19:51:11 +01:00
parent bce1110b13
commit 136b9e4b6e

View File

@ -59,49 +59,11 @@ final class MySqlMigrater {
columnType = rs.getInt("DATA_TYPE");
}
if (columnType == Types.TIMESTAMP) {
migrateLastLoginColumnFromTimestamp(st, tableName, col);
} else if (columnType == Types.INTEGER) {
if (columnType == Types.INTEGER) {
migrateLastLoginColumnFromInt(st, tableName, col);
}
}
/**
* Performs conversion of lastlogin column from timestamp type to bigint.
*
* @param st Statement object to the database
* @param tableName the table name
* @param col the column names configuration
* @see <a href="https://github.com/AuthMe/AuthMeReloaded/issues/477">#477</a>
*/
private static void migrateLastLoginColumnFromTimestamp(Statement st, String tableName,
Columns col) throws SQLException {
ConsoleLogger.info("Migrating lastlogin column from timestamp to bigint");
final String lastLoginOld = col.LAST_LOGIN + "_old";
// Rename lastlogin to lastlogin_old
String sql = String.format("ALTER TABLE %s CHANGE COLUMN %s %s BIGINT",
tableName, col.LAST_LOGIN, lastLoginOld);
st.execute(sql);
// Create lastlogin column
sql = String.format("ALTER TABLE %s ADD COLUMN %s "
+ "BIGINT NOT NULL DEFAULT 0 AFTER %s",
tableName, col.LAST_LOGIN, col.LAST_IP);
st.execute(sql);
// Set values of lastlogin based on lastlogin_old
sql = String.format("UPDATE %s SET %s = UNIX_TIMESTAMP(%s) * 1000",
tableName, col.LAST_LOGIN, lastLoginOld);
st.execute(sql);
// Drop lastlogin_old
sql = String.format("ALTER TABLE %s DROP COLUMN %s",
tableName, lastLoginOld);
st.execute(sql);
ConsoleLogger.info("Finished migration of lastlogin (timestamp to bigint)");
}
/**
* Performs conversion of lastlogin column from int to bigint.
*