File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,22 @@ const PoolConfig = require('mysql/lib/PoolConfig');
12
12
const SqlString = require ( 'mysql/lib/protocol/SqlString' ) ;
13
13
const TableDefinition = require ( './TableDefinition' ) ;
14
14
15
- const isEmpty = require ( 'lodash/isEmpty' ) ;
16
-
17
15
const MIGRATION_STRATEGIES = [
18
16
'safe' ,
19
17
'alter' ,
20
18
'drop' ,
21
19
] ;
22
20
21
+ function isObjectEmpty ( obj ) {
22
+ for ( var key in obj ) {
23
+ if ( ! obj . hasOwnProperty || obj . hasOwnProperty ( key ) ) {
24
+ return false ;
25
+ }
26
+ }
27
+
28
+ return true ;
29
+ }
30
+
23
31
function validateMigrationStrategy ( strategy ) {
24
32
if ( strategy && MIGRATION_STRATEGIES . indexOf ( strategy ) < 0 ) {
25
33
throw new Error ( `"${ strategy } " is not a valid migration strategy` ) ;
@@ -97,7 +105,7 @@ class PoolPlus extends Pool {
97
105
if ( this . _tables . has ( name ) ) {
98
106
throw new Error ( `A table called "${ name } " has already been defined for this pool` ) ;
99
107
}
100
- if ( isEmpty ( schema . columns ) ) {
108
+ if ( isObjectEmpty ( schema . columns ) ) {
101
109
throw new Error ( 'The schema must have at least one table column' ) ;
102
110
}
103
111
validateMigrationStrategy ( migrationStrategy ) ;
Original file line number Diff line number Diff line change @@ -110,6 +110,12 @@ describe('PoolPlus', () => {
110
110
it ( 'should throw if no columns are provided' , ( ) => {
111
111
should . throws ( ( ) => pool . defineTable ( 'table' , { } ) , / m u s t h a v e .* c o l u m n / ) ;
112
112
should . throws ( ( ) => pool . defineTable ( 'table' , { columns : { } } ) , / m u s t h a v e .* c o l u m n / ) ;
113
+ should . throws ( ( ) => pool . defineTable ( 'table' , { columns : Object . create ( null ) } ) , / m u s t h a v e .* c o l u m n / ) ;
114
+
115
+ function Clazz ( ) { /* constructor */ }
116
+ Clazz . prototype . foo = 1 ; // So the instance will have enumerable properties but no "own" properties
117
+
118
+ should . throws ( ( ) => pool . defineTable ( 'table' , { columns : new Clazz ( ) } ) , / m u s t h a v e .* c o l u m n / ) ;
113
119
} ) ;
114
120
115
121
it ( 'should throw if the specified migration strategy is invalid' , ( ) => {
You can’t perform that action at this time.
0 commit comments