readme
This commit is contained in:
parent
953d9f3376
commit
a7f80d1478
|
@ -0,0 +1 @@
|
|||
.idea
|
|
@ -3,9 +3,13 @@ import os
|
|||
|
||||
class Config:
|
||||
# SECRET_KEY = os.environ.get('SECRET_KEY') or 'your_secret_key'
|
||||
# SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'postgresql://username:password@localhost:5432/yourdbname'
|
||||
# SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
SECRET_KEY = '8665e31a29ab7e12cb0f92c1dbobj1e3a6a15230fb17'
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:postgres@db:5432/mini12306_python'
|
||||
|
||||
# SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or
|
||||
# 'postgresql://username:password@localhost:5432/your dbname'
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or ('postgresql://postgres:123456@localhost:54321'
|
||||
'/mini12306_python')
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
|
|
@ -5,6 +5,9 @@ services:
|
|||
context: ./
|
||||
dockerfile: ./Dockerfile
|
||||
restart: always
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://postgres:postgres@db:5432/mini12306_python
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
ports:
|
||||
- "3002:3002"
|
||||
depends_on:
|
||||
|
|
57
readme.md
57
readme.md
|
@ -1,4 +1,53 @@
|
|||
### 创建迁移脚本
|
||||
|
||||
### 环境安装
|
||||
1. 安装python 3.12以上版本
|
||||
2. 使用 pip 安装项目所需要的包
|
||||
|
||||
```
|
||||
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple
|
||||
pip config set install.trusted-host mirrors.aliyun.com
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. 安装 postgresql并创建数据库
|
||||
|
||||
4. 执行迁移
|
||||
|
||||
```
|
||||
flask db upgrade
|
||||
```
|
||||
5. 运行项目
|
||||
|
||||
```
|
||||
flask run
|
||||
```
|
||||
也可以使用
|
||||
```
|
||||
gunicorn --bind 0.0.0.0:5000 app:app // windows环境上无法运行该指令
|
||||
```
|
||||
|
||||
### docker部署
|
||||
|
||||
1. 找一台服务器,安装docker环境
|
||||
|
||||
2. 使用镜像导入功能导入镜像,如不导入镜像则docker会自动去下载,由于国内环境问题,大多数情况都无法进行自动下载
|
||||
```
|
||||
docker load > ./docker-images/postgres_15.tar
|
||||
docker load > ./docker-images/redis_alpine.tar
|
||||
```
|
||||
3. 构建容器
|
||||
```
|
||||
docker-compose build
|
||||
```
|
||||
4. 运行容器
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Flask-Migrate 使用方法
|
||||
首先,初始化 Alembic 目录(migrations/ 文件夹):
|
||||
```
|
||||
flask db init
|
||||
|
@ -8,11 +57,15 @@ flask db init
|
|||
```
|
||||
flask db migrate -m "Initial migration"
|
||||
```
|
||||
这将根据你定义的模型生成迁移脚本。
|
||||
|
||||
执行迁移
|
||||
```
|
||||
flask db upgrade
|
||||
```
|
||||
断点调试
|
||||
---
|
||||
### 断点调试
|
||||
|
||||
```
|
||||
pdb.set_trace()
|
||||
```
|
Loading…
Reference in New Issue