Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
4caf109
Add string escape for postgresql in custom query
Apr 5, 2013
773b2b6
Ajust Test config with default value
Apr 5, 2013
0d08651
- useful error message for bad data type (fixes #551)
Apr 17, 2013
db76b11
- correcting error message
Apr 18, 2013
94ce958
- changed error message to match expected test result
Apr 18, 2013
513aeb1
- adding second test for object style definition
Apr 25, 2013
75d7eef
Update the generated migration skeleton for async
Apr 26, 2013
0328b0a
Merge pull request #567 from terraflubb/migration_skeleton_gen_async_…
sdepold Apr 26, 2013
9011d75
Merge pull request #553 from crossman/master
janmeier Apr 28, 2013
f1ecabb
Change from _.each to native forEach
janmeier Apr 28, 2013
8ccd34b
Revert back to _.each, idiot
janmeier Apr 28, 2013
3791a29
When value is null, don't try to convert to Date, instead just leave it
mweibel Apr 29, 2013
9e82d76
Add test for checking the new behaviour
mweibel Apr 29, 2013
fe199e9
Change important MySQL query generator functions from using _.templat…
alum Apr 29, 2013
1009cb9
#572
sdepold Apr 29, 2013
b2184b2
v1.7.0-alpha1
sdepold Apr 29, 2013
4827513
Change important MySQL query generator functions from using _.templat…
alum Apr 29, 2013
d69ee78
Merge branch 'mysql-performance-improvements' of https://github.com/a…
alum Apr 29, 2013
efa85a9
Remove unnecessary semi-colon from query
alum May 2, 2013
a1c06dd
Merge pull request #573 from alum/mysql-performance-improvements
mickhansen May 2, 2013
92bb5fe
Added decimal support for min/max, closes #579
durango May 2, 2013
1c56292
Merge pull request #583 from durango/master
durango May 2, 2013
34ed0d7
'ORDER BY' should come after 'GROUP BY'
mekanics May 2, 2013
1f1364d
Merge branch 'postgres-clause-order-fix' of git://github.com/mekanics…
durango May 2, 2013
c78b739
Updated changelog
durango May 2, 2013
750817c
Merge branch 'master' of git://github.com/wyplay/sequelize into wypla…
durango May 3, 2013
644f6ef
Support for foreign keys in creating tables
optilude Apr 30, 2013
8f86153
Tests + fixes for attributesToSQL
optilude Apr 30, 2013
559e1ce
Basic implementation of capturing foreign key status
optilude Apr 30, 2013
10ec7ff
Tidy up setting of new attributes
optilude May 4, 2013
556a663
Topologically sorted iterator for DAOs taking dependencies into account
optilude May 4, 2013
f293a11
Create tables in dependency order
optilude May 4, 2013
be4ffc9
Support for dropping tables with constraints
optilude May 4, 2013
417a832
Skeletal test
optilude May 4, 2013
03ca029
Fixes after rebase
optilude May 5, 2013
1df9027
Don't pretend like composite primary keys work: they need to be handl…
optilude May 5, 2013
151a23f
Factor FK constraint logic out into a helper function
optilude May 5, 2013
6643167
Make cascade optional
optilude May 6, 2013
47f7e4c
Turn on foreign key checking for SQLite
optilude May 6, 2013
db1a504
Improve pragma handling for sqlite3
optilude May 6, 2013
9180844
Improve test coverage for cascade deletion in postgres
optilude May 6, 2013
7491c22
Tests for delete cascade
optilude May 6, 2013
27e9f9a
Replaced underscore with lodash.
durango May 6, 2013
35aeb2c
Test for update cascade and restrict
optilude May 6, 2013
809453f
Minor updates following comments form @janmeier
optilude May 7, 2013
5e12d1b
Merge pull request #594 from durango/lodash
sdepold May 8, 2013
3b03f5d
Update README.md
sdepold May 8, 2013
d25e697
lodash
sdepold May 8, 2013
256db5c
Merge pull request #595 from optilude/fk-constraints
sdepold May 8, 2013
d0cfa94
fk constraints
sdepold May 8, 2013
cfa224b
Updated roadmap with foreign key support
janmeier May 8, 2013
08c69a8
Added deletedAt buster tests borrowed from @gustawpursche
janmeier May 8, 2013
067e97c
Merge pull request #597 from innofluence/deletedAtTest
janmeier May 8, 2013
7e9d13d
Merge branch 'master' of github.com:sequelize/sequelize
sdepold May 9, 2013
7affa31
fixed url to irc channel
sdepold May 9, 2013
3c05453
Validations will now be called upon .save() and allowNull: true skips…
durango May 9, 2013
421fc4f
DAO factory API sketch
optilude Apr 21, 2013
2029345
Query interface and generator API sketch
optilude Apr 21, 2013
cfb657a
Implementation sketch and query generators
optilude Apr 23, 2013
290e895
Refactored and simplified create method plus outline tests
optilude Apr 24, 2013
eff68d6
Refactor given understanding of how it's possible to return autogener…
optilude Apr 27, 2013
ea0926f
Enum test
optilude Apr 27, 2013
daf936f
Test for bulk update
optilude Apr 27, 2013
a8a1254
Tests for bulkUpdate
optilude Apr 27, 2013
ade36f1
Test + fix for bulk delete
optilude Apr 27, 2013
65db2ad
Changelog entry
optilude Apr 27, 2013
31ec3a1
Fix typo in interface method name
optilude Apr 27, 2013
3b951e1
Rename and rationalise methods as per discussion on GitHub
optilude Apr 28, 2013
d2e9adc
Rebase onto sequelize master and reflect MySQL query generator refact…
optilude May 6, 2013
f5d9359
Update tests thanks to @janmeier's review
optilude May 7, 2013
fedb9cd
Merge pull request #569 from optilude/master
janmeier May 9, 2013
00f5f77
Change roadmap for bulk update, insert, delete
janmeier May 9, 2013
ecd1672
Added final changes as requested by sdepold
durango May 9, 2013
054a603
Added link to bulk insert, update, delete
janmeier May 9, 2013
d7a96a1
Merge pull request #601 from durango/validate-save-null
durango May 9, 2013
eea3828
Some PR broke this concept, so I'm not safely type checking all the w…
durango May 9, 2013
f692de9
Merge pull request #602 from durango/hstore-raw
durango May 9, 2013
d066f93
Upgraded validation for IPv6 support. Closes #371
durango May 9, 2013
0b5f0f1
Merge pull request #603 from durango/upgraded-validation
durango May 9, 2013
b168e55
error messages ftw
sdepold May 10, 2013
5e8eac2
Add failing case for MySQL query gen with bool. (Issue #607)
terraflubb May 10, 2013
42a44f1
MySQL: Outgoing booleans are turned into ints
terraflubb May 10, 2013
72d2737
Minor low-hanging changes to improve jshint performance
terraflubb May 10, 2013
026efd4
Failing tests for MySQL where clause value processing
terraflubb May 10, 2013
3f20fb5
Process values going into WHERE clauses in MySQL
terraflubb May 10, 2013
46f5caf
Migration environment set from command line args
terraflubb May 11, 2013
37244f1
(Subjectively) improve copy in binary
terraflubb May 11, 2013
6f65e6d
Include a done() in the migration skeleton
terraflubb May 11, 2013
4c23c8a
Throw nicer errors when we can't read config.json
terraflubb May 11, 2013
61482c0
Make migrations more verbose and time migrations
terraflubb May 11, 2013
eda888a
DataTypes improved
willrnch May 11, 2013
3935784
package.json now links to the right repo
janmeier May 11, 2013
ae1d4f6
Allow find and findall to take query options
janmeier May 11, 2013
3d1043c
update changelog
janmeier May 11, 2013
023e751
Yay TRAVIS
janmeier May 11, 2013
e772a0c
Merge pull request #613 from innofluence/findQueryOptions
durango May 11, 2013
b3b9cc1
Merge branch 'master' of github.com:sequelize/sequelize
sdepold May 13, 2013
c23f27a
Merge branch 'master' of git://github.com/Costent/sequelize into Cost…
sdepold May 13, 2013
01b66ce
added tests for new data types
sdepold May 13, 2013
705b752
Merge branch 'Costent-master'
sdepold May 13, 2013
6d5b8a1
convenient data types
sdepold May 13, 2013
48eba5f
Merge branch 'master' of github.com:sequelize/sequelize
sdepold May 13, 2013
c15eacd
Merge branch 'make_binary_verbose' of git://github.com/terraflubb/seq…
sdepold May 13, 2013
b4361e6
fixed logging
sdepold May 13, 2013
2514c2d
more verbose binary
sdepold May 13, 2013
2fece68
Merge branch 'terraflubb-make_binary_verbose'
sdepold May 13, 2013
1f2ef88
a test that makes sure that null values are correctly restored
sdepold May 13, 2013
d3669c8
Merge pull request #608 from terraflubb/mysql_bools_save_as_tinyints
sdepold May 13, 2013
2cf8d70
boolean handling
sdepold May 13, 2013
a1c6256
merge sequelize/sequelize
base698 May 13, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ env:
language: node_js

node_js:
- 0.8

- 0.8
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,26 @@ Also make sure to take a look at the examples in the repository. The website wil

- [Documentation](http://www.sequelizejs.com)
- [Twitter](http://twitter.com/sdepold)
- [IRC](irc://irc.freenode.net/sequelizejs)
- [IRC](http://webchat.freenode.net?channels=sequelizejs)
- [Google Groups](https://groups.google.com/forum/#!forum/sequelize)
- [XING](https://www.xing.com/net/priec1b5cx/sequelize) (pretty much inactive, but you might want to name it on your profile)

## Roadmap

A very basic roadmap. Chances aren't too bad, that not mentioned things are implemented as well. Don't panic :)

### 1.6.0 (ToDo)
- ~~Fix last issues with eager loading of associated data~~
- ~~Find out why Person.belongsTo(House) would add person_id to house. It should add house_id to person~~

### 1.7.0
- Check if lodash is a proper alternative to current underscore usage.
- ~~Check if lodash is a proper alternative to current underscore usage.~~
- Transactions
- Support for update of tables without primary key
- MariaDB support
- Support for update and delete calls for whole tables without previous loading of instances
- ~~Support for update and delete calls for whole tables without previous loading of instances~~ Implemented in [#569](https://github.com/sequelize/sequelize/pull/569) thanks to @optiltude
- Eager loading of nested associations [#388](https://github.com/sdepold/sequelize/issues/388#issuecomment-12019099)
- Model#delete
- Validate a model before it gets saved. (Move validation of enum attribute value to validate method)
- BLOB [#99](https://github.com/sdepold/sequelize/issues/99)
- Support for foreign keys
- ~~Validate a model before it gets saved.~~ Implemented in [#601](https://github.com/sequelize/sequelize/pull/601), thanks to @durango
- Move validation of enum attribute value to validate method
- BLOB [#99](https://github.com/sequelize/sequelize/issues/99)
- ~~Support for foreign keys~~ Implemented in [#595](https://github.com/sequelize/sequelize/pull/595), thanks to @optilude

### 1.7.x
- Complete support for non-id primary keys
Expand All @@ -74,6 +71,7 @@ A very basic roadmap. Chances aren't too bad, that not mentioned things are impl
### 2.0.0
- ~~save datetimes in UTC~~
- encapsulate attributes if a dao inside the attributes property + add getters and setters
- add proper error message everywhere


## Collaboration 2.0 ##
Expand Down
40 changes: 29 additions & 11 deletions bin/sequelize
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const path = require("path")
, _ = Sequelize.Utils._

var configPath = process.cwd() + '/config'
, environment = process.env.NODE_ENV || 'development'
, migrationsPath = process.cwd() + '/migrations'
, packageJsonPath = __dirname + '/../package.json'
, packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString())
Expand Down Expand Up @@ -78,22 +79,36 @@ var readConfig = function() {
throw new Error('The config.json is not available or contains invalid JSON.')
}
}
return config
}

program
.version(packageJson.version)
.option('-i, --init', 'Initializes the project. Creates a config/config.json')
.option('-m, --migrate', 'Runs undone migrations')
.option('-i, --init', 'Initializes the project.')
.option('-e, --env <environment>', 'Specify the environment.')
.option('-m, --migrate', 'Run pending migrations.')
.option('-u, --undo', 'Undo the last migration.')
.option('-f, --force', 'Forces the action to be done.')
.option('-c, --create-migration [migration-name]', 'Create a new migration skeleton file.')
.option('-c, --create-migration [migration-name]', 'Creates a new migration.')
.parse(process.argv)

if(typeof program.env === 'string') {
environment = program.env
}
console.log("Using environment '" + environment + "'.")

if(program.migrate) {
if(process.env.DATABASE_URL || configFileExists) {
var config = readConfig()
, options = {}

try {
config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}

_.each(config, function(value, key) {
if(['database', 'username', 'password'].indexOf(key) == -1) {
options[key] = value
Expand Down Expand Up @@ -146,9 +161,10 @@ if(program.migrate) {
}
})

console.log('Successfully created config.json')
console.log('Created "config/config.json"')
} else {
console.log('A config.json already exists. Run "sequelize --init --force" to overwrite it.')
console.log('"config/config.json" already exists. Run "sequelize --init --force" to overwrite.')
process.exit(1)
}

createMigrationsFolder(program.force)
Expand All @@ -157,21 +173,23 @@ if(program.migrate) {

var migrationName = [
moment().format('YYYYMMDDHHmmss'),
(typeof program.createMigration == 'string') ? program.createMigration : 'unnamed-migration'
(typeof program.createMigration === 'string') ? program.createMigration : 'unnamed-migration'
].join('-') + '.js'

var migrationContent = [
"module.exports = {",
" up: function(migration, DataTypes) {",
" // add altering commands here",
" up: function(migration, DataTypes, done) {",
" // add altering commands here, calling 'done' when finished",
" done()",
" },",
" down: function(migration) {",
" // add reverting commands here",
" down: function(migration, DataTypes, done) {",
" // add reverting commands here, calling 'done' when finished",
" done()",
" }",
"}"
].join('\n')

fs.writeFileSync(migrationsPath + '/' + migrationName, migrationContent)
} else {
console.log('Please define any params!')
console.log('Try "sequelize --help" for usage information.')
}
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# v1.7.0 #
- [DEPENDENCIES] Upgraded validator for IPv6 support. [#603](https://github.com/sequelize/sequelize/pull/603). thanks to durango
- [FEATURE] Validate a model before it gets saved. [#601](https://github.com/sequelize/sequelize/pull/601). thanks to durango
- [DEPENDENCIES] replaced underscore by lodash. [#954](https://github.com/sequelize/sequelize/pull/594). thanks to durango
- [BUG] Fix string escape with postgresql on raw SQL queries. [#586](https://github.com/sequelize/sequelize/pull/586). thanks to zanamixx
- [BUG] "order by" is now after "group by". [#585](https://github.com/sequelize/sequelize/pull/585). thanks to mekanics
- [BUG] Added decimal support for min/max. [#583](https://github.com/sequelize/sequelize/pull/583). thanks to durango
- [BUG] Null dates don't break SQLite anymore. [#572](https://github.com/sequelize/sequelize/pull/572). thanks to mweibel
- [BUG] Correctly handle booleans in MySQL. [#608](https://github.com/sequelize/sequelize/pull/608). Thanks to terraflubb
- [FEATURE] Schematics. [#564](https://github.com/sequelize/sequelize/pull/564). thanks to durango
- [FEATURE] Foreign key constraints. [#595](https://github.com/sequelize/sequelize/pull/595). thanks to optilude
- [FEATURE] Support for bulk insert (`<DAOFactory>.bulkCreate()`, update (`<DAOFactory>.update()`) and delete (`<DAOFactory>.destroy()`) [#569](https://github.com/sequelize/sequelize/pull/569). thanks to optilude
- [FEATURE] Add an extra `queryOptions` parameter to `DAOFactory.find` and `DAOFactory.findAll`. This allows a user to specify `{ raw: true }`, meaning that the raw result should be returned, instead of built DAOs. Usefull for queries returning large datasets, see [#611](https://github.com/sequelize/sequelize/pull/611) janmeier
- [FEATURE] Added convenient data types. [#616](https://github.com/sequelize/sequelize/pull/616). Thanks to Costent
- [FEATURE] Binary is more verbose now. [#612](https://github.com/sequelize/sequelize/pull/612). Thanks to terraflubb

# v1.6.0 #
- [DEPENDENCIES] upgrade mysql to alpha7. You *MUST* use this version or newer for DATETIMEs to work
Expand Down
2 changes: 2 additions & 0 deletions lib/associations/belongs-to.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Utils = require("./../utils")
, DataTypes = require('./../data-types')
, Helpers = require('./helpers')

module.exports = (function() {
var BelongsTo = function(srcDAO, targetDAO, options) {
Expand All @@ -24,6 +25,7 @@ module.exports = (function() {

this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.target.tableName) + "Id", this.source.options.underscored)
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.target, this.source, this.options)
Utils._.defaults(this.source.rawAttributes, newAttributes)

// Sync attributes to DAO proto each time a new assoc is added
Expand Down
2 changes: 2 additions & 0 deletions lib/associations/has-many.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Utils = require("./../utils")
, DataTypes = require('./../data-types')
, Helpers = require('./helpers')

var HasManySingleLinked = require("./has-many-single-linked")
, HasManyMultiLinked = require("./has-many-double-linked")
Expand Down Expand Up @@ -65,6 +66,7 @@ module.exports = (function() {
} else {
var newAttributes = {}
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.source, this.target, this.options)
Utils._.defaults(this.target.rawAttributes, newAttributes)
}

Expand Down
2 changes: 2 additions & 0 deletions lib/associations/has-one.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Utils = require("./../utils")
, DataTypes = require('./../data-types')
, Helpers = require("./helpers")

module.exports = (function() {
var HasOne = function(srcDAO, targetDAO, options) {
Expand Down Expand Up @@ -29,6 +30,7 @@ module.exports = (function() {

this.identifier = this.options.foreignKey || Utils._.underscoredIf(Utils.singularize(this.source.tableName) + "Id", this.options.underscored)
newAttributes[this.identifier] = { type: DataTypes.INTEGER }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.source, this.target, this.options)
Utils._.defaults(this.target.rawAttributes, newAttributes)

// Sync attributes to DAO proto each time a new assoc is added
Expand Down
25 changes: 25 additions & 0 deletions lib/associations/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Utils = require("./../utils")

module.exports = {

addForeignKeyConstraints: function(newAttribute, source, target, options) {
// FK constraints are opt-in: users must either rset `foreignKeyConstraints`
// on the association, or request an `onDelete` or `onUpdate` behaviour

if(options.foreignKeyConstraint || options.onDelete || options.onUpdate) {

// Find primary keys: composite keys not supported with this approach
var primaryKeys = Utils._.filter(Utils._.keys(source.rawAttributes), function(key) {
return source.rawAttributes[key].primaryKey
})

if(primaryKeys.length == 1) {
newAttribute.references = source.tableName,
newAttribute.referencesKey = primaryKeys[0]
newAttribute.onDelete = options.onDelete,
newAttribute.onUpdate = options.onUpdate
}
}
}

}
31 changes: 31 additions & 0 deletions lib/dao-factory-manager.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var Toposort = require('toposort-class')

module.exports = (function() {
var DAOFactoryManager = function(sequelize) {
this.daos = []
Expand Down Expand Up @@ -31,5 +33,34 @@ module.exports = (function() {
return this.daos
})

/**
* Iterate over DAOs in an order suitable for e.g. creating tables. Will
* take foreign key constraints into account so that dependencies are visited
* before dependents.
*/
DAOFactoryManager.prototype.forEachDAO = function(iterator) {
var daos = {}
, sorter = new Toposort()

this.daos.forEach(function(dao) {
daos[dao.tableName] = dao
var deps = []

for(var attrName in dao.rawAttributes) {
if(dao.rawAttributes.hasOwnProperty(attrName)) {
if(dao.rawAttributes[attrName].references) {
deps.push(dao.rawAttributes[attrName].references)
}
}
}

sorter.add(dao.tableName, deps)
})

sorter.sort().reverse().forEach(function(name) {
iterator(daos[name])
})
}

return DAOFactoryManager
})()
Loading