added database value generation with identity generation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package jef.platform.mysql.migration;
|
||||
|
||||
import jef.model.annotations.Generated;
|
||||
import jef.model.migration.operation.AddFieldOperation;
|
||||
import jef.model.migration.operation.AddForeignKeyOperation;
|
||||
import jef.model.migration.operation.AddIndexOperation;
|
||||
@@ -59,6 +60,8 @@ public class MysqlMigrationOperationTranslator implements MigrationOperationTran
|
||||
return connection.prepareStatement("ALTER TABLE `" + op.getTable() + "`"
|
||||
+ " ADD COLUMN `" + op.getField() + "` "
|
||||
+ op.getSqlType() + (op.isNotNull() ? " NOT NULL" : "") //TODO add after field specification
|
||||
+ (op.getGenerated() == Generated.Type.IDENTITY ? "AUTO_INCREMENT " : "")
|
||||
// + (op.getGenerated() == Generated.Type.COMPUTED ? "AUTO_INCREMENT " : "")//TODO
|
||||
+ " LAST");
|
||||
}
|
||||
|
||||
@@ -100,7 +103,10 @@ public class MysqlMigrationOperationTranslator implements MigrationOperationTran
|
||||
return connection.prepareStatement("CREATE TABLE `" + op.getTable() + "` ("
|
||||
+ op.getFields().stream().map(e -> {
|
||||
var f = e.build();
|
||||
return "`" + f.getField() + "` " + f.getSqlType() + (f.isNotNull() ? " NOT NULL" : "");
|
||||
return "`" + f.getField() + "` " + f.getSqlType()
|
||||
+ (f.isNotNull() ? " NOT NULL" : "")
|
||||
+ (f.getGenerated() == Generated.Type.IDENTITY ? " AUTO_INCREMENT" : "");
|
||||
// + (op.getGenerated() == Generated.Type.COMPUTED ? "AUTO_INCREMENT " : "")//TODO
|
||||
}).collect(Collectors.joining(", "))
|
||||
+ (op.getPrimaryKey() != null
|
||||
? ", PRIMARY KEY (" + op.getPrimaryKey().build().getFields().stream().map(e -> "`" + e + "`").collect(Collectors.joining(", ")) + ")"
|
||||
|
||||
Reference in New Issue
Block a user