Skip to content

Commit 0d03a03

Browse files
insistencegitee-org
authored andcommitted
!24 docs: 更新README文档
Merge pull request !24 from insistence/develop
2 parents 3412f22 + e334840 commit 0d03a03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1530
-823
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi-Vue-FastAPI v1.6.2</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi-Vue-FastAPI v1.7.0</h1>
55
<h4 align="center">基于RuoYi-Vue+FastAPI前后端分离的快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/RuoYi-Vue-FastAPI/stargazers"><img src="https://gitee.com/insistence2022/RuoYi-Vue-FastAPI/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/RuoYi-Vue-FastAPI"><img src="https://img.shields.io/github/stars/insistence/RuoYi-Vue-FastAPI?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/RuoYi-Vue-FastAPI"><img src="https://img.shields.io/badge/RuoYiVueFastAPI-v1.6.2-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/RuoYi-Vue-FastAPI"><img src="https://img.shields.io/badge/RuoYiVueFastAPI-v1.7.0-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/RuoYi-Vue-FastAPI/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
11+
<img src="https://img.shields.io/badge/node-≥14-blue">
1112
<img src="https://img.shields.io/badge/python-≥3.9-blue">
1213
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
1314
</p>

ruoyi-fastapi-backend/.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.6.2'
13+
APP_VERSION= '1.7.0'
1414
# 应用是否开启热重载
1515
APP_RELOAD = true
1616
# 应用是否开启IP归属区域查询

ruoyi-fastapi-backend/.env.prod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.6.2'
13+
APP_VERSION= '1.7.0'
1414
# 应用是否开启热重载
1515
APP_RELOAD = false
1616
# 应用是否开启IP归属区域查询

ruoyi-fastapi-backend/alembic.ini

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts.
5+
# this is typically a path given in POSIX (e.g. forward slashes)
6+
# format, relative to the token %(here)s which refers to the location of this
7+
# ini file
8+
script_location = %(here)s/alembic
9+
10+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
11+
# Uncomment the line below if you want the files to be prepended with date and time
12+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
13+
# for all available tokens
14+
file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
15+
16+
# sys.path path, will be prepended to sys.path if present.
17+
# defaults to the current working directory. for multiple paths, the path separator
18+
# is defined by "path_separator" below.
19+
prepend_sys_path = .
20+
21+
# timezone to use when rendering the date within the migration file
22+
# as well as the filename.
23+
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
24+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
25+
# string value is passed to ZoneInfo()
26+
# leave blank for localtime
27+
# timezone =
28+
29+
# max length of characters to apply to the "slug" field
30+
# truncate_slug_length = 40
31+
32+
# set to 'true' to run the environment during
33+
# the 'revision' command, regardless of autogenerate
34+
# revision_environment = false
35+
36+
# set to 'true' to allow .pyc and .pyo files without
37+
# a source .py file to be detected as revisions in the
38+
# versions/ directory
39+
# sourceless = false
40+
41+
# version location specification; This defaults
42+
# to <script_location>/versions. When using multiple version
43+
# directories, initial revisions must be specified with --version-path.
44+
# The path separator used here should be the separator specified by "path_separator"
45+
# below.
46+
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
47+
48+
# path_separator; This indicates what character is used to split lists of file
49+
# paths, including version_locations and prepend_sys_path within configparser
50+
# files such as alembic.ini.
51+
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
52+
# to provide os-dependent path splitting.
53+
#
54+
# Note that in order to support legacy alembic.ini files, this default does NOT
55+
# take place if path_separator is not present in alembic.ini. If this
56+
# option is omitted entirely, fallback logic is as follows:
57+
#
58+
# 1. Parsing of the version_locations option falls back to using the legacy
59+
# "version_path_separator" key, which if absent then falls back to the legacy
60+
# behavior of splitting on spaces and/or commas.
61+
# 2. Parsing of the prepend_sys_path option falls back to the legacy
62+
# behavior of splitting on spaces, commas, or colons.
63+
#
64+
# Valid values for path_separator are:
65+
#
66+
# path_separator = :
67+
# path_separator = ;
68+
# path_separator = space
69+
# path_separator = newline
70+
#
71+
# Use os.pathsep. Default configuration used for new projects.
72+
path_separator = os
73+
74+
75+
# set to 'true' to search source files recursively
76+
# in each "version_locations" directory
77+
# new in Alembic version 1.10
78+
# recursive_version_locations = false
79+
80+
# the output encoding used when revision files
81+
# are written from script.py.mako
82+
# output_encoding = utf-8
83+
84+
# database URL. This is consumed by the user-maintained env.py script only.
85+
# other means of configuring database URLs may be customized within the env.py
86+
# file.
87+
sqlalchemy.url = driver://user:pass@localhost/dbname
88+
89+
90+
[post_write_hooks]
91+
# post_write_hooks defines scripts or Python functions that are run
92+
# on newly generated revision scripts. See the documentation for further
93+
# detail and examples
94+
95+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
96+
# hooks = black
97+
# black.type = console_scripts
98+
# black.entrypoint = black
99+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
100+
101+
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
102+
# hooks = ruff
103+
# ruff.type = module
104+
# ruff.module = ruff
105+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
106+
107+
# Alternatively, use the exec runner to execute a binary found on your PATH
108+
# hooks = ruff
109+
# ruff.type = exec
110+
# ruff.executable = ruff
111+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
112+
113+
# Logging configuration. This is also consumed by the user-maintained
114+
# env.py script only.
115+
[loggers]
116+
keys = root,sqlalchemy,alembic
117+
118+
[handlers]
119+
keys = console
120+
121+
[formatters]
122+
keys = generic
123+
124+
[logger_root]
125+
level = WARNING
126+
handlers = console
127+
qualname =
128+
129+
[logger_sqlalchemy]
130+
level = WARNING
131+
handlers =
132+
qualname = sqlalchemy.engine
133+
134+
[logger_alembic]
135+
level = INFO
136+
handlers =
137+
qualname = alembic
138+
139+
[handler_console]
140+
class = StreamHandler
141+
args = (sys.stderr,)
142+
level = NOTSET
143+
formatter = generic
144+
145+
[formatter_generic]
146+
format = %(levelname)-5.5s [%(name)s] %(message)s
147+
datefmt = %H:%M:%S
148+
149+
[settings]
150+
# This section is used to set environment variables for the alembic.
151+
# The env option is used to specify the environment for the alembic.
152+
# It can be set to dev or prod.
153+
env = dev
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration with an async dbapi.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import asyncio
2+
import os
3+
from alembic import context
4+
from logging.config import fileConfig
5+
from sqlalchemy import pool
6+
from sqlalchemy.engine import Connection
7+
from sqlalchemy.ext.asyncio import async_engine_from_config
8+
from config.database import Base, ASYNC_SQLALCHEMY_DATABASE_URL
9+
from utils.import_util import ImportUtil
10+
11+
12+
# 判断vesrions目录是否存在,如果不存在则创建
13+
alembic_veresions_path = 'alembic/versions'
14+
if not os.path.exists(alembic_veresions_path):
15+
os.makedirs(alembic_veresions_path)
16+
17+
18+
# 自动查找所有模型
19+
found_models = ImportUtil.find_models(Base)
20+
21+
# this is the Alembic Config object, which provides
22+
# access to the values within the .ini file in use.
23+
alembic_config = context.config
24+
25+
# Interpret the config file for Python logging.
26+
# This line sets up loggers basically.
27+
if alembic_config.config_file_name is not None:
28+
fileConfig(alembic_config.config_file_name)
29+
30+
# add your model's MetaData object here
31+
# for 'autogenerate' support
32+
target_metadata = Base.metadata
33+
# ASYNC_SQLALCHEMY_DATABASE_URL = 'mysql+asyncmy://root:mysqlroot@127.0.0.1:3306/ruoyi-fastapi'
34+
# other values from the config, defined by the needs of env.py,
35+
alembic_config.set_main_option('sqlalchemy.url', ASYNC_SQLALCHEMY_DATABASE_URL)
36+
37+
38+
def run_migrations_offline() -> None:
39+
"""Run migrations in 'offline' mode.
40+
41+
This configures the context with just a URL
42+
and not an Engine, though an Engine is acceptable
43+
here as well. By skipping the Engine creation
44+
we don't even need a DBAPI to be available.
45+
46+
Calls to context.execute() here emit the given string to the
47+
script output.
48+
49+
"""
50+
url = alembic_config.get_main_option('sqlalchemy.url')
51+
context.configure(
52+
url=url,
53+
target_metadata=target_metadata,
54+
literal_binds=True,
55+
dialect_opts={'paramstyle': 'named'},
56+
)
57+
58+
with context.begin_transaction():
59+
context.run_migrations()
60+
61+
62+
def do_run_migrations(connection: Connection) -> None:
63+
def process_revision_directives(context, revision, directives):
64+
script = directives[0]
65+
66+
# 检查所有操作集是否为空
67+
all_empty = all(ops.is_empty() for ops in script.upgrade_ops_list)
68+
69+
if all_empty:
70+
# 如果没有实际变更,不生成迁移文件
71+
directives[:] = []
72+
print('❎️ 未检测到模型变更,不生成迁移文件')
73+
else:
74+
print('✅️ 检测到模型变更,生成迁移文件')
75+
76+
context.configure(
77+
connection=connection,
78+
target_metadata=target_metadata,
79+
compare_type=True,
80+
compare_server_default=True,
81+
transaction_per_migration=True,
82+
process_revision_directives=process_revision_directives,
83+
)
84+
85+
with context.begin_transaction():
86+
context.run_migrations()
87+
88+
89+
async def run_async_migrations() -> None:
90+
"""In this scenario we need to create an Engine
91+
and associate a connection with the context.
92+
93+
"""
94+
95+
connectable = async_engine_from_config(
96+
alembic_config.get_section(alembic_config.config_ini_section, {}),
97+
prefix='sqlalchemy.',
98+
poolclass=pool.NullPool,
99+
)
100+
101+
async with connectable.connect() as connection:
102+
await connection.run_sync(do_run_migrations)
103+
104+
await connectable.dispose()
105+
106+
107+
def run_migrations_online() -> None:
108+
"""Run migrations in 'online' mode."""
109+
110+
asyncio.run(run_async_migrations())
111+
112+
113+
if context.is_offline_mode():
114+
run_migrations_offline()
115+
else:
116+
run_migrations_online()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
${imports if imports else ""}
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = ${repr(up_revision)}
16+
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
17+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19+
20+
21+
def upgrade() -> None:
22+
"""Upgrade schema."""
23+
${upgrades if upgrades else "pass"}
24+
25+
26+
def downgrade() -> None:
27+
"""Downgrade schema."""
28+
${downgrades if downgrades else "pass"}

ruoyi-fastapi-backend/config/env.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import configparser
23
import os
34
import sys
45
from dotenv import load_dotenv
@@ -206,7 +207,15 @@ def parse_cli_args():
206207
"""
207208
解析命令行参数
208209
"""
209-
if 'uvicorn' in sys.argv[0]:
210+
# 检查是否在alembic环境中运行,如果是则跳过参数解析
211+
if 'alembic' in sys.argv[0] or any('alembic' in arg for arg in sys.argv):
212+
ini_config = configparser.ConfigParser()
213+
ini_config.read('alembic.ini', encoding='utf-8')
214+
if 'settings' in ini_config:
215+
# 获取env选项
216+
env_value = ini_config['settings'].get('env')
217+
os.environ['APP_ENV'] = env_value if env_value else 'dev'
218+
elif 'uvicorn' in sys.argv[0]:
210219
# 使用uvicorn启动时,命令行参数需要按照uvicorn的文档进行配置,无法自定义参数
211220
pass
212221
else:

ruoyi-fastapi-backend/config/get_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def init_create_table():
1818
1919
:return:
2020
"""
21-
logger.info('初始化数据库连接...')
21+
logger.info('🔎 初始化数据库连接...')
2222
async with async_engine.begin() as conn:
2323
await conn.run_sync(Base.metadata.create_all)
24-
logger.info('数据库连接成功')
24+
logger.info('✅️ 数据库连接成功')

0 commit comments

Comments
 (0)