Тёмный

Sequelize Migration 

Ben Awad
Подписаться 496 тыс.
Просмотров 34 тыс.
50% 1

Learn how to migrate your database with Sequelize. I will be using a Node.js server and PostgreSQL database in this example.
----
Video Suggestions:
Trello: trello.com/b/mErpLVj7/todo
Join the Trello board: trello.com/invite/b/mErpLVj7/...
----
Follow Me Online Here:
GitHub: github.com/benawad
Instagram: / benawad97
Patreon: / benawad
----
Join the Discord: / discord
Twitter: / benawad
#benawad
TikTok: / benawad ​

----
Follow me online: voidpet.com/benawad
#benawad

Наука

Опубликовано:

 

20 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 36   
@coherentpanda7115
@coherentpanda7115 4 года назад
This is an oldie, but it sure helped me a ton just now! Migrations sounded like a big and scary word, but really with Sequelize and a little bit of knowledge it's really quite easy to do without fear of deleting my data. Thanks Ben
@jeyko666
@jeyko666 6 лет назад
It's like every issue I face you have a video to cover it, you are the best teacher ever!
@syahirahnordin6140
@syahirahnordin6140 4 года назад
Thank you. this have been so much help to me!
@ThomasWSmith-wm5xn
@ThomasWSmith-wm5xn 4 года назад
13.5 add "async" before the parenthesis : async (queryInterface, Sequelize) => {}
@olehbaranovskyi2219
@olehbaranovskyi2219 3 года назад
Thanks, really helpful tutorials
@maksymdudyk1718
@maksymdudyk1718 2 года назад
Thank you, Ben.
@saranshmehra1538
@saranshmehra1538 3 года назад
Thank you brother 💓
@farzanr.nobakht3022
@farzanr.nobakht3022 5 лет назад
It was helpful!
@smartliga8623
@smartliga8623 5 лет назад
That's how your safe config.JS has to look like for migration: p.s CLI works with .js files and .json. To work with env.vars you have to use .js. Also note - we have to npm install dotenv package require('dotenv').config(); module.exports = { dev: { username: process.env.DB_USER, password: process.env.DB_PASS, database: process.env.DB_NAME, host: process.env.DB_HOST, dialect: 'mysql' }, "production": { "username": process.env.DB_USER, "password": process.env.DB_PASS, "database": process.env.DB_NAME, "host": process.env.DB_HOST, "dialect": "mysql" } }
@uzair004
@uzair004 2 года назад
I was confused why we need migration and how to use it. after watching this video, Thankfully I am even more confused :D
@zephyrprime
@zephyrprime 3 года назад
What is the command interpreter environment you are running this in?
@mohdaatif6241
@mohdaatif6241 5 лет назад
Thanks
@ThomasWSmith-wm5xn
@ThomasWSmith-wm5xn 4 года назад
New drinking game: take a shot everytime you here an american say "actually" in an online tutorial video. Dont die.
@adhamel-deeb3974
@adhamel-deeb3974 4 года назад
sequelize db:migrate:undo 💁
@Joseph-if6nh
@Joseph-if6nh 4 года назад
In a migration, is it possible to update a column based on a column in another table? I want to use bulkUpdate to updated with a join condition but am unsure how
@bawad
@bawad 4 года назад
Yeah search this on stack overflow there's some posts on it
@willcalltickets
@willcalltickets 6 лет назад
Am I correct in thinking that if you have auto-save setup on your editor, and are running the app via "yarn start", then you could make a mess of what you are trying to achieve. The database will be re-tooled via the sync command and will get rid of all that data before you have the chance to run the migration - and the migration will also fail. 2 options 1) Always make sure you are not running your app while doing migrations (too much room for error) 2) disable the sync in the index.js and rely soley on implementing migrations for db changes as a best practice re #2, would I just remove the first line from the following and just start from server.listen()? I am referring to this statement in index.js models.sequelize.sync({ force: false }).then(() => { server.listen(PORT, () => { new SubscriptionServer( ... ...
@bawad
@bawad 6 лет назад
+Rob Kurtz if you get rid of force: true then the sync command will not overwrite any data. You don't have to worry about it
@willcalltickets
@willcalltickets 6 лет назад
+Ben Awad per docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#instance-method-sync "Sync all defined models to the DB" By using force: true, it will drop tables if they exist. But if force: false, won't it still try to update the db per our local model?
@bawad
@bawad 6 лет назад
+Rob Kurtz it will update the db to the model if the table does not exist. If it already exist, nothing changes. So the migration will not get messed up because you will only be migrating tables that exist
@willcalltickets
@willcalltickets 6 лет назад
+Ben Awad got it - thank you for the clarification
@4ware
@4ware 6 лет назад
How do i implement associations when using migrations?
@bawad
@bawad 6 лет назад
+Kai Wernicke there is an addConstraint method for queryInterface and you can add foreign keys
@andresmontoya7852
@andresmontoya7852 6 лет назад
Why is necessary to use sequelize migrations?
@bawad
@bawad 6 лет назад
migrations are useful when you want to make changes to a database you have in production and you want to make sure not to lose/corrupt data
@andresmontoya7852
@andresmontoya7852 6 лет назад
Thank you!
@seoparse
@seoparse 4 года назад
It is not necessary, but: 1) You can copy-paste your previous actions with exact definitions (type, nullable, default), it is useful sometimes, just grab it from previous migration and change what you need. 2) You have a self-descriptive log of your actions on the database schema + VCS info. 3) You can create test database by another entry in configuration and populate it with your schema. 4) You can apply migration to multiple databases by one command, if you need. 5) You can migrate from one RDBMS to another with less pain.
@k4rc1nogen57
@k4rc1nogen57 5 лет назад
Hey what terminal is that?
@bawad
@bawad 5 лет назад
iterm2 with gruvbox
@k4rc1nogen57
@k4rc1nogen57 5 лет назад
Thanks! Sadly it's Apple only :(
@bawad
@bawad 5 лет назад
yeah :(
@mrthatham6928
@mrthatham6928 6 лет назад
Have you uploaded this code your github repository?
@bawad
@bawad 6 лет назад
+venkatesh thatham I don't think I did, I can check and see if I still have it. Do you want to see it?
@mrthatham6928
@mrthatham6928 6 лет назад
Ben Awad I'll be thankful if it's possible. Because, I'm quite new to MEAN Stack development
@bawad
@bawad 6 лет назад
Here you go, I forgot to link it: github.com/benawad/graphql-express-template/tree/30_sequelize_migrations
@mrthatham6928
@mrthatham6928 6 лет назад
Ben Awad Thank you very much. It's very helpful
Далее
Creating PostgreSQL Database Models with Sequelize
23:18
Parents' Breakfast Rescue Mission for Laptops
00:28
Каха бизнес-класс
00:48
Просмотров 1,1 млн
Microservices with Databases can be challenging...
20:52
I've been using Redis wrong this whole time...
20:53
Просмотров 339 тыс.
The Story of Next.js
12:13
Просмотров 555 тыс.
Sequelize ORM Tutorial (all in one video)
49:59
Просмотров 160 тыс.
Why aren't you using Fastify? Or Koa? Or NestJS?
9:58
I tried 8 different Postgres ORMs
9:46
Просмотров 393 тыс.
We Don't Need Migrations Anymore
6:21
Просмотров 58 тыс.
ЗАКОПАЛ НОВЫЙ ТЕЛЕФОН!!!🎁😱
0:28