Repository navigation
feat: implement proper schema support in mysql, snowflake, add queryInterface.listDatabases - #14999
Conversation
queryInterface.listDatabases
queryInterface.listDatabasesqueryInterface.listDatabases
…elize into ephys/mysql-create-schema
queryInterface.listDatabasesqueryInterface.listDatabases
queryInterface.listDatabasesqueryInterface.listDatabases
|
I haven't really looked at the code yet, just mainly the description;
|
That is correct, and they have two ways of migrating: Option 1: Rename & move the tablesLet's say you had a table called CREATE SCHEMA `archive`;
ALTER TABLE `archive.users` RENAME TO `archive`.`users`;Option 2: Rename your modelIf you have a model that uses the schema option, like in the following example: sequelize.define('Users', {/* attributes */}, {
tableName: 'users',
schema: 'archive',
});you can continue using the old naming by changing its definition to this: sequelize.define('Users', {/* attributes */}, {
tableName: 'archive.users',
});
Because the migration is decently simple if you want to continue with the old fake schema (see option 2 above), and considering the complexity such an option would add, I don't think we should add one |
|
Ah yes, I forgot about option 2. But that's a very valid workaround and indeed does not require further backwards compatibility |
fzn0x
left a comment
There was a problem hiding this comment.
Other than that, looks good to me, many improvements on the syntax too.
WikiRik
left a comment
There was a problem hiding this comment.
Very good PR as always, nice additions as well.
I didn't have time to look into why some dialects do not have native databases support, but I also want to do that soon for my own knowledge.
I also didn't have the time yet to properly take a look at if all new functions have tests with them which I want to do in the next few days.
…elize into ephys/mysql-create-schema
WikiRik
left a comment
There was a problem hiding this comment.
Looks like all my comments have been resolved. I think we're good to go!
|
🎉 This PR is included in version 7.0.0-alpha.18 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Pull Request Checklist
yarn testoryarn test-DIALECTpass with this change (including linting)?Description Of Change
This PR blocks #14687
This PR aims to fix the way we support schemas in mysql.
Before this PR, creating a table "users" in the schema "archive" would result in a table
archive.usersbeing created in the default schema.After this PR, it would create the table
usersin the schemaarchive.I believe the source of the issue is a confusion caused by the fact that in mysql/mariadb,
CREATE SCHEMAandCREATE DATABASEare synonymous. However, the behavior of mysql's schema/database is that of a schema (as understood by the rest of our codebase and how other dialects define what a schema is), not a database.Surprisingly, our MariaDB implementation already did this correctly. All I had to (more or less) was hoist the implementation from MariaDB to MySQL, as MariaDB extends MySQL.
Other Changes
createDatabase&dropDatabase, did you know we had none?queryInterface.listDatabases(needed it for integration tests)queryGenerator.{create,drop}DatabaseQuery, as well asqueryGenerator.{create,drop}SchemaQuery,queryGenerator.listSchemasQuerycreateDatabaseQueryandcreateSchemaQuery: now throws if it receives an option that specific dialect does not support (so people don't think the option is supported just because it's listed in our types)QueryGenerator#{create,drop}Schemaare now namedQueryGenerator#{create,drop}SchemaQueryto be aligned with otherQueryGeneratormethods.showSchemasQueryrenamed tolistSchemasQueryskipoption in all implementations oflistSchemasQueryTODO
Squash Commit Message Body