Git Product home page Git Product logo

docker-fastapi-demo's Introduction

docker-fastapi-demo

Fastapi 脚手架

alembic 数据库迁移

一个迁移过程基本如下:

# 1/ 初始化环境 
alembic init migrations 

# 2/ 修改alembic.ini参数
# alembic.ini 
sqlalchemy.url = mysql://root:Root1024@localhost/fastapi

# migrations/env.py
import sys 
sys.path = ['', '..'] + sys.path[1:]
from service.models import Base

...
target_metadata = Base.metadata  # 一个app model 
target_metadata = [Base.metadata, Base2.metadata]  # 多个app model

# 3/ 生成迁移脚本
alembic revision --autogenerate -m "init"

# 4/ 应用迁移脚本到数据库
alembic upgrade head 

alembic 还支持数据库的回滚、历史版本的查看等操作。更多内容,可参考:https://alembic.sqlalchemy.org/en/latest/index.html。

编译启动

docker build -t fastapi-mysql:v1.0 .

docker run -p 80:80 -d -e DB_CONNECTION="mysql://root:Root1024@xxxx/fastapi" fastapi-mysql:v1.0 ./start.sh

docker-fastapi-demo's People

Contributors

pylixm avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.