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

Typescript support for migration files #705

Closed
VBukharov opened this issue Aug 4, 2020 · 3 comments
Closed

Typescript support for migration files #705

VBukharov opened this issue Aug 4, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@VBukharov
Copy link

Hi @B4nan

I'm trying to add mikro-orm to my project. I use it with an electron and react.

And I have a few problems with migrations. I use them programmatically.
I created a reproduction repository so you can take a look. To start application use npm run dev.

Looks like these problems are about with webpack configuration, not mikro-orm itself

  1. Typescript syntax
    It works well when migration file was written in JS only. When I use typescript then an error occurs:
    ts-error

This problem seems to be similar to this one.

First commit JS syntax is used for migration file.

Second commit TS syntax is used for migration file

  1. Webpack production mode

I think this problem is about webpack configuration but I'm stuck with it. I would really appreciate it if you could give me some advice on this)

When I use webpack with production mode it create application bundle in dist folder. When I execute npm run start script error occurs
start-error

There are no migration file at runtime and I have no idea how to add it(

Versions

Dependency Version
node v12.18.2
typescript 3.9.7
mikro-orm 3.6.15
your-driver SQLite
@VBukharov VBukharov added the bug Something isn't working label Aug 4, 2020
@B4nan
Copy link
Member

B4nan commented Aug 7, 2020

Migrations currently work only based on actual files in the migrations folder, which is not compatible with webpack. Not a webpack user myself, and I am not aware of any workaround currently.

Check out this repo, it uses different way for migrations, which should be compatible with webpack:

https://github.com/thekevinbrown/express-ts-webpack-example-app

B4nan pushed a commit that referenced this issue Aug 13, 2020
This allows using migrations with webpack. 

Related: #705
@B4nan
Copy link
Member

B4nan commented Aug 25, 2020

Latest RC of v4 supports passing list of migrations in the configuration, which is compatible with webpack:

https://mikro-orm.io/docs/next/migrations#importing-migrations-statically

@B4nan
Copy link
Member

B4nan commented Sep 3, 2020

So from what I understand, you would like to use TS migrations but execute them in the bundled code. That will never work, unless you register ts-node there, which is hardly what you want. So to your first question, use JS migrations - if you would like to have TS migrations, you will need to compile them first and adjust the migrations.pattern so it finds the JS files. Executing TS files is possible only with ts-node.

Btw I see you are using sqlite3 v5 - that version is buggy when it comes to storing dates (it will store them as strings in some nonstandard format, while v4 will store them as timestamps - so its not even possible to upgrade on existing database). I would suggest to revert it to v4.

Your second error is pretty much connected to what you are trying -- if you want to bundle everything, you need to use the migrationsList feature, as noted above. The error is caused by calling Migrator.up(), that by default searches the migrations folder for new migrations. The folder is not there. If you use migrationsList, it will skip the folder lookup and prefer the list you provide there.

Will close this now, as tbh I am a bit tired of issues where I talk to myself only...

@B4nan B4nan closed this as completed Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants