Skip to content

support create / drop database with query interface #8821

Closed

Description

@matheusvellone

What are you doing?

I'm trying to create a new schema with mysql using migrations

module.exports = {
  up(queryInterface) {
    return queryInterface.createSchema('admin')
  },
  down(queryInterface) {
    return queryInterface.dropSchema('admin')
  },
}

What do you expect to happen?

The schema to be created

What is actually happening?

Schema not being created 😢

Aditional info

Did a little research to understand what's happening and found this line https://github.com/sequelize/sequelize/blob/master/lib/dialects/mysql/query-generator.js#L19, which returns the SHOW TABLES SQL instead of a CREATE DATABASE

As a workaround, I could change the queryInterface.createSchema with queryInterface.sequelize.query and put my CREATE DATABASE query, which gives me exactly what I need. Just reporting a broken functionality (i guess it's broken)

If you need more info about it, just let me know :)

EDIT: Just to avoid confusion

CREATE DATABASE creates a database with the given name. To use this statement, you need the CREATE privilege for the database. CREATE SCHEMA is a synonym for CREATE DATABASE.

https://dev.mysql.com/doc/refman/5.7/en/create-database.html

Dialect: mysql
Dialect version: 1.5.0
Database version: 8.0.3-rc-log
Sequelize version: 4.28.6
Tested with latest release: Yes, versions above

Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.

Activity

  1. matheusvellone commented on Dec 29, 2017

    @matheusvellone
    Author

    Found this issue #1379 which reported the same problem.

    Despite being a massive breaking change, I didn't fully got why not to support multiple schemas through prefixes.
    In my case the prefixes would not only solve this createSchema problem, but also all my multi-tenant queries, which I would be able to just prefix the table with any schema in my database.

    I'm open to provide more details/use cases if you need or want to.
    Also, I can try contributing with some PRs to help with these changes.

  2. added
    type: feature
    on Jan 11, 2018
  3. sushantdhiman commented on Jan 11, 2018

    @sushantdhiman
    Contributor

    Schema and batabase are different concept, they may be interchangeable in MySQL but are very different for other databases.

    What you are looking for is createDatabase / dropDatabase statement which I am afraid we dont support yet. But I will be happy to accept an PR which add create/drop database support to query interface

  4. changed the title [-]createSchema with MySQL not working[/-] [+]support create / drop database with query interface[/+] on Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions