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 1a38b088
authored
Jan 02, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
1c16980a
a5b4c60a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
9 deletions
bin/sequelize
lib/dialects/postgres/query-generator.js
package.json
test/dao-factory/create.test.js
test/sequelize.executable.test.js
test/support.js
bin/sequelize
View file @
1a38b08
...
...
@@ -6,6 +6,7 @@ var path = require("path")
,
Sequelize
=
require
(
__dirname
+
'/../index'
)
,
moment
=
require
(
"moment"
)
,
_
=
Sequelize
.
Utils
.
_
,
url
=
require
(
"url"
)
var
configuration
=
{
configFile
:
process
.
cwd
()
+
'/config/config.json'
,
...
...
@@ -86,19 +87,54 @@ var createMigrationsFolder = function(force) {
}
}
var
parseDbUrl
=
function
(
urlString
)
{
var
urlParts
,
config
=
{};
try
{
urlParts
=
url
.
parse
(
urlString
)
config
.
database
=
urlParts
.
path
.
replace
(
/^
\/
/
,
''
);
config
.
dialect
=
urlParts
.
protocol
;
config
.
dialect
=
config
.
dialect
.
replace
(
/:$/
,
''
);
config
.
host
=
urlParts
.
hostname
;
config
.
port
=
urlParts
.
port
;
if
(
config
.
dialect
===
'sqlite'
)
{
config
.
storage
=
'/'
+
config
.
database
;
}
if
(
urlParts
.
auth
)
{
config
.
username
=
urlParts
.
auth
.
split
(
':'
)[
0
]
config
.
password
=
urlParts
.
auth
.
split
(
':'
)[
1
]
}
}
catch
(
e
)
{
throw
new
Error
(
'Error parsing url: '
+
url
);
}
return
config
};
var
readConfig
=
function
()
{
var
config
try
{
config
=
require
(
configuration
.
configFile
);
}
catch
(
e
)
{
throw
new
Error
(
'Error reading "'
+
relativeConfigFile
()
+
'".'
)
if
(
program
.
url
)
{
config
=
parseDbUrl
(
program
.
url
);
}
else
{
try
{
config
=
require
(
configuration
.
configFile
);
}
catch
(
e
)
{
throw
new
Error
(
'Error reading "'
+
relativeConfigFile
()
+
'".'
)
}
}
if
(
typeof
config
!=
'object'
)
{
throw
new
Error
(
'Config must be an object: '
+
relativeConfigFile
());
}
console
.
log
(
'Loaded configuration file "'
+
relativeConfigFile
()
+
'".'
)
if
(
program
.
url
)
{
console
.
log
(
'Parsed url '
+
program
.
url
);
}
else
{
console
.
log
(
'Loaded configuration file "'
+
relativeConfigFile
()
+
'".'
);
}
if
(
config
[
configuration
.
environment
])
{
console
.
log
(
'Using environment "'
+
configuration
.
environment
+
'".'
)
config
=
config
[
configuration
.
environment
]
...
...
@@ -114,6 +150,7 @@ program
.
option
(
'-u, --undo'
,
'Undo the last migration.'
)
.
option
(
'-f, --force'
,
'Forces the action to be done.'
)
.
option
(
'-c, --create-migration [migration-name]'
,
'Creates a new migration.'
)
.
option
(
'-U, --url <url>'
,
'Database url. An alternative to a config file'
)
.
option
(
'--config <config_file>'
,
'Specifies alternate config file.'
)
.
parse
(
process
.
argv
)
...
...
@@ -130,7 +167,7 @@ if(typeof program.env === 'string') {
}
if
(
program
.
migrate
)
{
if
(
configFileExists
())
{
if
(
configFileExists
()
||
program
.
url
)
{
var
config
,
options
=
{}
...
...
lib/dialects/postgres/query-generator.js
View file @
1a38b08
...
...
@@ -311,7 +311,7 @@ module.exports = (function() {
tuples
.
push
(
"("
+
Utils
.
_
.
map
(
attrValueHash
,
function
(
value
,
key
){
if
(
serials
.
indexOf
(
key
)
!==
-
1
)
{
return
'DEFAULT'
;
return
value
||
'DEFAULT'
;
}
return
this
.
escape
(
value
)
}.
bind
(
this
)).
join
(
","
)
+
...
...
package.json
View file @
1a38b08
...
...
@@ -26,6 +26,10 @@
{
"name"
:
"Daniel Durante"
,
"email"
:
"me@danieldurante.com"
},
{
"name"
:
"Mick Hansen"
,
"email"
:
"mick.kasper.hansen@gmail.com"
}
],
"repository"
:
{
...
...
@@ -85,4 +89,4 @@
"node"
:
">=0.6.21"
},
"license"
:
"MIT"
}
\ No newline at end of file
}
test/dao-factory/create.test.js
View file @
1a38b08
...
...
@@ -907,6 +907,23 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'should allow autoincremented attributes to be set'
,
function
(
done
)
{
var
Worker
=
this
.
sequelize
.
define
(
'Worker'
,
{},
{
timestamps
:
false
})
Worker
.
sync
().
done
(
function
(
err
)
{
Worker
.
bulkCreate
([
{
id
:
5
},
{
id
:
10
}
]).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
Worker
.
findAll
({
order
:
'id ASC'
}).
done
(
function
(
err
,
workers
)
{
expect
(
workers
[
0
].
id
).
to
.
equal
(
5
)
expect
(
workers
[
1
].
id
).
to
.
equal
(
10
)
done
()
})
})
})
})
describe
(
'enums'
,
function
()
{
it
(
'correctly restores enum values'
,
function
(
done
)
{
var
self
=
this
...
...
test/sequelize.executable.test.js
View file @
1a38b08
...
...
@@ -206,4 +206,70 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
})
})
})([
'--migrate'
,
'-m'
])
;(
function
(
flags
)
{
flags
.
forEach
(
function
(
flag
)
{
var
prepare
=
function
(
callback
)
{
exec
(
"rm -rf ./*"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"../../bin/sequelize --init"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"cp ../assets/migrations/*-createPerson.js ./migrations/"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"cat ../support.js|sed s,/../,/../../, > ./support.js"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
var
dialect
=
Support
.
getTestDialect
()
,
config
=
require
(
__dirname
+
'/config/config.js'
)
config
.
sqlite
.
storage
=
__dirname
+
"/tmp/test.sqlite"
config
=
_
.
extend
(
config
,
config
[
dialect
],
{
dialect
:
dialect
})
var
url
=
Support
.
getTestUrl
(
config
);
exec
(
"echo '"
+
JSON
.
stringify
(
config
)
+
"' > config/config.json"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"../../bin/sequelize -m "
+
flag
+
" "
+
url
,
{
cwd
:
__dirname
+
"/tmp"
},
callback
)
})
})
})
})
})
}
describe
(
flag
,
function
()
{
it
(
"creates a SequelizeMeta table"
,
function
(
done
)
{
var
sequelize
=
this
.
sequelize
if
(
this
.
sequelize
.
options
.
dialect
===
'sqlite'
)
{
var
options
=
this
.
sequelize
.
options
options
.
storage
=
__dirname
+
"/tmp/test.sqlite"
sequelize
=
new
Support
.
Sequelize
(
""
,
""
,
""
,
options
)
}
prepare
(
function
()
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tables
)
{
tables
=
tables
.
sort
()
expect
(
tables
).
to
.
have
.
length
(
2
)
expect
(
tables
[
1
]).
to
.
equal
(
"SequelizeMeta"
)
done
()
})
}.
bind
(
this
))
})
it
(
"creates the respective table via url"
,
function
(
done
)
{
var
sequelize
=
this
.
sequelize
if
(
this
.
sequelize
.
options
.
dialect
===
'sqlite'
)
{
var
options
=
this
.
sequelize
.
options
options
.
storage
=
__dirname
+
"/tmp/test.sqlite"
sequelize
=
new
Support
.
Sequelize
(
""
,
""
,
""
,
options
)
}
prepare
(
function
()
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tables
)
{
tables
=
tables
.
sort
()
expect
(
tables
).
to
.
have
.
length
(
2
)
expect
(
tables
[
0
]).
to
.
equal
(
"Person"
)
done
()
})
}.
bind
(
this
))
})
})
})
})([
'--url'
,
'-U'
])
})
test/support.js
View file @
1a38b08
...
...
@@ -137,6 +137,19 @@ var Support = {
}
return
"["
+
dialect
.
toUpperCase
()
+
"] "
+
moduleName
},
getTestUrl
:
function
(
config
)
{
var
url
,
dbConfig
=
config
[
config
.
dialect
];
if
(
config
.
dialect
===
'sqlite'
)
{
url
=
'sqlite://'
+
dbConfig
.
storage
;
}
else
{
url
=
config
.
dialect
+
"://"
+
dbConfig
.
username
+
"@"
+
dbConfig
.
host
+
":"
+
dbConfig
.
port
+
"/"
+
dbConfig
.
database
;
}
return
url
;
}
}
...
...
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