增加数据字典

This commit is contained in:
mkg
2021-04-16 14:08:13 +08:00
parent a709095dc2
commit 2f0df0a700
24 changed files with 1284 additions and 431 deletions
-1
View File
@@ -1 +0,0 @@
Generic single-database configuration.
-45
View File
@@ -1,45 +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
[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
[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
-96
View File
@@ -1,96 +0,0 @@
from __future__ import with_statement
import logging
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
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')
# 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',
str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata
# 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 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=target_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 = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_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()
-24
View File
@@ -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"}
-28
View File
@@ -1,28 +0,0 @@
"""empty message
Revision ID: 58fc2c4c30a5
Revises: 715a8ecc5856
Create Date: 2021-03-19 21:31:06.761526
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '58fc2c4c30a5'
down_revision = '715a8ecc5856'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_role', sa.Column('enable', sa.Integer(), nullable=True, comment='是否启用'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('admin_role', 'enable')
# ### end Alembic commands ###
-28
View File
@@ -1,28 +0,0 @@
"""empty message
Revision ID: 64de3323bc01
Revises: 95b59a101b26
Create Date: 2021-03-18 20:54:17.724297
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '64de3323bc01'
down_revision = '95b59a101b26'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_user', sa.Column('realname', sa.String(length=20), nullable=True, comment='真实名字'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('admin_user', 'realname')
# ### end Alembic commands ###
-28
View File
@@ -1,28 +0,0 @@
"""empty message
Revision ID: 715a8ecc5856
Revises: 64de3323bc01
Create Date: 2021-03-19 21:30:52.200812
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '715a8ecc5856'
down_revision = '64de3323bc01'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('admin_role', 'enable')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_role', sa.Column('enable', mysql.CHAR(collation='utf8_unicode_ci', length=1), nullable=True, comment='是否启用'))
# ### end Alembic commands ###
-28
View File
@@ -1,28 +0,0 @@
"""empty message
Revision ID: 816f66c2def4
Revises: ce8825111f8f
Create Date: 2021-03-14 22:57:37.092157
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '816f66c2def4'
down_revision = 'ce8825111f8f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_admin_log', sa.Column('success', sa.Integer(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('admin_admin_log', 'success')
# ### end Alembic commands ###
-28
View File
@@ -1,28 +0,0 @@
"""empty message
Revision ID: 85fcf9a09800
Revises: e187b65f7f1b
Create Date: 2021-04-01 21:03:40.387739
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '85fcf9a09800'
down_revision = 'e187b65f7f1b'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_user', sa.Column('avatar', sa.String(length=255), nullable=True, comment='头像'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('admin_user', 'avatar')
# ### end Alembic commands ###
-30
View File
@@ -1,30 +0,0 @@
"""empty message
Revision ID: 95b59a101b26
Revises: 816f66c2def4
Create Date: 2021-03-17 22:28:41.595865
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '95b59a101b26'
down_revision = '816f66c2def4'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_user', sa.Column('enable', sa.Integer(), nullable=True, comment='启用'))
op.drop_column('admin_user', 'status')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_user', sa.Column('status', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True, comment='启用'))
op.drop_column('admin_user', 'enable')
# ### end Alembic commands ###
@@ -1,8 +1,8 @@
"""empty message
Revision ID: 59add0790978
Revision ID: 9a591b224cc7
Revises:
Create Date: 2021-03-11 22:39:09.829159
Create Date: 2021-04-16 10:13:27.930524
"""
from alembic import op
@@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '59add0790978'
revision = '9a591b224cc7'
down_revision = None
branch_labels = None
depends_on = None
@@ -25,10 +25,33 @@ def upgrade():
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_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_photo',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
@@ -45,7 +68,7 @@ def upgrade():
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.String(length=19), 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='创建时间'),
@@ -57,7 +80,7 @@ def upgrade():
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.CHAR(length=1), 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='排序'),
@@ -68,12 +91,23 @@ def upgrade():
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('status', sa.Integer(), nullable=True, comment='启用'),
sa.Column('enable', sa.Integer(), 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_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='用户编号'),
@@ -88,9 +122,12 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
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_dict_type')
op.drop_table('admin_dict_data')
op.drop_table('admin_admin_log')
# ### end Alembic commands ###
-35
View File
@@ -1,35 +0,0 @@
"""empty message
Revision ID: ce8825111f8f
Revises: 59add0790978
Create Date: 2021-03-11 22:41:25.156430
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'ce8825111f8f'
down_revision = '59add0790978'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
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')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('admin_role_power')
# ### end Alembic commands ###
-28
View File
@@ -1,28 +0,0 @@
"""empty message
Revision ID: e187b65f7f1b
Revises: 58fc2c4c30a5
Create Date: 2021-04-01 21:03:04.872235
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e187b65f7f1b'
down_revision = '58fc2c4c30a5'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('admin_user', sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('admin_user', 'remark')
# ### end Alembic commands ###