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 22d12aa6
authored
Jul 01, 2014
by
Nuno Sousa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix change column migration for enums on Postgres
1 parent
d934bbaa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletions
lib/dialects/postgres/query-generator.js
test/assets/migrations/20111205163000-addColumnLevelAndChangeToEnumToUser.js
test/migrator.test.js
lib/dialects/postgres/query-generator.js
View file @
22d12aa
...
...
@@ -215,6 +215,7 @@ module.exports = (function() {
if
(
definition
.
match
(
/^ENUM
\(
/
))
{
query
=
this
.
pgEnum
(
tableName
,
attributeName
,
definition
)
+
query
;
definition
=
definition
.
replace
(
/^ENUM
\(
.+
\)
/
,
this
.
quoteIdentifier
(
'enum_'
+
tableName
+
'_'
+
attributeName
));
definition
+=
' USING ('
+
this
.
quoteIdentifier
(
attributeName
)
+
'::'
+
this
.
quoteIdentifier
(
definition
)
+
')'
;
}
if
(
definition
.
match
(
/UNIQUE;*$/
))
{
...
...
test/assets/migrations/20111205163000-addColumnLevelAndChangeToEnumToUser.js
0 → 100644
View file @
22d12aa
module
.
exports
=
{
up
:
function
(
migration
,
DataTypes
,
done
)
{
migration
.
addColumn
(
'User'
,
'level'
,
{
type
:
DataTypes
.
STRING
}).
complete
(
function
()
{
migration
.
changeColumn
(
'User'
,
'level'
,
{
type
:
DataTypes
.
ENUM
,
allowNull
:
false
,
values
:
[
'basic'
,
'advanced'
]
}).
complete
(
done
);
});
},
down
:
function
(
migration
,
DataTypes
,
done
)
{
migration
.
removeColumn
(
'User'
,
'level'
).
complete
(
done
);
}
};
test/migrator.test.js
View file @
22d12aa
...
...
@@ -100,7 +100,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
SequelizeMeta
.
create
({
from
:
null
,
to
:
20111117063700
}).
success
(
function
()
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
1
4
)
expect
(
migrations
).
to
.
have
.
length
(
1
5
)
expect
(
migrations
[
0
].
filename
).
to
.
equal
(
'20111130161100-emptyMigration.js'
)
done
()
})
...
...
@@ -317,6 +317,28 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
})
it
(
'changes the level column from user and casts the data to the target enum type'
,
function
(
done
)
{
var
self
=
this
this
.
init
({
to
:
20111205163000
},
function
(
migrator
)
{
migrator
.
migrate
().
success
(
function
()
{
self
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
complete
(
function
(
err
,
data
)
{
var
level
=
data
.
level
;
if
(
dialect
===
'postgres'
)
{
expect
(
level
.
type
).
to
.
equal
(
'USER-DEFINED'
);
}
else
if
(
dialect
===
'sqlite'
)
{
expect
(
level
.
type
).
to
.
equal
(
'TEXT'
);
}
else
{
expect
(
level
.
type
).
to
.
equal
(
'ENUM(\'BASIC\',\'ADVANCED\')'
);
}
done
()
})
})
})
})
})
})
...
...
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