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 552fc607
authored
Dec 06, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove column
1 parent
a83e88d2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
26 deletions
lib/connectors/mysql/query-generator.js
lib/connectors/query-generator.js
lib/query-interface.js
spec/assets/migrations/20111206061400-removeShopIdColumnFromUser.js
spec/migrator.spec.js
lib/connectors/mysql/query-generator.js
View file @
552fc60
...
...
@@ -57,6 +57,11 @@ var QueryGenerator = module.exports = {
return
Utils
.
_
.
template
(
query
)({
tableName
:
tableName
,
attributes
:
attrString
})
},
removeColumnQuery
:
function
(
tableName
,
attributeName
)
{
var
query
=
"ALTER TABLE `<%= tableName %>` DROP `<%= attributeName %>`;"
return
Utils
.
_
.
template
(
query
)({
tableName
:
tableName
,
attributeName
:
attributeName
})
},
/*
Returns a query for selecting elements in the database <tableName>.
Options:
...
...
lib/connectors/query-generator.js
View file @
552fc60
...
...
@@ -16,6 +16,40 @@ module.exports = (function() {
},
/*
Returns a rename table query.
Parameters:
- originalTableName: Name of the table before execution.
- futureTableName: Name of the table after execution.
*/
renameTableQuery
:
function
(
originalTableName
,
futureTableName
)
{
throw
new
Error
(
'Define the method renameQuery!'
)
},
/*
Returns a query, which adds an attribute to an existing table.
Parameters:
- tableName: Name of the existing table.
- attributeName: Name of the new attribute.
- options: A hash with attribute specific options:
- type: DataType
- defaultValue: A String with the default value
- allowNull: Boolean
*/
addColumnQuery
:
function
(
tableName
,
attributeName
,
options
)
{
throw
new
Error
(
'Define the method addColumnQuery!'
)
},
/*
Returns a query, which removes an attribute from an existing table.
Parameters:
- tableName: Name of the existing table
- attributeName: Name of the obsolete attribute.
*/
removeColumnQuery
:
function
(
tableName
,
attributeName
)
{
throw
new
Error
(
'Define the method removeColumnQuery!'
)
},
/*
Returns a query for selecting elements in the table <tableName>.
Options:
- attributes -> An array of attributes (e.g. ['name', 'birthday']). Default: *
...
...
@@ -69,30 +103,6 @@ module.exports = (function() {
},
/*
Returns a rename table query.
Parameters:
- originalTableName: Name of the table before execution.
- futureTableName: Name of the table after execution.
*/
renameTableQuery
:
function
(
originalTableName
,
futureTableName
)
{
throw
new
Error
(
'Define the method renameQuery!'
)
},
/*
Returns a query, which adds an attribute to an existing table.
Parameters:
- tableName: Name of the existing table.
- attributeName: Name of the new attribute.
- options: A hash with attribute specific options:
- type: DataType
- defaultValue: A String with the default value
- allowNull: Boolean
*/
addColumnQuery
:
function
(
tableName
,
attributeName
,
options
)
{
throw
new
Error
(
'Define the method addColumnQuery!'
)
},
/*
Takes something and transforms it into values of a where condition.
*/
getWhereConditions
:
function
(
smth
)
{
...
...
lib/query-interface.js
View file @
552fc60
...
...
@@ -122,8 +122,19 @@ module.exports = (function() {
}).
run
()
}
QueryInterface
.
prototype
.
removeColumn
=
function
()
{
QueryInterface
.
prototype
.
removeColumn
=
function
(
tableName
,
attributeName
)
{
var
self
=
this
,
query
=
this
.
QueryGenerator
.
removeColumnQuery
(
tableName
,
attributeName
)
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
sequelize
.
query
(
query
).
success
(
function
()
{
self
.
emit
(
'removeColumn'
,
null
)
emitter
.
emit
(
'success'
,
null
)
}).
error
(
function
(
err
)
{
self
.
emit
(
'removeColumn'
,
err
)
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}
QueryInterface
.
prototype
.
changeColumn
=
function
()
{
...
...
spec/assets/migrations/20111206061400-removeShopIdColumnFromUser.js
0 → 100644
View file @
552fc60
module
.
exports
=
{
up
:
function
(
migration
,
DataTypes
)
{
migration
.
removeColumn
(
'User'
,
'shopId'
)
},
down
:
function
(
migration
,
DataTypes
)
{}
}
spec/migrator.spec.js
View file @
552fc60
...
...
@@ -97,7 +97,7 @@ describe('Migrator', function() {
})
expect
(
err
).
toBeFalsy
()
expect
(
migrations
.
length
).
toEqual
(
4
)
expect
(
migrations
.
length
).
toEqual
(
5
)
expect
(
migrations
[
0
].
filename
).
toEqual
(
'20111123060700-addBirthdateToPerson.js'
)
done
()
})
...
...
@@ -220,6 +220,38 @@ describe('Migrator', function() {
})
})
})
describe
(
'removeColumn'
,
function
()
{
it
(
'removes the shopId column from user'
,
function
()
{
setup
({
from
:
20111205064000
,
to
:
20111206061400
})
Helpers
.
async
(
function
(
done
)
{
migrator
.
migrate
().
success
(
done
).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
Helpers
.
async
(
function
(
done
)
{
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
var
signature
=
data
.
filter
(
function
(
hash
){
return
hash
.
Field
==
'signature'
})[
0
]
,
isAdmin
=
data
.
filter
(
function
(
hash
){
return
hash
.
Field
==
'isAdmin'
})[
0
]
,
shopId
=
data
.
filter
(
function
(
hash
){
return
hash
.
Field
==
'shopId'
})[
0
]
expect
(
signature
.
Field
).
toEqual
(
'signature'
)
expect
(
signature
.
Null
).
toEqual
(
'NO'
)
expect
(
isAdmin
.
Field
).
toEqual
(
'isAdmin'
)
expect
(
isAdmin
.
Null
).
toEqual
(
'NO'
)
expect
(
isAdmin
.
Default
).
toEqual
(
'0'
)
expect
(
shopId
).
toBeFalsy
()
done
()
}).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
})
})
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