This commit is contained in:
DeGssoft 2022-12-12 00:52:43 -03:00
Родитель 9dc381013b
Коммит d244177a8d
6 изменённых файлов: 77 добавлений и 7 удалений

Просмотреть файл

@ -156,4 +156,4 @@ User.destroy(
## Homework
Completa la tarea descrita en el archivo [README](https://github.com/soyHenry/FT-M4/tree/master/03-sequelize/homework)
Completa la tarea descrita en el archivo [README](../03-sequelize/homework/README.md)

Просмотреть файл

@ -3,7 +3,11 @@ const modelCharacter = require('./models/Character.js');
const modelAbility = require('./models/Ability.js');
const modelRole = require('./models/Role.js');
const db = new Sequelize('postgres://franco:12345@localhost:5432/henry_sequelize', {
const user = "postgres";
const password = "P@ssw0rd";
const host = "localhost";
const port = "5432";
const db = new Sequelize(`postgres://${user}:${password}@${host}:${port}/henry_sequelize`, {
logging: false,
});

Просмотреть файл

@ -2,6 +2,21 @@ const { DataTypes } = require('sequelize');
module.exports = sequelize => {
sequelize.define('Ability', {
})
name: {
type: Sequelize.STRING,
allowNull: false
},
description: {
type: Sequelize.TEXT
},
manaCost: {
type: Sequelize.FLOAT,
allowNull: false
}
}, {
indexes: [{
unique: true,
fields: ['name', 'manaCost']
}]
});
}

Просмотреть файл

@ -2,6 +2,37 @@ const { DataTypes } = require('sequelize');
module.exports = sequelize => {
sequelize.define('Character', {
code: {
type: Sequelize.STRING(5),
primaryKey: true,
allowNull: false
},
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false
},
age: {
type: Sequelize.INTEGER
},
race: {
type: Sequelize.ENUM,
values: ['Human', 'Elf', 'Machine', 'Demon', 'Animal', 'Other'],
defaultValue: 'Other',
},
hp: {
type: Sequelize.FLOAT,
allowNull: false
},
mana: {
type: Sequelize.FLOAT,
allowNull: false
},
dateAdded: {
type: Sequelize.DATEONLY
}
}, {
timestamps: false
});
})
}

Просмотреть файл

@ -2,6 +2,13 @@ const { DataTypes } = require('sequelize');
module.exports = sequelize => {
sequelize.define('Role', {
})
name: {
type: Sequelize.STRING,
allowNull: false,
unique: true
},
description: {
type: Sequelize.STRING
}
});
}

Просмотреть файл

@ -0,0 +1,13 @@
version: '3.8'
services:
postgres:
image: 'postgres:15'
restart: always
volumes:
- './postgres_data:/var/lib/postgresql/data'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: P@ssw0rd
POSTGRES_DB: henry_sequelize
ports:
- '5432:5432'