Skip to content

Commit bffe472

Browse files
committed
Made dates fields not nullable
1 parent 26d84e4 commit bffe472

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/org/javawebstack/orm/migration/AutoMigrator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static void migrateTable(SQLPool pool, TableInfo info, boolean tableExis
6363
sb.append('(')
6464
.append(parameterTypes)
6565
.append(')');
66-
sb.append(info.isNotNull(fieldName) ? " NOT NULL" : " NULL");
66+
sb.append(info.isNotNull(fieldName) || isDatesField(info, fieldName) ? " NOT NULL" : " NULL");
6767
if (info.isAutoIncrement() && info.getIdField().equals(fieldName))
6868
sb.append(" AUTO_INCREMENT");
6969
if (columnKeys.containsKey(columnName)) {
@@ -194,4 +194,11 @@ private static List<String> getTables(SQLPool pool) {
194194
}
195195
}
196196

197+
private static boolean isDatesField(TableInfo info, String fieldName) {
198+
if (!info.hasDates())
199+
return false;
200+
201+
return fieldName.equals(info.getCreatedField()) || fieldName.equals(info.getUpdatedField());
202+
}
203+
197204
}

0 commit comments

Comments
 (0)