16 How to run or setup migrations in Nest JS with TypeORM

  Рет қаралды 26,943

Amitav Roy

Amitav Roy

Күн бұрын

Пікірлер: 68
@sandeepkumar44
@sandeepkumar44 2 жыл бұрын
The only tutorial I found which uses entity to create migrations flawlessly
@googleaccount1338
@googleaccount1338 2 жыл бұрын
Is this a current solution? The documentation mentions creation via DataSource.
@matkoklaic
@matkoklaic 2 жыл бұрын
You are right, this is not a current solution.
@amitavroydev
@amitavroydev Жыл бұрын
For the latest version look at the recent video that I have posted. In the new version of TypeORM where datasource is introduced, things have changed and I have captured that. kzbin.info/www/bejne/iqrCi6ZorJh-j9E
@jhvhest
@jhvhest 2 жыл бұрын
Your video is the first one that really helped in getting migrations to work. Thnx!
@amitavroydev
@amitavroydev 2 жыл бұрын
Thanks for the comment and good to know that it helped
@adenaziz3600
@adenaziz3600 2 жыл бұрын
i've got error on typeorm.config.ts, it's said "Object literal may only specify known properties, and 'cli' does not exist"
@adenaziz3600
@adenaziz3600 2 жыл бұрын
i've solved it. You are using version 0.2.45 while i'm using the latest version, so i have to downgrade first.
@labaks4844
@labaks4844 2 жыл бұрын
@@adenaziz3600 what are downgrading? typeorm? UPDATE: downgraded as you mentioned and the error was gone.! thanks!!
@amitavroydev
@amitavroydev Жыл бұрын
Yes the version thing is very important
@nehagadhavi5754
@nehagadhavi5754 Жыл бұрын
migrations: [__dirname + '/../database/migrations/*{.ts,.js}'], migrationsRun: true, migrationsTableName: 'typeorm_migrations', charset: 'utf8mb4_unicode_ci', update with these changes
@tarunnagia6327
@tarunnagia6327 2 жыл бұрын
Hi, I'm getting error in related to cli with latest version, what should I do?
@amitavroydev
@amitavroydev 2 жыл бұрын
Yes, there are major changes in TypeORM
@eduardokiriakos6255
@eduardokiriakos6255 2 жыл бұрын
@@amitavroydev I have had a headache for three days due to these changes! There is still very little info about dataSources
@amitavroydev
@amitavroydev 2 жыл бұрын
Yeah, I tried as well but the docs are not very clear. I am not able to upgrade the orm version. And it breaks at a point saying it's looking for a db driver which i am not even using
@eduardokiriakos6255
@eduardokiriakos6255 2 жыл бұрын
@@amitavroydev I found a useful tutorial about this! It's in Spanish but it has link to the Github Repo. kzbin.info/www/bejne/m2eug3mIZ7Clopo -- the part two shows how to setup migrations using the dataSource!
@sarunmrzn
@sarunmrzn 2 жыл бұрын
@@amitavroydev any update on this?
@mdtowhidulislam5260
@mdtowhidulislam5260 2 жыл бұрын
cli: { migrationDir: __dirname + '/../migrations', }, this part is not working on 09:01 ...can someone tell me how to solve this??? and maybe for this reason I am getting an error - Missing required argument: dataSource when run the command npm run typeorm:cli migration:show
@amitavroydev
@amitavroydev 2 жыл бұрын
can you check if the typeorm version is matching your pckage.json version? I know in recent version things have changed a bit
@mdtowhidulislam5260
@mdtowhidulislam5260 2 жыл бұрын
@@amitavroydev my typeorm version is 0.3.10
@antonpavlovich4880
@antonpavlovich4880 2 жыл бұрын
@@mdtowhidulislam5260 you need to pass file with exported dataSource object
@antonpavlovich4880
@antonpavlovich4880 2 жыл бұрын
​@@mdtowhidulislam5260 with 0.3.10 typeorm version we don`t need to pass this CLI object, all we have to do is pass two argument: 1 -d (path to file with exported dataSource object) 2 -n (path to migration dir included the name of migration without extension)
@yohanespradono5224
@yohanespradono5224 Жыл бұрын
i have set "synchronize": false in ormconfig.json but nestjs keeps creating/syncing the table schema
@amitavroydev
@amitavroydev Жыл бұрын
May be it's not using the JSON file. Can you do it inside the Module's config?
@raneanish21
@raneanish21 2 жыл бұрын
cli in migrations is deprecated is there any other way to include cli property? in typeormmoduleoptions?
@amitavroydev
@amitavroydev 2 жыл бұрын
Yes Anish, I have seen that. I need to try that out. I haven't done that yet. My team also haven't explored that.
@SantoshKumar-uw5cg
@SantoshKumar-uw5cg Жыл бұрын
I am getting 'Missing required argument: dataSource' on npm run typeorm:cli migration:show
@amitavroydev
@amitavroydev Жыл бұрын
Will check
@SantoshKumar-uw5cg
@SantoshKumar-uw5cg Жыл бұрын
@@amitavroydev FYI I am trying to implement migrations in nestjs microservices app with a multi-tenant architecture
@labaks4844
@labaks4844 2 жыл бұрын
did anyone get this error?? "No repository for "UserRepository" was found. Looks like this entity is not registered in current "default" connection?"
@amitavroydev
@amitavroydev 2 жыл бұрын
That's a strange error. Is your basic DB connection working?
@muhammadsadiq3653
@muhammadsadiq3653 2 жыл бұрын
@Labaks, when you're getting this is mostly because you haven't added your entity or repository to it's module
@Brunodelucasdev
@Brunodelucasdev 2 жыл бұрын
After run migration i receive "Error during migration generation:" and stack of errors! why solve this?
@amitavroydev
@amitavroydev 2 жыл бұрын
What's the issue? It must be failing complaining about something. Without knowing that, it's very difficult to say that could be the problem.
@muhammadsadiq3653
@muhammadsadiq3653 2 жыл бұрын
Has anyone figured out yet how to migrate using typeorm 0.3.x basically everything I'm doing isn't working
@ravenpl7366
@ravenpl7366 2 жыл бұрын
i have spent last 2 days looking for solution but didnt find it. Every tutorial, info is for
@amitavroydev
@amitavroydev 2 жыл бұрын
Believe me, I tried twice but still couldn’t get everything to work smoothly
@svetoslavhristov789
@svetoslavhristov789 2 жыл бұрын
kzbin.info/www/bejne/raCwgaFpg9Jml6M solution
@muhammadsadiq3653
@muhammadsadiq3653 2 жыл бұрын
Tried running "typeorm:cli" but i'm getting "Error: Unknown or unexpected option: -f". I believe the -f flag means this "src/config/typeorm-migrations.config.ts" is a file, don't get why it isn't working
@amitavroydev
@amitavroydev Жыл бұрын
Have you executed typeorm:config?
@nealfarrand1246
@nealfarrand1246 2 жыл бұрын
Amazing. Thank you so much for this updated tutorial that works.
@amitavroydev
@amitavroydev 2 жыл бұрын
Thanks for the comment Good to know you found it useful
@gillesashley9314
@gillesashley9314 2 жыл бұрын
Yes, I agree, I'm coming from a Laravel background and migration is a first-class citizen as your said, super easy. My question is, why can't the nest team make migration a first-class citizen like Laravel. I tried leaning nest but couldn't cope with the migration and seeding configurations. Had to continue using Laravel.
@amitavroydev
@amitavroydev 2 жыл бұрын
Well, it's difficult to say but I think because Nest support so many ORMs, this problem exist. Every ORM has a different configuration. Like for mongo you need mongoose, but for relational you need to use typeorm or prisma. Laravel on the other hand has it's own ORM which is a big advantage. So, they are able to support multiple databases without changing the ORM.
@Андрюхаслазерки
@Андрюхаслазерки 2 жыл бұрын
Nice, very nice video. Thank you very much!!!!!
@amitavroydev
@amitavroydev 2 жыл бұрын
Good to know you liked it. Cheers
@ashiqdey
@ashiqdey 2 жыл бұрын
teaching is good, but I am wondering why you code in light mode, doesnt it hurt eyes?
@amitavroydev
@amitavroydev 2 жыл бұрын
No, actually it never hurts. On the contrary I try to be on light mode because the shift from Dark mode to light mode when working on web apps is a nightmare. You are developing an app / client project which is not following a dark theme - then suddenly your code editor is dark and the browser it white. That suddent and drastic shift in color is actually irritating.
@markzabana
@markzabana 2 жыл бұрын
I tried to use this concept in my project but it isn't working. In 'typeOrmConfig' can't get any value from process.env like you do. How can I do ?
@amitavroydev
@amitavroydev 2 жыл бұрын
That's strange because process.env is something which is available by default. You are facing issue during development or only on production?
@abolfazlroshanzamir1322
@abolfazlroshanzamir1322 2 жыл бұрын
Hi, your teaching is great. Where can I download the source of your project?
@amitavroydev
@amitavroydev 2 жыл бұрын
Here github.com/amitavdevzone/nest-js-quiz-manager
@tuanvominh3219
@tuanvominh3219 2 жыл бұрын
Thank you so much. 😁😁😁
@amitavroydev
@amitavroydev 2 жыл бұрын
Welcome
@KhoiNguyen-pm2jg
@KhoiNguyen-pm2jg 2 жыл бұрын
TS2322: Type '{ type: "mysql"; url: string; entities: string[]; migrations: string[]; cli: { migrationsDir: string; }; extra: { charset: string; }; synchronize: true; autoLoadEntities: true; logging: boolean; }' is not assignable to type 'TypeOrmModuleOptions'. Object literal may only specify known properties, and 'cli' does not exist in type '{ retryAttempts?: number; retryDelay?: number; toRetry?: (err: any) => boolean; autoLoadEntities?: boolean; keepConnectionAlive?: boolean; verboseRetryLog?: boolean; } & Partial'. I get an type error in typeorm.config.ts. Can you help me?
@amitavroydev
@amitavroydev 2 жыл бұрын
When exactly is this problem coming?
@KhoiNguyen-pm2jg
@KhoiNguyen-pm2jg 2 жыл бұрын
@@amitavroydev at 8:34, when i copy your code, i get that error
@KhoiNguyen-pm2jg
@KhoiNguyen-pm2jg 2 жыл бұрын
@@amitavroydev i'm using typeorm version 0.3.7
@KhoiNguyen-pm2jg
@KhoiNguyen-pm2jg 2 жыл бұрын
@@amitavroydev hey bro, can you help me :((
@anirudhhosur3827
@anirudhhosur3827 6 күн бұрын
All your videos were awesome until now :/ I watched this video 2-3 times (the starting half). I still am getting confused as to different config files with ConfigAsync and ConfigAsyncOptions, etc. Its confusing now! I have understood why migrations are important. Thanks for the intro.
@amitavroydev
@amitavroydev 6 күн бұрын
The two configs were required because the way typeorm is available on the cli. So i had to create two different configs. One for cli and the other for normal. In the new version though things have changed
@jackfrost8969
@jackfrost8969 Жыл бұрын
so now you magically switched from postgres to mysql
@amitavroydev
@amitavroydev Жыл бұрын
It's an ORM, so not much change in the logic honestly.
@jackfrost8969
@jackfrost8969 Жыл бұрын
@@amitavroydev then why did you switched them? There is not much issues apart from one where I can't disable the foreign check constraint before truncating the table used while preparing for seed data. SET foreign_key_checks = 0 this only works in mysql, for postgres I have still not found any working solution for it. I have tried changing the replication role, disabling the triggers to no avail.
@rudeadyet1992
@rudeadyet1992 Жыл бұрын
this tuto is too old my friend. typeorm >=0.3 need datasource for migration
@amitavroydev
@amitavroydev Жыл бұрын
Yes you are right about this. The video is almost a year old. At that time, Typeorm was on 0.2.x And now, the latest one is 0.3.x
@rudeadyet1992
@rudeadyet1992 Жыл бұрын
@@amitavroydev Appreciate your reply, thanks! :)
TypeORM v0.3.x Migrations, queries, with NestJS!
28:37
Marius Espejo
Рет қаралды 38 М.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
Learn Nest.js from Scratch by building an API
1:09:06
Academind
Рет қаралды 547 М.
TypeORM Relations Tutorial - FULL details!
49:02
Marius Espejo
Рет қаралды 92 М.
The New Outlook is TERRIBLE
20:19
Chris Titus Tech
Рет қаралды 117 М.
Google’s Quantum Chip: Did We Just Tap Into Parallel Universes?
9:34
NestJS + TypeORM Tutorial | Repositories, Relations, Migrations & More
1:06:30
Nest.js | Middleware, Pipes & Interceptors Explained By Example
33:39
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН