Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit f97cac29
authored
Jul 31, 2018
by
Marco Barcellos
Committed by
Sushant
Jul 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(tests/changeColumn) (#9741)
1 parent
6fe9278a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
36 deletions
test/integration/query-interface/changeColumn.test.js
test/integration/query-interface/changeColumn.test.js
View file @
f97cac2
...
@@ -6,14 +6,6 @@ const Support = require(__dirname + '/../support');
...
@@ -6,14 +6,6 @@ const Support = require(__dirname + '/../support');
const
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
);
const
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
);
const
dialect
=
Support
.
getTestDialect
();
const
dialect
=
Support
.
getTestDialect
();
let
count
=
0
;
function
log
()
{
// sqlite fires a lot more querys than the other dbs. this is just a simple hack, since i'm lazy
if
(
dialect
!==
'sqlite'
||
count
===
0
)
{
count
++
;
}
};
describe
(
Support
.
getTestDialectTeaser
(
'QueryInterface'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'QueryInterface'
),
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
sequelize
.
options
.
quoteIdenifiers
=
true
;
this
.
sequelize
.
options
.
quoteIdenifiers
=
true
;
...
@@ -26,7 +18,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -26,7 +18,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
describe
(
'changeColumn'
,
()
=>
{
describe
(
'changeColumn'
,
()
=>
{
it
(
'should support schemas'
,
function
()
{
it
(
'should support schemas'
,
function
()
{
return
this
.
sequelize
.
createSchema
(
'archive'
).
bind
(
this
).
then
(
function
()
{
return
this
.
sequelize
.
createSchema
(
'archive'
).
then
(()
=>
{
return
this
.
queryInterface
.
createTable
({
return
this
.
queryInterface
.
createTable
({
tableName
:
'users'
,
tableName
:
'users'
,
schema
:
'archive'
schema
:
'archive'
...
@@ -37,14 +29,14 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -37,14 +29,14 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
autoIncrement
:
true
autoIncrement
:
true
},
},
currency
:
DataTypes
.
INTEGER
currency
:
DataTypes
.
INTEGER
}).
bind
(
this
).
then
(
function
()
{
}).
then
(()
=>
{
return
this
.
queryInterface
.
changeColumn
({
return
this
.
queryInterface
.
changeColumn
({
tableName
:
'users'
,
tableName
:
'users'
,
schema
:
'archive'
schema
:
'archive'
},
'currency'
,
{
},
'currency'
,
{
type
:
DataTypes
.
FLOAT
type
:
DataTypes
.
FLOAT
});
});
}).
then
(
function
()
{
}).
then
(
()
=>
{
return
this
.
queryInterface
.
describeTable
({
return
this
.
queryInterface
.
describeTable
({
tableName
:
'users'
,
tableName
:
'users'
,
schema
:
'archive'
schema
:
'archive'
...
@@ -69,12 +61,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -69,12 +61,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
autoIncrement
:
true
autoIncrement
:
true
},
},
currency
:
DataTypes
.
INTEGER
currency
:
DataTypes
.
INTEGER
}).
bind
(
this
).
then
(
function
()
{
}).
then
(()
=>
{
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'currency'
,
{
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'currency'
,
{
type
:
DataTypes
.
FLOAT
,
type
:
DataTypes
.
FLOAT
,
allowNull
:
true
allowNull
:
true
});
});
}).
then
(
function
()
{
}).
then
(
()
=>
{
return
this
.
queryInterface
.
describeTable
({
return
this
.
queryInterface
.
describeTable
({
tableName
:
'users'
tableName
:
'users'
});
});
...
@@ -95,7 +87,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -95,7 +87,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
tableName
:
'users'
tableName
:
'users'
},
{
},
{
firstName
:
DataTypes
.
STRING
firstName
:
DataTypes
.
STRING
}).
bind
(
this
).
then
(
function
()
{
}).
then
(()
=>
{
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'firstName'
,
{
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'firstName'
,
{
type
:
DataTypes
.
ENUM
([
'value1'
,
'value2'
,
'value3'
])
type
:
DataTypes
.
ENUM
([
'value1'
,
'value2'
,
'value3'
])
});
});
...
@@ -103,14 +95,14 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -103,14 +95,14 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
});
});
it
(
'should work with enums with schemas'
,
function
()
{
it
(
'should work with enums with schemas'
,
function
()
{
return
this
.
sequelize
.
createSchema
(
'archive'
).
bind
(
this
).
then
(
function
()
{
return
this
.
sequelize
.
createSchema
(
'archive'
).
then
(()
=>
{
return
this
.
queryInterface
.
createTable
({
return
this
.
queryInterface
.
createTable
({
tableName
:
'users'
,
tableName
:
'users'
,
schema
:
'archive'
schema
:
'archive'
},
{
},
{
firstName
:
DataTypes
.
STRING
firstName
:
DataTypes
.
STRING
});
});
}).
bind
(
this
).
then
(
function
()
{
}).
then
(()
=>
{
return
this
.
queryInterface
.
changeColumn
({
return
this
.
queryInterface
.
changeColumn
({
tableName
:
'users'
,
tableName
:
'users'
,
schema
:
'archive'
schema
:
'archive'
...
@@ -135,33 +127,86 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -135,33 +127,86 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
type
:
DataTypes
.
INTEGER
,
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
allowNull
:
false
}
}
})
}).
then
(()
=>
{
.
bind
(
this
).
then
(
function
()
{
return
this
.
queryInterface
.
createTable
(
'level'
,
{
return
this
.
queryInterface
.
createTable
(
'level'
,
{
id
:
{
id
:
{
type
:
DataTypes
.
INTEGER
,
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
primaryKey
:
true
,
autoIncrement
:
true
autoIncrement
:
true
}
}
});
});
});
});
});
});
it
(
'able to change column to foreign key'
,
function
()
{
it
(
'able to change column to foreign key'
,
function
()
{
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'level_id'
,
{
return
this
.
queryInterface
.
getForeignKeyReferencesForTable
(
'users'
).
then
(
foreignKeys
=>
{
type
:
DataTypes
.
INTEGER
,
expect
(
foreignKeys
).
to
.
be
.
an
(
'array'
);
references
:
{
expect
(
foreignKeys
).
to
.
be
.
empty
;
model
:
'level'
,
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'level_id'
,
{
key
:
'id'
type
:
DataTypes
.
INTEGER
,
},
references
:
{
onUpdate
:
'cascade'
,
model
:
'level'
,
onDelete
:
'cascade'
key
:
'id'
},
{
logging
:
log
}).
then
(()
=>
{
},
expect
(
count
).
to
.
be
.
equal
(
1
);
onUpdate
:
'cascade'
,
count
=
0
;
onDelete
:
'cascade'
});
}).
then
(()
=>
{
return
this
.
queryInterface
.
getForeignKeyReferencesForTable
(
'users'
);
}).
then
(
newForeignKeys
=>
{
expect
(
newForeignKeys
).
to
.
be
.
an
(
'array'
);
expect
(
newForeignKeys
).
to
.
have
.
lengthOf
(
1
);
expect
(
newForeignKeys
[
0
].
columnName
).
to
.
be
.
equal
(
'level_id'
);
});
});
});
});
it
(
'able to change column property without affecting other properties'
,
function
()
{
let
firstTable
,
firstForeignKeys
;
// 1. look for users table information
// 2. change column level_id on users to have a Foreign Key
// 3. look for users table Foreign Keys information
// 4. change column level_id AGAIN to allow null values
// 5. look for new foreign keys information
// 6. look for new table structure information
// 7. compare foreign keys and tables(before and after the changes)
return
this
.
queryInterface
.
describeTable
({
tableName
:
'users'
}).
then
(
describedTable
=>
{
firstTable
=
describedTable
;
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'level_id'
,
{
type
:
DataTypes
.
INTEGER
,
references
:
{
model
:
'level'
,
key
:
'id'
},
onUpdate
:
'cascade'
,
onDelete
:
'cascade'
});
}).
then
(
()
=>
{
return
this
.
queryInterface
.
getForeignKeyReferencesForTable
(
'users'
);
}).
then
(
keys
=>
{
firstForeignKeys
=
keys
;
return
this
.
queryInterface
.
changeColumn
(
'users'
,
'level_id'
,
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
true
});
}).
then
(
()
=>
{
return
this
.
queryInterface
.
getForeignKeyReferencesForTable
(
'users'
);
}).
then
(
newForeignKeys
=>
{
expect
(
firstForeignKeys
.
length
).
to
.
be
.
equal
(
newForeignKeys
.
length
);
expect
(
firstForeignKeys
[
0
].
columnName
).
to
.
be
.
equal
(
'level_id'
);
expect
(
firstForeignKeys
[
0
].
columnName
).
to
.
be
.
equal
(
newForeignKeys
[
0
].
columnName
);
return
this
.
queryInterface
.
describeTable
({
tableName
:
'users'
});
}).
then
(
describedTable
=>
{
expect
(
describedTable
.
level_id
).
to
.
have
.
property
(
'allowNull'
);
expect
(
describedTable
.
level_id
.
allowNull
).
to
.
not
.
equal
(
firstTable
.
level_id
.
allowNull
);
expect
(
describedTable
.
level_id
.
allowNull
).
to
.
be
.
equal
(
true
);
});
});
});
});
}
}
});
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment