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

Tests don't pass for MySQL? #20

Closed
Trellian opened this issue Oct 26, 2017 · 2 comments
Closed

Tests don't pass for MySQL? #20

Trellian opened this issue Oct 26, 2017 · 2 comments
Labels

Comments

@Trellian
Copy link

Trellian commented Oct 26, 2017

On MySQL, the table creation does not happen successfully (because of the impossibly stupid handling of foreign keys in MySQL).

I had to modify the 'createTables' class as follows

`

  createTables() {
    const knex = this.knex;

    return knex.schema.dropTableIfExists('Person_Movie')	// changed order of dropping for MySQL
    .then(() => {
      return knex.schema.dropTableIfExists('Review');
    }).then(() => {
      return knex.schema.dropTableIfExists('Person');
    }).then(() => {
      return knex.schema.dropTableIfExists('Movie');
    }).then(() => {
      return knex.schema.createTable('Movie', (table) => {
        table.increments('id').primary().unsigned();
        table.string('name');
        table.date('release_date');
      });
    }).then(() => {
      return knex.schema.createTable('Person', (table) => {
        table.increments('id').primary().unsigned();
        table.string('firstName');
        table.string('lastName');
        table.enum('gender', _.values(models.Person.Gender));
        table.integer('age');
        table.json('addresses', true);
        table.integer('parentId')
          .unsigned()
          .nullable()
          .defaultTo(0)
//          .references('id')		/* delay creation of foreign key for mysql  */
//          .inTable('Person')
          .index();
      });
    }).then(() => {
        return knex.schema
           .raw('alter table Person add CONSTRAINT FOREIGN KEY (`parentId`) REFERENCES `Person` (`id`)');
    }).then(() => {
      return knex.schema.createTable('Review', (table) => {
        table.increments('id').primary().unsigned();
        table.string('title');
        table.integer('stars');
        table.string('text');
        table.integer('movieId')
          .unsigned()
          .nullable()
          .references('id')
          .inTable('Movie')
          .index();
        table.integer('reviewerId')
          .unsigned()
          .nullable()
          .references('id')
          .inTable('Person')
          .index();
      });
    }).then(() => {
      return knex.schema.createTable('Person_Movie', (table) => {
        table.increments('id').primary().unsigned().index();
        table.integer('movieId')
          .unsigned()
          .nullable()
          .references('id')
          .inTable('Movie')
          .index();
        table.integer('personId')
          .unsigned()
          .nullable()
          .references('id')
          .inTable('Person')
          .index();
      });
    });
  }
`
Even after this, though, there were many failures, I have attached a zip file with a log of the errors, please see attached
[test_errors.zip](https://github.com/Vincit/objection-graphql/files/1417732/test_errors.zip)

@koskimas
Copy link
Collaborator

Thanks! I'll fix this for the next release.

@koskimas koskimas added the bug label Nov 10, 2017
@Trellian
Copy link
Author

@koskimas Thanks! MySQL is notorious for it's poor foreign key handling, for many years now. And I don't understand why knex has a 'dropForeign' method, but no 'addForeign' method. Weird.

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

No branches or pull requests

2 participants