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
enhancement(database)!: add db identifier shortening and migration #19732
Conversation
Co-authored-by: Christian <christiancp100@gmail.com>
… feat/shorten-db-names
Co-authored-by: Jean-Sébastien Herbaux <Convly@users.noreply.github.com>
@@ -34,7 +34,7 @@ const createColumn = (name: string, attribute: Attribute): Column => { | |||
}; | |||
}; | |||
|
|||
const createTable = (meta: Meta): Table => { | |||
const createTable = (meta: Meta, options: MetadataOptions): Table => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid exposing & passing arround the metadata options could you store them in the metadata and expose a meta.getOptions() fn instead to keep a bit of encapsulation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or it's a matter of using another type :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did a very quick read. pretty nice 👍
Note: We definitely want to create an identifierProvider that we can init with options instead of passing the options in each function call :)
Just did some last minute QA and there are some indexes that aren't being renamed, at least on sqlite, even though the rename is called on them. If it's -only- on sqlite that's fine and we can ignore it, because they're not actually renamed anyway, but if it's mysql and postgres I would like to fix that to avoid having to recreate indexes unneccessarily. I'll look into it on Monday |
What does it do?
TODO
These will likely come in another PR before v5 release.
Why is it needed?
To finally close #13117 🥳
How to test it?
Simple version: starting with a Strapi 4 project, switch to this branch and start Strapi. The migration should run, and any of your database identifiers (table names, column names, indexes) that were longer than 55 characters will be renamed to fit into that length. Additionally, identifier parts such as "components" will have been shortened to "cmp", "order_inv_fk" to "oifk", etc.
Detailed version:
What is currently even possible to test will depend on the database being used. By default, postgres has a limit of 63 characters and mysql has a limit of 65, sqlite is unlimited.
develop
)You should also see the following changes in your database:
If you notice any identifiers in the database longer than 55 characters, or any data loss, please report details here.
Additionally, tests have already been provided in previous PRs for all the naming functions and
createMetadata
itself, covering every case we could think of comparing the full length to the expected shortened length, but since there are potentially edge cases that were missed, if you notice any please let me know.Related issue(s)/PR(s)
Let us know if this is related to any issue/pull request