Skip to content

Commit 0690899

Browse files
committed
fix: fix a bug when the entity has another entity as field
fix herbsjs#64
1 parent cb8db24 commit 0690899

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/generators/src/infra/database/migrations/migrations.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ module.exports =
1919

2020
for (const entity of Array.from(entities.values())) {
2121
const { name, schema } = entity.entity.prototype.meta
22-
22+
2323
if (glob.sync(`${migrationsPath}/*_${camelCase(name)}s.js`).length) {
2424
// don't override already existing migration files for that entity
2525
continue
2626
}
2727

2828
function type2Str(Type) {
29-
const _type = new Type()
30-
if (_type instanceof String) return 'string'
31-
if (_type instanceof Number) return 'integer'
32-
if (_type instanceof Boolean) return 'boolean'
33-
if (_type instanceof Date) return 'timestamp'
29+
const nativeTypes = [Boolean, Number, String, Array, Object, Date, Function]
30+
31+
if (nativeTypes.includes(Type)) {
32+
const _type = new Type()
33+
if (_type instanceof String) return 'string'
34+
if (_type instanceof Number) return 'integer'
35+
if (_type instanceof Boolean) return 'boolean'
36+
if (_type instanceof Date) return 'timestamp'
37+
}
3438
}
3539

3640
function getDBType(appDir) {

0 commit comments

Comments
 (0)