Building Data Science Applications with FastAPI by François Voron
Author:François Voron
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2021-08-26T00:00:00+00:00
Figure 6.6 â The Aerich migration environment structure
The migrations folder will contain all of the migration scripts. Notice that it creates a sub-directory for each of the "apps" defined in the configuration. As you can see, we have a first migration script that creates all the tables that have already been defined.
It also adds the aerich.ini configuration file, which essentially sets the path to your configuration variable and migrations folder.
To apply the migrations to your database, simply run the following command:
$ aerich upgrade
During the life of your project, when you have made changes to your table's schema, you'll have to generate new migration scripts to reflect the changes. This is done quite easily using the following command:
$ aerich migrate --name added_new_tables
The --name option allows you to set a name for your migration. It will automatically generate a new migration file that reflects your changes.
Aerich migration scripts are not cross-database compatible
Contrary to Alembic, Aerich doesn't abstract migration operations through cross-compatible Python scripts. Instead, it directly generates SQL files that are compatible with the engine you are working with. Since there are significant differences between the various SQL implementations, you can't work, for example, on a SQLite database during development and have a PostgreSQL for production: the migration scripts generated locally wouldn't work on your production server. This is why you should have the same database engine both in local and in production.
Just as with any automated migration system, you should always review the generated scripts to make sure they correctly reflect your changes and that you don't lose data in the process. Always test your migrations in a test environment and have fresh and working backups before running them in production.
That's it for this introduction to Tortoise ORM. If you have ever used an ORM before, you should be already confident with it. The main challenge to tackle with FastAPI is to make it work together with Pydantic models to get the benefit of both worlds. We'll now leave the world of relational databases to explore how we can work with a document-oriented database, MongoDB.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Web Development with Julia and Genie by Ivo Balbaert & Adrian Salceanu(5733)
State Management with React Query by Daniel Afonso(3222)
Eleventy by Example by Robinson Bryan;(3156)
Architecting Vue.js 3 Enterprise-Ready Web Applications by Solomon Eseme(2853)
Digital Marketing with Drupal by José Fernandes(2811)
Building Python Web APIs with FastAPI by Abdulazeez Abdulazeez Adeshina(2755)
Becoming an Enterprise Django Developer by Michael Dinder(1223)
Building Python Web APIs with FastAPI: A fast-paced guide to building high-performance, robust web APIs with very little boilerplate code by Abdulazeez Abdulazeez Adeshina(1159)
Operator Training Simulator Handbook by Joseph Philip(1129)
Practical WebAssembly: Explore the fundamentals of WebAssembly programming using Rust by Sendil Kumar Nellaiyapen(1052)
Google Workspace User Guide: A Practical Guide to Using Google Workspace Apps Efficiently While Integrating Them With Your Data by Balaji Iyer(1042)
Hands-on Cloud Analytics with Microsoft Azure Stack: Transform Your Data to Derive Powerful Insights Using Microsoft Azure by Prashila Naik(1023)
Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python by Andros Fenollosa(972)
State Management with React Query by Afonso Daniel;(939)
Modern Frontend Development with Node.js by Florian Rappl(905)
High Performance with Laravel Octane by R. Butti(894)
Kubernetes Design Patterns and Extensions by Onur Yilmaz(887)
JavaScript from Frontend to Backend by Unknown(792)
Building Data Science Applications with FastAPI by François Voron(759)
