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 7d1be4e6
authored
Dec 27, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrations
1 parent
f014bd26
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
bin/sequelize
bin/sequelize
View file @
7d1be4e
#!/usr/bin/env node
var
path
=
require
(
"path"
)
,
fs
=
require
(
"fs"
)
,
program
=
require
(
"commander"
)
,
configPath
=
__dirname
+
'/../config'
const
path
=
require
(
"path"
)
,
fs
=
require
(
"fs"
)
,
program
=
require
(
"commander"
)
,
Sequelize
=
require
(
__dirname
+
'/../index'
)
,
_
=
Sequelize
.
Utils
.
_
var
configPath
=
__dirname
+
'/../config'
,
configFile
=
configPath
+
'/config.json'
,
configPathExists
=
path
.
existsSync
(
configPath
)
,
configFileExists
=
path
.
existsSync
(
configFile
)
...
...
@@ -12,13 +15,21 @@ var writeConfig = function(config) {
!
configPathExists
&&
fs
.
mkdirSync
(
configPath
)
config
=
JSON
.
stringify
(
config
)
config
=
config
.
replace
(
'{'
,
'{\n'
)
config
=
config
.
replace
(
/,/g
,
",\n"
)
config
=
config
.
replace
(
'{'
,
'{\n
'
)
config
=
config
.
replace
(
/,/g
,
",\n
"
)
config
=
config
.
replace
(
'}'
,
"\n}"
)
fs
.
writeFileSync
(
configFile
,
config
)
}
var
readConfig
=
function
()
{
try
{
return
JSON
.
parse
(
fs
.
readFileSync
(
configFile
))
}
catch
(
e
)
{
throw
new
Error
(
'The config.json is not available or contains invalid JSON.'
)
}
}
program
.
version
(
'1.3.0'
)
.
option
(
'-i, --init'
,
'Initializes the project. Creates a config/config.json'
)
...
...
@@ -28,7 +39,19 @@ program
if
(
program
.
migrate
)
{
if
(
configFileExists
)
{
var
config
=
readConfig
()
,
options
=
{}
_
.
each
(
config
,
function
(
value
,
key
)
{
if
([
'database'
,
'username'
,
'password'
].
indexOf
(
key
)
==
-
1
)
{
options
[
key
]
=
value
}
})
options
=
_
.
extend
(
options
,
{
logging
:
false
})
var
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
options
)
sequelize
.
migrate
({
path
:
__dirname
+
'/../spec/assets/migrations'
})
}
else
{
throw
new
Error
(
'Please add a configuration file under config/config.json. You might run "sequelize --init".'
)
}
...
...
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