Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add species migrations & seeds #30

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

zgudino
Copy link
Member

@zgudino zgudino commented Mar 29, 2018

Resolves #29.

Copy link
Member

@fdvj fdvj left a comment

Choose a reason for hiding this comment

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

Vas bien, solo un par de correcciones y faltaria el test para probar que el seed está bien.

@@ -0,0 +1,28 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

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

Los nombres solo tienen que llegar hasta minuto, no segundo. Seria 201803292038_create_species.js.

También, une las dos migraciones en una sola. No es necesario tener dos migraciones separadas.

id: {
allowNull: false,
primaryKey: true,
type: Sequelize.UUID
Copy link
Member

Choose a reason for hiding this comment

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

Agregalle defaultValue: Sequelize.UUIDV4

type: Sequelize.STRING
},
createdAt: {
defaultValue: Sequelize.fn('NOW'),
Copy link
Member

Choose a reason for hiding this comment

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

No tienes q colocar esto. Sequelize lo crea automatico. Ponlo solo asi
createdAt: Sequelize.DATE

type: Sequelize.DATE
},
updatedAt: {
defaultValue: Sequelize.fn('NOW'),
Copy link
Member

Choose a reason for hiding this comment

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

Lo mismo aqui. Esto no es necesario. Pon
updatedAt: Sequelize.DATE

name: {
unique: true,
allowNull: false,
type: Sequelize.STRING
Copy link
Member

Choose a reason for hiding this comment

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

Limita el nombre de la especie a 32 caracteres
type: Sequelize.STRING(32)

return queryInterface.bulkInsert('species', species);
},

down: (queryInterface, Sequelize) => {
Copy link
Member

Choose a reason for hiding this comment

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

Lo mismo, action en lugar de queryInterface

models/specie.js Outdated
}
);

Specie.associate = function(models) {
Copy link
Member

Choose a reason for hiding this comment

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

Elimina esto. Las asociaciones se hacen a través de una opción que le agregamos al framework:
https://github.com/adoptapanama/admin-api/blob/develop/models/role.js#L44

models/specie.js Outdated
@@ -0,0 +1,19 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
Copy link
Member

Choose a reason for hiding this comment

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

En lugar de sequelize, usa la variable db para seguir el formato:
https://github.com/adoptapanama/admin-api/blob/develop/models/role.js#L4

models/specie.js Outdated
'use strict';
module.exports = (sequelize, DataTypes) => {
const Specie = sequelize.define(
'Specie',
Copy link
Member

Choose a reason for hiding this comment

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

Sube specie a la primera linea, y luego abre el bracket como se ve aqui:
https://github.com/adoptapanama/admin-api/blob/develop/models/role.js#L5

models/specie.js Outdated
'Specie',
{
id: Sequelize.UUID,
name: Sequelize.STRING
Copy link
Member

Choose a reason for hiding this comment

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

Agregale el allowNull: false, y el defaultValue: Sequelize.UUIDV4, y el primaryKey: true

@zgudino zgudino force-pushed the develop branch 3 times, most recently from 8945c7f to a6da43e Compare April 3, 2018 13:41
@zgudino
Copy link
Member Author

zgudino commented Apr 3, 2018

@fdvj procedi a hacer los ajustes que recomendaste; muchas gracias por el review. Me falta el test.

Pending

  • Migration's functional test is missing

@zgudino zgudino force-pushed the develop branch 3 times, most recently from aee058b to 8d64dee Compare April 6, 2018 21:38
done();
});

it('should have field `createdAt` as date type', (done) => {
Copy link
Member

Choose a reason for hiding this comment

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

Este test no es necesario. Solamente el de arriba

Copy link
Member Author

Choose a reason for hiding this comment

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

Fue removido.


const { Specie } = server.models;

await Specie.bulkCreate([{ name: 'anfibio' }]); // stubbed opcional
Copy link
Member

Choose a reason for hiding this comment

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

No entiendo el proposito de estos. No son necesarios para ningun test

Copy link
Member Author

Choose a reason for hiding this comment

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

await Server.initialize(); si lo mantengo porque ya resuelve Sequelize constructor.

await Specie.bulkCreate([{ name: 'anfibio' }]); // stubbed opcional

// transformar instancia Model a JSON plano
await Specie.findAll({ limit: 10 }).then((models) => {
Copy link
Member

Choose a reason for hiding this comment

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

Igual este. Otra observación es el await con el then. La idea del await es deshacer los promises (el then). Esto no va, pero de ir, lo escribirías así:

const models = await Specie.findAll({ limit: 10 });
species = models.map((model) => model.toJSON());

Copy link
Member Author

Choose a reason for hiding this comment

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

Segui tu sugerencia. Gracias!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants