Skip to content

Commit

Permalink
Be smarter about columnType.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Apr 20, 2018
1 parent 944f2b7 commit 09bdc15
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 108 deletions.
74 changes: 37 additions & 37 deletions features/autoIncrement/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
Feature: autoIncrement
======================

Enable this test in `package.json` with: `"features": ["autoIncrement"]`

When autoIncrement is set to true on an attribute and no value is provided for it a new unique value
will be assigned by the adapter before the record is created. It is guaranteed that the adapter will
assign a unique value not present on any existing record. The values assigned automatically will not
necessarily be sequential, which accommodates the use of UUIDs. If a value for the attribute is
present in the data provided for a new record it will be saved as-is without any guarantee of uniqueness.
The autoIncrement option has no effect when updating existing records.

Usage on Waterline models:

```
attributes: {
id: {
type: "integer", // or "string"
autoIncrement: true
}
}
```

## Sub-Features

### autoIncrement.sequential

Enable this test in `package.json` with: `"features": ["autoIncrement.sequential"]`

If the adapter will provide sequential unique values, for example increasing integers, then it is
further guaranteed that the next value will be the last saved value plus one increment. If a value
is provided and is larger than the current auto-inc counter the counter will be bumped to the
provided value. If a provided value is less than or equal to the auto-inc counter value the
counter will remain unchanged, and again there will be no guaranteed that this value is unique.

This sub-feature is a special case/implementation detail of the `autoIncrement` attribute by
selected adapters and is not configured explicitly.
Feature: autoIncrement
======================

Enable this test in `package.json` with: `"features": ["autoIncrement"]`

When autoIncrement is set to true on an attribute and no value is provided for it a new unique value
will be assigned by the adapter before the record is created. It is guaranteed that the adapter will
assign a unique value not present on any existing record. The values assigned automatically will not
necessarily be sequential, which accommodates the use of UUIDs. If a value for the attribute is
present in the data provided for a new record it will be saved as-is without any guarantee of uniqueness.
The autoIncrement option has no effect when updating existing records.

Usage on Waterline models:

```
attributes: {
id: {
type: 'number', // or 'string'
autoIncrement: true
}
}
```

## Sub-Features

### autoIncrement.sequential

Enable this test in `package.json` with: `"features": ["autoIncrement.sequential"]`

If the adapter will provide sequential unique values, for example increasing integers, then it is
further guaranteed that the next value will be the last saved value plus one increment. If a value
is provided and is larger than the current auto-inc counter the counter will be bumped to the
provided value. If a provided value is less than or equal to the auto-inc counter value the
counter will remain unchanged, and again there will be no guaranteed that this value is unique.

This sub-feature is a special case/implementation detail of the `autoIncrement` attribute by
selected adapters and is not configured explicitly.
12 changes: 6 additions & 6 deletions features/autoIncrement/support/autoInc.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ module.exports = function() {
name: {
type: 'string',
autoMigrations: {
columnType: 'varchar'
columnType: 'varchar'
}
},
normalField: {
type: 'number',
autoMigrations: {
columnType: 'integer'
columnType: '_number'
}
},
type: {
type: 'string',
autoMigrations: {
columnType: 'varchar'
}
columnType: 'varchar'
}
},
id: {
type: 'number',
autoMigrations: {
autoIncrement: true,
columnType: 'integer'
columnType: '_numberkey'
}
}
}

});
};
};
2 changes: 1 addition & 1 deletion features/compositePrimaryKey/support/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = Waterline.Collection.extend({
attributes: {
name: 'string',
pkOne: {
type: 'integer',
type: 'number',
primaryKey: true
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = Waterline.Collection.extend({
connection: 'associations2',

attributes: {
amount: 'integer',
amount: 'number',
type: 'string',
apartment: {
model: 'apartment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = Waterline.Collection.extend({

// migrate: 'drop',
attributes: {
medallion: 'integer',
medallion: 'number',
model: 'string',
drivers: {
collection: 'driver',
Expand Down
4 changes: 2 additions & 2 deletions features/unique/support/unique.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = Waterline.Collection.extend({
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true,
}
},
Expand Down
2 changes: 1 addition & 1 deletion interfaces/associations/support/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var defaults = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module.exports = {
fetchRecordsOnDestroy: false,
fetchRecordsOnCreate: true,
fetchRecordsOnCreateEach: true,

attributes: {
// Primary Key
id: {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand All @@ -37,7 +37,7 @@ module.exports = {
type: 'json',
autoMigrations: {
columnType: 'json',
}
}
},

// Timestamps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports.payment = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down Expand Up @@ -86,8 +86,8 @@ module.exports.customer = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
8 changes: 4 additions & 4 deletions interfaces/associations/support/fixtures/oneToOne.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports.user_resource = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down Expand Up @@ -78,8 +78,8 @@ module.exports.profile = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
},
Expand Down
2 changes: 1 addition & 1 deletion interfaces/migratable/support/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var defaults = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true
}
Expand Down
4 changes: 2 additions & 2 deletions interfaces/migratable/support/fixtures/alter.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true,
}
},
Expand Down
6 changes: 3 additions & 3 deletions interfaces/migratable/support/fixtures/create.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true,
}
},

name: {
type: 'string',
autoMigrations: {
Expand Down
6 changes: 3 additions & 3 deletions interfaces/migratable/support/fixtures/custom.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = {
type: Adapter.identity === 'sails-mongo' ? 'string' : 'number',
columnName: '_id',
autoMigrations: {
columnType: 'integer',
autoIncrement: true,
columnType: Adapter.identity === 'sails-mongo' ? '_stringkey' : '_numberkey',
autoIncrement: Adapter.identity === 'sails-mongo' ? false : true,
unique: true,
}
},

name: {
type: 'string',
columnName: 'nameColumn',
Expand Down
Loading

1 comment on commit 09bdc15

@mikermcneil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.