Skip to content

Commit

Permalink
Refactoring models to use a single column for primaryKey
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyfox committed Jul 29, 2017
1 parent 6994e4b commit 3864f4d
Show file tree
Hide file tree
Showing 28 changed files with 117 additions and 198 deletions.
135 changes: 54 additions & 81 deletions eanaEltuMigration/dictionary.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions models/dictionaryBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
DictionaryBlock.belongsTo(models.Language, {
foreignKey: {
allowNull: false,
primaryKey: true
allowNull: false
},
constraints: true,
onDelete: 'cascade'
Expand Down
2 changes: 1 addition & 1 deletion models/dictionaryBuild.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const DictionaryBuild = sequelize.define('DictionaryBuild', {
id: { type: DataTypes.STRING, primaryKey: true },
name: { type: DataTypes.STRING, allowNull: false },
description: { type: DataTypes.STRING }
});

Expand Down
4 changes: 1 addition & 3 deletions models/dictionaryBuildData.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const DictionaryBuildData = sequelize.define('DictionaryBuildData', {
position: { type: DataTypes.INTEGER, primaryKey: true },
position: { type: DataTypes.INTEGER, allowNull: false },
type: { type: DataTypes.STRING},
data: { type: DataTypes.TEXT, allowNull: true }
});
Expand All @@ -10,7 +10,6 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
DictionaryBuildData.belongsTo(models.DictionaryBuild, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand All @@ -19,7 +18,6 @@ module.exports = function (sequelize, DataTypes) {

DictionaryBuildData.belongsTo(models.Language, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
3 changes: 1 addition & 2 deletions models/dictionaryTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
DictionaryTemplate.belongsTo(models.Language, {
foreignKey: {
allowNull: false,
primaryKey: true
allowNull: false
},
constraints: true,
onDelete: 'cascade'
Expand Down
3 changes: 1 addition & 2 deletions models/entryLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module.exports = function (sequelize, DataTypes) {
through: {
model: models.EntryLayoutTemplates,
unique: false
},
primaryKey: true
}
});
};

Expand Down
6 changes: 3 additions & 3 deletions models/entryLayoutTemplates.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const EntryLayoutTemplates = sequelize.define('EntryLayoutTemplates', {
position: { type: DataTypes.INTEGER, primaryKey: true, defaultValue: 0 },
field: { type: DataTypes.STRING, primaryKey: true }
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
position: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
field: { type: DataTypes.STRING, allowNull: false }
});

EntryLayoutTemplates.associate = function (models) {
Expand All @@ -13,7 +14,6 @@ module.exports = function (sequelize, DataTypes) {

EntryLayoutTemplates.belongsTo(models.EntryLayout, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
3 changes: 1 addition & 2 deletions models/entryTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = function (sequelize, DataTypes) {
through: {
model: models.EntryLayoutTemplates,
unique: false
},
primaryKey: true
}
});
};

Expand Down
8 changes: 2 additions & 6 deletions models/entryType.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ module.exports = function (sequelize, DataTypes) {
onDelete: 'CASCADE'
});

EntryType.belongsToMany(models.Lemma, {
through: {
model: models.EntryTypeEntries,
unique: false
},
primaryKey: true
EntryType.hasMany(models.Lemma, {
onDelete: 'CASCADE'
});

EntryType.belongsToMany(models.Metadata, {
Expand Down
24 changes: 0 additions & 24 deletions models/entryTypeEntries.js

This file was deleted.

6 changes: 1 addition & 5 deletions models/entryTypeLayouts.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const EntryTypeLayout = sequelize.define('EntryTypeLayout', {
order: { type: DataTypes.INTEGER, primaryKey: true }
order: { type: DataTypes.INTEGER, allowNull: false }
});

EntryTypeLayout.removeAttribute('id');

EntryTypeLayout.associate = function (models) {
// associations can be defined here
EntryTypeLayout.belongsTo(models.EntryType, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand All @@ -19,7 +16,6 @@ module.exports = function (sequelize, DataTypes) {

EntryTypeLayout.belongsTo(models.EntryLayout, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
25 changes: 0 additions & 25 deletions models/entryTypeTemplates.js

This file was deleted.

5 changes: 2 additions & 3 deletions models/grapheme.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const Grapheme = sequelize.define('Grapheme', {
id: { type: DataTypes.STRING, primaryKey: true },
grapheme: { type: DataTypes.STRING, allowNull: false },
sortOrder: { type: DataTypes.INTEGER, allowNull: false }
});

Grapheme.associate = function (models) {
// associations can be defined here
Grapheme.belongsTo(models.Language, {
foreignKey: {
allowNull: false,
primaryKey: true
allowNull: false
},
constraints: true,
onDelete: 'cascade'
Expand Down
2 changes: 0 additions & 2 deletions models/graphemePhonemeCorrespondence.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
GraphemePhonemeCorrespondence.belongsTo(models.Grapheme, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand All @@ -19,7 +18,6 @@ module.exports = function (sequelize, DataTypes) {

GraphemePhonemeCorrespondence.belongsTo(models.Phoneme, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
3 changes: 1 addition & 2 deletions models/lemma.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
Lemma.belongsTo(models.Language, {
foreignKey: {
allowNull: false,
primaryKey: true
allowNull: false
},
constraints: true,
onDelete: 'cascade'
Expand Down
3 changes: 1 addition & 2 deletions models/lemmaClassType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const LemmaClassType = sequelize.define('LemmaClassType', {
id: { type: DataTypes.STRING, allowNull: false, primaryKey: true },
classType: { type: DataTypes.STRING, allowNull: false },
name: { type: DataTypes.STRING, allowNull: false },
abbreviation: { type: DataTypes.STRING, allowNull: false },
description: { type: DataTypes.STRING, allowNull: true }
Expand All @@ -11,7 +11,6 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
LemmaClassType.belongsTo(models.Language, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
2 changes: 0 additions & 2 deletions models/lemmaClassTypeAssociation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
LemmaClassTypeAssociation.belongsTo(models.Lemma, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand All @@ -19,7 +18,6 @@ module.exports = function (sequelize, DataTypes) {

LemmaClassTypeAssociation.belongsTo(models.LemmaClassType, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
4 changes: 0 additions & 4 deletions models/lemmaDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ module.exports = function (sequelize, DataTypes) {
odd: DataTypes.TEXT
});

LemmaDefinition.removeAttribute('id');

LemmaDefinition.associate = function (models) {
// associations can be defined here
LemmaDefinition.belongsTo(models.Lemma, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
onDelete: 'cascade'
});
LemmaDefinition.belongsTo(models.Language, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
4 changes: 0 additions & 4 deletions models/linkedLemma.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ module.exports = function (sequelize, DataTypes) {
note: { type: DataTypes.STRING, allowNull: true }
});

LinkedLemma.removeAttribute('id');

LinkedLemma.associate = function (models) {
// associations can be defined here
LinkedLemma.belongsTo(models.Lemma, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand All @@ -20,7 +17,6 @@ module.exports = function (sequelize, DataTypes) {
LinkedLemma.belongsTo(models.Lemma, {
as: "ReferencesLemma",
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
4 changes: 0 additions & 4 deletions models/localizedEntryLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ module.exports = function (sequelize, DataTypes) {
changeable: { type: DataTypes.STRING, allowNull: false, defaultValue: "" }
});

LocalizedEntryLayout.removeAttribute('id');

LocalizedEntryLayout.associate = function (models) {
// associations can be defined here
LocalizedEntryLayout.belongsTo(models.EntryType, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
onDelete: 'CASCADE'
});
LocalizedEntryLayout.belongsTo(models.Language, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
4 changes: 0 additions & 4 deletions models/localizedMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ module.exports = function (sequelize, DataTypes) {
value: { type: DataTypes.TEXT, allowNull: false }
});

LocalizedMetadata.removeAttribute('id');

LocalizedMetadata.associate = function (models) {
// associations can be defined here
LocalizedMetadata.belongsTo(models.Metadata, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
onDelete: 'cascade'
});
LocalizedMetadata.belongsTo(models.Language, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
3 changes: 1 addition & 2 deletions models/morpheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
Morpheme.belongsTo(models.Language, {
foreignKey: {
allowNull: false,
primaryKey: true
allowNull: false
},
constraints: true,
onDelete: 'cascade'
Expand Down
3 changes: 1 addition & 2 deletions models/morphemeAffixType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module.exports = function (sequelize, DataTypes) {
// associations can be defined here
MorphemeAffixType.belongsTo(models.Language, {
foreignKey: {
allowNull: false,
primaryKey: true
allowNull: false
},
constraints: true,
onDelete: 'cascade'
Expand Down
4 changes: 0 additions & 4 deletions models/morphemeDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ module.exports = function (sequelize, DataTypes) {
odd: DataTypes.TEXT
});

MorphemeDefinition.removeAttribute('id');

MorphemeDefinition.associate = function (models) {
// associations can be defined here
MorphemeDefinition.belongsTo(models.Morpheme, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
onDelete: 'cascade'
});
MorphemeDefinition.belongsTo(models.Language, {
foreignKey: {
primaryKey: true,
allowNull: false
},
constraints: true,
Expand Down
Loading

0 comments on commit 3864f4d

Please sign in to comment.