Add models and relationships for sequelize
This commit is contained in:
@ -1,4 +1,59 @@
|
||||
import {sequelize} from "./Sequelize";
|
||||
import {Catalogue} from "./models/Catalogue";
|
||||
import {Character} from "./models/Character";
|
||||
import {CharacterGrowthRate} from "./models/CharacterGrowthRate";
|
||||
import {ClassGrowthRate} from "./models/ClassGrowthRate";
|
||||
import {FE_Class} from "./models/FE_Class";
|
||||
import {Gender} from "./models/Gender";
|
||||
import {House} from "./models/House";
|
||||
import {RestrictedCharacterClass} from "./models/RestrictedCharacterClass";
|
||||
import {Stat} from "./models/Stat";
|
||||
|
||||
// Sequelize associations
|
||||
|
||||
House.hasMany(Character, {
|
||||
sourceKey: "id",
|
||||
foreignKey: "idHouse",
|
||||
});
|
||||
|
||||
Gender.hasMany(Character, {
|
||||
sourceKey: "id",
|
||||
foreignKey: "idGender",
|
||||
});
|
||||
|
||||
Gender.hasMany(FE_Class, {
|
||||
sourceKey: "id",
|
||||
foreignKey: "idGender",
|
||||
});
|
||||
|
||||
Character.belongsToMany(FE_Class, {
|
||||
foreignKey: {name: "Id_Character"},
|
||||
through: RestrictedCharacterClass,
|
||||
});
|
||||
FE_Class.belongsToMany(Character, {
|
||||
foreignKey: {name: "Id_Class"},
|
||||
through: RestrictedCharacterClass,
|
||||
});
|
||||
|
||||
Character.belongsToMany(Stat, {
|
||||
foreignKey: {name: "Id_Character"},
|
||||
through: CharacterGrowthRate,
|
||||
});
|
||||
Stat.belongsToMany(Character, {
|
||||
foreignKey: {name: "Id_Stat"},
|
||||
through: CharacterGrowthRate,
|
||||
});
|
||||
|
||||
FE_Class.belongsToMany(Stat, {
|
||||
foreignKey: {name: "Id_Class"},
|
||||
through: ClassGrowthRate,
|
||||
});
|
||||
Stat.belongsToMany(FE_Class, {
|
||||
foreignKey: {name: "Id_Stat"},
|
||||
through: ClassGrowthRate,
|
||||
});
|
||||
|
||||
// Create tables if not exists
|
||||
sequelize.sync();
|
||||
|
||||
export {Catalogue, Character, CharacterGrowthRate, ClassGrowthRate, FE_Class, Gender, House, Stat, RestrictedCharacterClass};
|
40
server/src/models/Catalogue.ts
Normal file
40
server/src/models/Catalogue.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class Catalogue extends Model {
|
||||
public id!: number;
|
||||
public version!: string;
|
||||
public lastUpdate!: Date;
|
||||
}
|
||||
|
||||
const versionField = "No_Version";
|
||||
|
||||
Catalogue.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
field: "Id_Catalogue",
|
||||
},
|
||||
version: {
|
||||
type: DataTypes.STRING(16),
|
||||
allowNull: false,
|
||||
field: versionField
|
||||
},
|
||||
lastUpdate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
field: "Dttm_Last_Update"
|
||||
},
|
||||
}, {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: [versionField],
|
||||
},
|
||||
],
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Catalogue',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {Catalogue}
|
50
server/src/models/Character.ts
Normal file
50
server/src/models/Character.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class Character extends Model {
|
||||
public id!: number;
|
||||
public firstName: string;
|
||||
public lastName: string;
|
||||
public imgFileName: string;
|
||||
public idHouse!: number;
|
||||
public idGender!: number;
|
||||
}
|
||||
|
||||
Character.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
field: "Id_Character",
|
||||
},
|
||||
firstName: {
|
||||
type: DataTypes.STRING(32),
|
||||
allowNull: true,
|
||||
field: "Nm_First",
|
||||
},
|
||||
lastName: {
|
||||
type: DataTypes.STRING(32),
|
||||
allowNull: true,
|
||||
field: "Nm_Last",
|
||||
},
|
||||
imgFileName: {
|
||||
type: DataTypes.STRING(64),
|
||||
allowNull: true,
|
||||
field: "Nm_File_Img",
|
||||
},
|
||||
idHouse: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_House",
|
||||
},
|
||||
idGender: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Gender",
|
||||
},
|
||||
}, {
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Character',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {Character}
|
32
server/src/models/CharacterGrowthRate.ts
Normal file
32
server/src/models/CharacterGrowthRate.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class CharacterGrowthRate extends Model {
|
||||
public value!: number;
|
||||
public idCharacter!: number;
|
||||
public idStat!: number;
|
||||
}
|
||||
|
||||
CharacterGrowthRate.init({
|
||||
value: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false,
|
||||
field: "Nb_Value",
|
||||
},
|
||||
idCharacter: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Character",
|
||||
},
|
||||
idStat: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Stat",
|
||||
},
|
||||
}, {
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Character_Growth_Rate',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {CharacterGrowthRate};
|
32
server/src/models/ClassGrowthRate.ts
Normal file
32
server/src/models/ClassGrowthRate.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class ClassGrowthRate extends Model {
|
||||
public value!: number;
|
||||
public idClass!: number;
|
||||
public idStat!: number;
|
||||
}
|
||||
|
||||
ClassGrowthRate.init({
|
||||
value: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false,
|
||||
field: "Nb_Value",
|
||||
},
|
||||
idClass: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Class",
|
||||
},
|
||||
idStat: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Stat",
|
||||
},
|
||||
}, {
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Class_Growth_Rate',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {ClassGrowthRate};
|
46
server/src/models/FE_Class.ts
Normal file
46
server/src/models/FE_Class.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class FE_Class extends Model {
|
||||
public id!: number;
|
||||
public name!: string;
|
||||
public isAvailableForAll!: boolean;
|
||||
public idGender!: number;
|
||||
}
|
||||
|
||||
const nameField = "Nm_Class";
|
||||
|
||||
FE_Class.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
field: "Id_Class",
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(32),
|
||||
allowNull: false,
|
||||
field: nameField,
|
||||
},
|
||||
isAvailableForAll: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
field: "Is_Available_For_All",
|
||||
},
|
||||
idGender: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Gender",
|
||||
},
|
||||
}, {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: [nameField],
|
||||
},
|
||||
],
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Class',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {FE_Class}
|
34
server/src/models/Gender.ts
Normal file
34
server/src/models/Gender.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class Gender extends Model {
|
||||
public id!: number;
|
||||
public name!: string;
|
||||
}
|
||||
|
||||
const nameField = "Nm_Gender";
|
||||
|
||||
Gender.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
field: "Id_Gender",
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(16),
|
||||
allowNull: false,
|
||||
field: nameField,
|
||||
},
|
||||
}, {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: [nameField],
|
||||
}
|
||||
],
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Gender',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {Gender}
|
34
server/src/models/House.ts
Normal file
34
server/src/models/House.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class House extends Model {
|
||||
public id!: number;
|
||||
public name!: string;
|
||||
}
|
||||
|
||||
const nameField = "Nm_House";
|
||||
|
||||
House.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
field: "Id_House",
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(64),
|
||||
allowNull: false,
|
||||
field: nameField,
|
||||
},
|
||||
}, {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: [nameField],
|
||||
}
|
||||
],
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_House',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {House}
|
25
server/src/models/RestrictedCharacterClass.ts
Normal file
25
server/src/models/RestrictedCharacterClass.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class RestrictedCharacterClass extends Model {
|
||||
public idClass!: number;
|
||||
public idCharacter!: number;
|
||||
}
|
||||
|
||||
RestrictedCharacterClass.init({
|
||||
idClass: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Class",
|
||||
},
|
||||
idCharacter: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
field: "Id_Character",
|
||||
},
|
||||
}, {
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Character_Class',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {RestrictedCharacterClass};
|
45
server/src/models/Stat.ts
Normal file
45
server/src/models/Stat.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import {sequelize, Model, DataTypes} from "../Sequelize";
|
||||
|
||||
class Stat extends Model {
|
||||
public id!: number;
|
||||
public name!: string;
|
||||
public shortName!: string;
|
||||
}
|
||||
|
||||
const nameField = "Nm_Stat";
|
||||
const shortNameField = "Nm_Short";
|
||||
|
||||
Stat.init({
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
field: "Id_Stat",
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(16),
|
||||
allowNull: false,
|
||||
field: nameField,
|
||||
},
|
||||
shortName: {
|
||||
type: DataTypes.STRING(3),
|
||||
allowNull: false,
|
||||
field: shortNameField,
|
||||
},
|
||||
}, {
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
fields: [nameField],
|
||||
},
|
||||
{
|
||||
unique: true,
|
||||
fields: [shortNameField],
|
||||
}
|
||||
],
|
||||
timestamps: false,
|
||||
tableName: 'Tbl_Stat',
|
||||
sequelize: sequelize,
|
||||
});
|
||||
|
||||
export {Stat}
|
Reference in New Issue
Block a user