Repository navigation
Find database migrations dir in typescript project - #18010
DevDengChao wants to merge 24 commits into
Conversation
Signed-off-by: DevDengChao <2325690622@qq.com>
Signed-off-by: DevDengChao <2325690622@qq.com>
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
Related to #17960 |
|
I'll mention it to the team on Monday |
innerdvations
left a comment
There was a problem hiding this comment.
By the way, I currently have another PR where I fix an issue with the dialect initialization.
I'll have to think about how to reconcile how that works with this one but it shouldn't be very complex.
Signed-off-by: DevDengChao <2325690622@qq.com>
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
| static async init(config: DatabaseConfig) { | ||
| const db = new Database(config); | ||
| await db.setup(); | ||
| await validateDatabase(db); | ||
| return db; | ||
| } |
There was a problem hiding this comment.
@innerdvations If we can not use an async constructor, then we need to setup the db asynchronously, which causes the entityManager to be decleared nullable, while the entityManager is used widely in the project, and brings more things need to be updated.
There was a problem hiding this comment.
The root cause is that is-using-typescript checks tsconfig.json asynchronously:
module.exports = (dir, filename = undefined) => {
const filePath = getConfigPath(dir, { filename });
return fse.pathExists(filePath); // Promise<boolean>
};Any idea about replace pathExists with pathExistsSync ?
There was a problem hiding this comment.
Making path synchronous is a workaround I'd rather avoid. If we can make it work "properly" with everything relying on an async action happening in/after the setup, that would be best. We can keep everything that works synchronously in the constructor, and then move everything after that to the async setup method and await it in init (basically what you've done already)
I will try to give this PR some closer attention this week :)
Signed-off-by: DevDengChao <2325690622@qq.com>
| @@ -1,5 +1,5 @@ | |||
| // eslint-disable-next-line no-var | |||
| declare var strapi: any; | |||
| declare var strapi: any & { dirs: { app: { root } } }; | |||
There was a problem hiding this comment.
This should be defined in the strapi typings
There was a problem hiding this comment.
May I ask for help?
The @strapi/database package dose not depend on @strapi/types, so I cannot import { Strapi } from '@strapi/types/src';.
Even I can add @strapi/types to @strapi/database's devDependencies, it causes a circular dependencies.
So what should I do ?
There was a problem hiding this comment.
Or maybe someone could update the strapi defined in global.d.ts first so I could follow it.
There was a problem hiding this comment.
Sorry, I didn't pay enough attention before to realize what was happening. If this is already defined as 'any' why do we need to add anything to it? Shouldn't it work without changing anything here?
There was a problem hiding this comment.
It works without this change, I added it for better DX when writing unit tests..
Then should we keep it or remove it ?
Signed-off-by: DevDengChao <2325690622@qq.com>
|
Changing those db properties to optional will be a breaking change for typescript, so we'll have to do it in a bit of a hacky way for Strapi v4 and then do it better in v5. I am working on a new PR to address that specifically and will credit you for your work on the issue, and then once that's merged, the TS migrations issue can be done in a much simpler PR. |
Based on #18010 by @DevDengChao Co-authored-by: DevDengChao <2325690622@qq.com>
|
@innerdvations Good to hear that. Subscribing the other PR now. |
a7ef509 to
ce84fad
Compare
|
Important With the release of Strapi 5, we have lifted the code freeze. To ensure we can effectively review and assist with contributions, we are now only accepting PRs targeting version 5 (the develop branch). |
|
@alexandrebodin Hi, I created another PR here #21374 , do you have time review it ? |
|
This was fast thank you ! I'll assign someone We are aiming to review everything in the next month 🙏 |
What does it do?
Recongnize /dist/database/migrations in ts project
Why is it needed?
#17820
How to test it?
Related issue(s)/PR(s)
#17820