In this video, Jose Haro Peralta explains how to set up Alembic to manage migrations with SQLAlchemy. You'll also learn to add to or query data from the database using SQLAlchemy.
Chapters:
0:00 Introduction
2:54 Setting up the environment for the tutorial and installing dependencies
4:30 Initialising Alembic
5:13 Configuring Alembic
6:52 Creating a SQLAlchemy model
10:02 Creating a migration with Alembic
10:52 Running a migration with Alembic
11:15 Writing to the database using SQLAlchemy models
14:20 Reading from the database using SQLAlchemy models
14:54 Enriching SQLAlchemy models with additional propetries and methods
17:53 Wrapping up
What are SQLAlchemy and Alembic?
* SQLAlchemy is Python's most popular Object Relational Mapper (ORM). ORMs are frameworks that offer an object-oriented interface to your database tables. ORMs give you a layer of abstraction on top of SQL, so you don't have to write SQL queries by hand - instead, you just write code. ORMs also abstract away the differences between SQL engines, such as PostgreSQL and MySQL, so you can switch between one and the other without having to change your code. You can learn more about SQLAlchemy with its official documentation: [ Ссылка ].
* Alembic is a database migrations management framework. Alembic ensures that your database schemas accurately reflect the data models that you define with SQLAlchemy. You can learn more about Alembic with its official documentation: [ Ссылка ].
The code for this tutorial is available in GitHub: [ Ссылка ].
If you liked this video, please like it and share it with your network! You can also subscribe to my channel! All this goes a long way to supporting me to continue creating this kind of content.
I'm also the author of Microservice APIs with Examples in Python. It's a book dedicated to explaning how to design and build microservices and APIs, with examples in Python. If you're interested in the book, you can get a copy through this link: [ Ссылка ]. Feel free to use the following code to get a 40% discount: slperalta.
You can also download two chapters of the book for free from this link: [ Ссылка ]
ERRATA:
* In the section 7:20-7:40 I wrongly say that declarative_base() is an Alembic function. declarative_base() is a SQLALchemy function and the Base class is a SQLAlchemy class.
Ещё видео!