Automated model registration

This commit is contained in:
Alexis
2021-07-20 22:03:20 +02:00
parent c03a5d62ec
commit 4be8a25370
17 changed files with 101 additions and 52 deletions

View File

@@ -0,0 +1,54 @@
import { DataTypes, Model, Optional } from "sequelize";
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface IngredientAttributes {
id: number
name: string
description: string
published: boolean
}
interface IngredientCreationAttributes extends Optional<IngredientAttributes, 'id'> { }
class Ingredient extends Model<IngredientAttributes, IngredientCreationAttributes> implements IngredientAttributes {
public id!: number
public name!: string
public description!: string
public published: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
Ingredient.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
published: {
type: DataTypes.BOOLEAN,
defaultValue: false
}
},
{
tableName: 'ingredient',
sequelize: AuracleDatabaseDriver,
}
)
}

View File

@@ -0,0 +1,54 @@
import { DataTypes, Model, Optional } from "sequelize";
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface MetaSchoolAttributes {
id: number
name: string
description: string
published: boolean
}
interface MetaSchoolCreationAttributes extends Optional<MetaSchoolAttributes, 'id'> { }
class MetaSchool extends Model<MetaSchoolAttributes, MetaSchoolCreationAttributes> implements MetaSchoolAttributes {
public id!: number
public name!: string
public description!: string
public published: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
MetaSchool.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
published: {
type: DataTypes.BOOLEAN,
defaultValue: false
}
},
{
tableName: 'meta-school',
sequelize: AuracleDatabaseDriver,
}
)
}

View File

@@ -0,0 +1,54 @@
import { DataTypes, Model, Optional } from "sequelize";
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface SchoolAttributes {
id: number
name: string
description: string
published: boolean
}
interface SchoolCreationAttributes extends Optional<SchoolAttributes, 'id'> { }
class School extends Model<SchoolAttributes, SchoolCreationAttributes> implements SchoolAttributes {
public id!: number
public name!: string
public description!: string
public published: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
School.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
published: {
type: DataTypes.BOOLEAN,
defaultValue: false
}
},
{
tableName: 'school',
sequelize: AuracleDatabaseDriver,
}
)
}

View File

@@ -0,0 +1,87 @@
import { DataTypes, Model, Optional } from "sequelize";
import { AuracleDatabaseDriver } from "../../AuracleDatabaseDriver";
interface SpellAttributes {
id: number
name: string
description: string
level: number
charge: number
cost: string
isRitual: boolean
published: boolean
public: boolean
}
interface SpellCreationAttributes extends Optional<SpellAttributes, 'id'> { }
class Spell extends Model<SpellAttributes, SpellCreationAttributes> implements SpellAttributes {
public id!: number
public name!: string
public description!: string
public level: number
public charge: number
public cost: string
public isRitual: boolean
public published: boolean
public public: boolean
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
export default () => {
Spell.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
level: {
type: DataTypes.INTEGER,
defaultValue: 0
},
charge: {
type: DataTypes.INTEGER,
defaultValue: 0
},
cost: {
type: DataTypes.STRING,
defaultValue: '0'
},
isRitual: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
published: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
public: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
},
{
tableName: 'spell',
sequelize: AuracleDatabaseDriver,
}
)
}