h2.vm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- 将该建表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/create_tables.sql 文件里
  2. CREATE TABLE IF NOT EXISTS "${table.tableName.toLowerCase()}" (
  3. #foreach ($column in $columns)
  4. #if (${column.javaType} == 'Long')
  5. #set ($dataType='bigint')
  6. #elseif (${column.javaType} == 'Integer')
  7. #set ($dataType='int')
  8. #elseif (${column.javaType} == 'Boolean')
  9. #set ($dataType='bit')
  10. #elseif (${column.javaType} == 'Date')
  11. #set ($dataType='datetime')
  12. #else
  13. #set ($dataType='varchar')
  14. #end
  15. #if (${column.primaryKey})##处理主键
  16. "${column.javaField}"#if (${column.javaType} == 'String') ${dataType} NOT NULL#else ${dataType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end,
  17. #else
  18. #if (${column.columnName} == 'create_time')
  19. "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  20. #elseif (${column.columnName} == 'update_time')
  21. "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  22. #elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater')
  23. "${column.columnName}" ${dataType} DEFAULT '',
  24. #elseif (${column.columnName} == 'deleted')
  25. "deleted" bit NOT NULL DEFAULT FALSE,
  26. #elseif (${column.columnName} == 'tenant_id')
  27. "tenant_id" bigint NOT NULL DEFAULT 0,
  28. #else
  29. "${column.columnName.toLowerCase()}" ${dataType}#if (${column.nullable} == false) NOT NULL#end,
  30. #end
  31. #end
  32. #end
  33. PRIMARY KEY ("${primaryColumn.columnName.toLowerCase()}")
  34. ) COMMENT '${table.tableComment}';
  35. -- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/clean.sql 文件里
  36. DELETE FROM "${table.tableName}";