删除文件 migrations
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
Single-database configuration for Flask.
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
# A generic, single database configuration.
|
|
||||||
|
|
||||||
[alembic]
|
|
||||||
# template used to generate migration files
|
|
||||||
# file_template = %%(rev)s_%%(slug)s
|
|
||||||
|
|
||||||
# set to 'true' to run the environment during
|
|
||||||
# the 'revision' command, regardless of autogenerate
|
|
||||||
# revision_environment = false
|
|
||||||
|
|
||||||
|
|
||||||
# Logging configuration
|
|
||||||
[loggers]
|
|
||||||
keys = root,sqlalchemy,alembic,flask_migrate
|
|
||||||
|
|
||||||
[handlers]
|
|
||||||
keys = console
|
|
||||||
|
|
||||||
[formatters]
|
|
||||||
keys = generic
|
|
||||||
|
|
||||||
[logger_root]
|
|
||||||
level = WARN
|
|
||||||
handlers = console
|
|
||||||
qualname =
|
|
||||||
|
|
||||||
[logger_sqlalchemy]
|
|
||||||
level = WARN
|
|
||||||
handlers =
|
|
||||||
qualname = sqlalchemy.engine
|
|
||||||
|
|
||||||
[logger_alembic]
|
|
||||||
level = INFO
|
|
||||||
handlers =
|
|
||||||
qualname = alembic
|
|
||||||
|
|
||||||
[logger_flask_migrate]
|
|
||||||
level = INFO
|
|
||||||
handlers =
|
|
||||||
qualname = flask_migrate
|
|
||||||
|
|
||||||
[handler_console]
|
|
||||||
class = StreamHandler
|
|
||||||
args = (sys.stderr,)
|
|
||||||
level = NOTSET
|
|
||||||
formatter = generic
|
|
||||||
|
|
||||||
[formatter_generic]
|
|
||||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
||||||
datefmt = %H:%M:%S
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
import logging
|
|
||||||
from logging.config import fileConfig
|
|
||||||
|
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
from alembic import context
|
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
|
||||||
# access to the values within the .ini file in use.
|
|
||||||
config = context.config
|
|
||||||
|
|
||||||
# Interpret the config file for Python logging.
|
|
||||||
# This line sets up loggers basically.
|
|
||||||
fileConfig(config.config_file_name)
|
|
||||||
logger = logging.getLogger('alembic.env')
|
|
||||||
|
|
||||||
|
|
||||||
def get_engine():
|
|
||||||
try:
|
|
||||||
# this works with Flask-SQLAlchemy<3 and Alchemical
|
|
||||||
return current_app.extensions['migrate'].db.get_engine()
|
|
||||||
except TypeError:
|
|
||||||
# this works with Flask-SQLAlchemy>=3
|
|
||||||
return current_app.extensions['migrate'].db.engine
|
|
||||||
|
|
||||||
|
|
||||||
def get_engine_url():
|
|
||||||
try:
|
|
||||||
return get_engine().url.render_as_string(hide_password=False).replace(
|
|
||||||
'%', '%%')
|
|
||||||
except AttributeError:
|
|
||||||
return str(get_engine().url).replace('%', '%%')
|
|
||||||
|
|
||||||
|
|
||||||
# add your model's MetaData object here
|
|
||||||
# for 'autogenerate' support
|
|
||||||
# from myapp import mymodel
|
|
||||||
# target_metadata = mymodel.Base.metadata
|
|
||||||
config.set_main_option('sqlalchemy.url', get_engine_url())
|
|
||||||
target_db = current_app.extensions['migrate'].db
|
|
||||||
|
|
||||||
# other values from the config, defined by the needs of env.py,
|
|
||||||
# can be acquired:
|
|
||||||
# my_important_option = config.get_main_option("my_important_option")
|
|
||||||
# ... etc.
|
|
||||||
|
|
||||||
|
|
||||||
def get_metadata():
|
|
||||||
if hasattr(target_db, 'metadatas'):
|
|
||||||
return target_db.metadatas[None]
|
|
||||||
return target_db.metadata
|
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_offline():
|
|
||||||
"""Run migrations in 'offline' mode.
|
|
||||||
|
|
||||||
This configures the context with just a URL
|
|
||||||
and not an Engine, though an Engine is acceptable
|
|
||||||
here as well. By skipping the Engine creation
|
|
||||||
we don't even need a DBAPI to be available.
|
|
||||||
|
|
||||||
Calls to context.execute() here emit the given string to the
|
|
||||||
script output.
|
|
||||||
|
|
||||||
"""
|
|
||||||
url = config.get_main_option("sqlalchemy.url")
|
|
||||||
context.configure(
|
|
||||||
url=url, target_metadata=get_metadata(), literal_binds=True
|
|
||||||
)
|
|
||||||
|
|
||||||
with context.begin_transaction():
|
|
||||||
context.run_migrations()
|
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_online():
|
|
||||||
"""Run migrations in 'online' mode.
|
|
||||||
|
|
||||||
In this scenario we need to create an Engine
|
|
||||||
and associate a connection with the context.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
# this callback is used to prevent an auto-migration from being generated
|
|
||||||
# when there are no changes to the schema
|
|
||||||
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
|
|
||||||
def process_revision_directives(context, revision, directives):
|
|
||||||
if getattr(config.cmd_opts, 'autogenerate', False):
|
|
||||||
script = directives[0]
|
|
||||||
if script.upgrade_ops.is_empty():
|
|
||||||
directives[:] = []
|
|
||||||
logger.info('No changes in schema detected.')
|
|
||||||
|
|
||||||
connectable = get_engine()
|
|
||||||
|
|
||||||
with connectable.connect() as connection:
|
|
||||||
context.configure(
|
|
||||||
connection=connection,
|
|
||||||
target_metadata=get_metadata(),
|
|
||||||
process_revision_directives=process_revision_directives,
|
|
||||||
**current_app.extensions['migrate'].configure_args
|
|
||||||
)
|
|
||||||
|
|
||||||
with context.begin_transaction():
|
|
||||||
context.run_migrations()
|
|
||||||
|
|
||||||
|
|
||||||
if context.is_offline_mode():
|
|
||||||
run_migrations_offline()
|
|
||||||
else:
|
|
||||||
run_migrations_online()
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
"""${message}
|
|
||||||
|
|
||||||
Revision ID: ${up_revision}
|
|
||||||
Revises: ${down_revision | comma,n}
|
|
||||||
Create Date: ${create_date}
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
${imports if imports else ""}
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = ${repr(up_revision)}
|
|
||||||
down_revision = ${repr(down_revision)}
|
|
||||||
branch_labels = ${repr(branch_labels)}
|
|
||||||
depends_on = ${repr(depends_on)}
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
${upgrades if upgrades else "pass"}
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
${downgrades if downgrades else "pass"}
|
|
||||||
@@ -1,175 +0,0 @@
|
|||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: b7a6be37d1f3
|
|
||||||
Revises:
|
|
||||||
Create Date: 2023-04-06 00:18:14.996470
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from sqlalchemy.dialects import mysql
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'b7a6be37d1f3'
|
|
||||||
down_revision = None
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table('admin_admin_log',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('method', sa.String(length=10), nullable=True),
|
|
||||||
sa.Column('uid', sa.Integer(), nullable=True),
|
|
||||||
sa.Column('url', sa.String(length=255), nullable=True),
|
|
||||||
sa.Column('desc', sa.Text(), nullable=True),
|
|
||||||
sa.Column('ip', sa.String(length=255), nullable=True),
|
|
||||||
sa.Column('success', sa.Integer(), nullable=True),
|
|
||||||
sa.Column('user_agent', sa.Text(), nullable=True),
|
|
||||||
sa.Column('create_time', sa.DateTime(), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_dept',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False, comment='部门ID'),
|
|
||||||
sa.Column('parent_id', sa.Integer(), nullable=True, comment='父级编号'),
|
|
||||||
sa.Column('dept_name', sa.String(length=50), nullable=True, comment='部门名称'),
|
|
||||||
sa.Column('sort', sa.Integer(), nullable=True, comment='排序'),
|
|
||||||
sa.Column('leader', sa.String(length=50), nullable=True, comment='负责人'),
|
|
||||||
sa.Column('phone', sa.String(length=20), nullable=True, comment='联系方式'),
|
|
||||||
sa.Column('email', sa.String(length=50), nullable=True, comment='邮箱'),
|
|
||||||
sa.Column('status', sa.Integer(), nullable=True, comment='状态(1开启,0关闭)'),
|
|
||||||
sa.Column('remark', sa.Text(), nullable=True, comment='备注'),
|
|
||||||
sa.Column('address', sa.String(length=255), nullable=True, comment='详细地址'),
|
|
||||||
sa.Column('create_at', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.Column('update_at', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_dict_data',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('data_label', sa.String(length=255), nullable=True, comment='字典类型名称'),
|
|
||||||
sa.Column('data_value', sa.String(length=255), nullable=True, comment='字典类型标识'),
|
|
||||||
sa.Column('type_code', sa.String(length=255), nullable=True, comment='字典类型描述'),
|
|
||||||
sa.Column('is_default', sa.Integer(), nullable=True, comment='是否默认'),
|
|
||||||
sa.Column('enable', sa.Integer(), nullable=True, comment='是否开启'),
|
|
||||||
sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'),
|
|
||||||
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_dict_type',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('type_name', sa.String(length=255), nullable=True, comment='字典类型名称'),
|
|
||||||
sa.Column('type_code', sa.String(length=255), nullable=True, comment='字典类型标识'),
|
|
||||||
sa.Column('description', sa.String(length=255), nullable=True, comment='字典类型描述'),
|
|
||||||
sa.Column('enable', sa.Integer(), nullable=True, comment='是否开启'),
|
|
||||||
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_mail',
|
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='邮件编号'),
|
|
||||||
sa.Column('receiver', sa.String(length=1024), nullable=True, comment='收件人邮箱'),
|
|
||||||
sa.Column('subject', sa.String(length=128), nullable=True, comment='邮件主题'),
|
|
||||||
sa.Column('content', sa.Text(), nullable=True, comment='邮件正文'),
|
|
||||||
sa.Column('user_id', sa.Integer(), nullable=True, comment='发送人id'),
|
|
||||||
sa.Column('create_at', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_photo',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('name', sa.String(length=255), nullable=False),
|
|
||||||
sa.Column('href', sa.String(length=255), nullable=True),
|
|
||||||
sa.Column('mime', sa.CHAR(length=50), nullable=False),
|
|
||||||
sa.Column('size', sa.CHAR(length=30), nullable=False),
|
|
||||||
sa.Column('create_time', sa.DateTime(), nullable=True),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_power',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False, comment='权限编号'),
|
|
||||||
sa.Column('name', sa.String(length=255), nullable=True, comment='权限名称'),
|
|
||||||
sa.Column('type', sa.String(length=1), nullable=True, comment='权限类型'),
|
|
||||||
sa.Column('code', sa.String(length=30), nullable=True, comment='权限标识'),
|
|
||||||
sa.Column('url', sa.String(length=255), nullable=True, comment='权限路径'),
|
|
||||||
sa.Column('open_type', sa.String(length=10), nullable=True, comment='打开方式'),
|
|
||||||
sa.Column('parent_id', sa.Integer(), nullable=True, comment='父类编号'),
|
|
||||||
sa.Column('icon', sa.String(length=128), nullable=True, comment='图标'),
|
|
||||||
sa.Column('sort', sa.Integer(), nullable=True, comment='排序'),
|
|
||||||
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
|
|
||||||
sa.Column('enable', sa.Integer(), nullable=True, comment='是否开启'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_role',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False, comment='角色ID'),
|
|
||||||
sa.Column('name', sa.String(length=255), nullable=True, comment='角色名称'),
|
|
||||||
sa.Column('code', sa.String(length=255), nullable=True, comment='角色标识'),
|
|
||||||
sa.Column('enable', sa.Integer(), nullable=True, comment='是否启用'),
|
|
||||||
sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'),
|
|
||||||
sa.Column('details', sa.String(length=255), nullable=True, comment='详情'),
|
|
||||||
sa.Column('sort', sa.Integer(), nullable=True, comment='排序'),
|
|
||||||
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_user',
|
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='用户ID'),
|
|
||||||
sa.Column('username', sa.String(length=20), nullable=True, comment='用户名'),
|
|
||||||
sa.Column('realname', sa.String(length=20), nullable=True, comment='真实名字'),
|
|
||||||
sa.Column('avatar', sa.String(length=255), nullable=True, comment='头像'),
|
|
||||||
sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'),
|
|
||||||
sa.Column('password_hash', sa.String(length=128), nullable=True, comment='哈希密码'),
|
|
||||||
sa.Column('enable', sa.Integer(), nullable=True, comment='启用'),
|
|
||||||
sa.Column('dept_id', sa.Integer(), nullable=True, comment='部门id'),
|
|
||||||
sa.Column('create_at', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.Column('update_at', sa.DateTime(), nullable=True, comment='创建时间'),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_role_power',
|
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='标识'),
|
|
||||||
sa.Column('power_id', sa.Integer(), nullable=True, comment='用户编号'),
|
|
||||||
sa.Column('role_id', sa.Integer(), nullable=True, comment='角色编号'),
|
|
||||||
sa.ForeignKeyConstraint(['power_id'], ['admin_power.id'], ),
|
|
||||||
sa.ForeignKeyConstraint(['role_id'], ['admin_role.id'], ),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.create_table('admin_user_role',
|
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='标识'),
|
|
||||||
sa.Column('user_id', sa.Integer(), nullable=True, comment='用户编号'),
|
|
||||||
sa.Column('role_id', sa.Integer(), nullable=True, comment='角色编号'),
|
|
||||||
sa.ForeignKeyConstraint(['role_id'], ['admin_role.id'], ),
|
|
||||||
sa.ForeignKeyConstraint(['user_id'], ['admin_user.id'], ),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
with op.batch_alter_table('apscheduler_jobs', schema=None) as batch_op:
|
|
||||||
batch_op.drop_index('ix_apscheduler_jobs_next_run_time')
|
|
||||||
|
|
||||||
op.drop_table('apscheduler_jobs')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table('apscheduler_jobs',
|
|
||||||
sa.Column('id', mysql.VARCHAR(length=191), nullable=False),
|
|
||||||
sa.Column('next_run_time', mysql.DOUBLE(asdecimal=True), nullable=True),
|
|
||||||
sa.Column('job_state', sa.BLOB(), nullable=False),
|
|
||||||
sa.PrimaryKeyConstraint('id'),
|
|
||||||
mysql_default_charset='utf8mb3',
|
|
||||||
mysql_engine='InnoDB'
|
|
||||||
)
|
|
||||||
with op.batch_alter_table('apscheduler_jobs', schema=None) as batch_op:
|
|
||||||
batch_op.create_index('ix_apscheduler_jobs_next_run_time', ['next_run_time'], unique=False)
|
|
||||||
|
|
||||||
op.drop_table('admin_user_role')
|
|
||||||
op.drop_table('admin_role_power')
|
|
||||||
op.drop_table('admin_user')
|
|
||||||
op.drop_table('admin_role')
|
|
||||||
op.drop_table('admin_power')
|
|
||||||
op.drop_table('admin_photo')
|
|
||||||
op.drop_table('admin_mail')
|
|
||||||
op.drop_table('admin_dict_type')
|
|
||||||
op.drop_table('admin_dict_data')
|
|
||||||
op.drop_table('admin_dept')
|
|
||||||
op.drop_table('admin_admin_log')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
Reference in New Issue
Block a user