backend: исправлено отслеживание изменений столбцов в бд

This commit is contained in:
2022-11-19 06:45:39 +03:00
parent 9672952d34
commit 337bf70534
9 changed files with 71 additions and 262 deletions

View File

@@ -1,44 +0,0 @@
"""empty message
Revision ID: 02142c549a8c
Revises: 07950b032eb7
Create Date: 2022-11-19 00:29:12.011840
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '02142c549a8c'
down_revision = '07950b032eb7'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('character_classes', schema=None) as batch_op:
batch_op.create_unique_constraint(None, ['name'])
with op.batch_alter_table('character_races', schema=None) as batch_op:
batch_op.create_unique_constraint(None, ['name'])
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.create_unique_constraint(None, ['name'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='unique')
with op.batch_alter_table('character_races', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='unique')
with op.batch_alter_table('character_classes', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='unique')
# ### end Alembic commands ###

View File

@@ -1,36 +0,0 @@
"""empty message
Revision ID: 07950b032eb7
Revises: 5aef83a8a42f
Create Date: 2022-11-18 23:40:33.130706
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '07950b032eb7'
down_revision = '5aef83a8a42f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.alter_column('owner',
existing_type=mysql.INTEGER(),
nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.alter_column('owner',
existing_type=mysql.INTEGER(),
nullable=False)
# ### end Alembic commands ###

View File

@@ -0,0 +1,64 @@
"""empty message
Revision ID: 370968e335df
Revises:
Create Date: 2022-11-19 06:44:47.040525
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '370968e335df'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('character_classes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('character_races',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('users',
sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('first_name', sa.String(length=255), nullable=True),
sa.Column('last_name', sa.String(length=255), nullable=True),
sa.Column('username', sa.String(length=255), nullable=False),
sa.Column('registered_on', sa.DateTime(), nullable=False),
sa.Column('is_admin', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('characters',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('owner', sa.BigInteger(), nullable=True),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('character_race', sa.Integer(), nullable=False),
sa.Column('character_class', sa.Integer(), nullable=False),
sa.Column('created_on', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['character_class'], ['character_classes.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['character_race'], ['character_races.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['owner'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('characters')
op.drop_table('users')
op.drop_table('character_races')
op.drop_table('character_classes')
# ### end Alembic commands ###

View File

@@ -1,51 +0,0 @@
"""empty message
Revision ID: 4126152c5668
Revises: 8f02337dbef0
Create Date: 2022-11-18 18:46:52.576544
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '4126152c5668'
down_revision = '8f02337dbef0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('character_classes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('character_races',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('characters',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('owner', sa.Integer(), nullable=True),
sa.Column('name', sa.String(length=255), nullable=True),
sa.Column('character_race', sa.Integer(), nullable=True),
sa.Column('character_class', sa.Integer(), nullable=True),
sa.Column('created_on', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['character_class'], ['character_classes.id'], ),
sa.ForeignKeyConstraint(['character_race'], ['character_races.id'], ),
sa.ForeignKeyConstraint(['owner'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('characters')
op.drop_table('character_races')
op.drop_table('character_classes')
# ### end Alembic commands ###

View File

@@ -1,54 +0,0 @@
"""empty message
Revision ID: 5aef83a8a42f
Revises: 4126152c5668
Create Date: 2022-11-18 19:18:39.496655
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '5aef83a8a42f'
down_revision = '4126152c5668'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.alter_column('owner',
existing_type=mysql.INTEGER(),
nullable=False)
batch_op.alter_column('name',
existing_type=mysql.VARCHAR(length=255),
nullable=False)
batch_op.alter_column('character_race',
existing_type=mysql.INTEGER(),
nullable=False)
batch_op.alter_column('character_class',
existing_type=mysql.INTEGER(),
nullable=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.alter_column('character_class',
existing_type=mysql.INTEGER(),
nullable=True)
batch_op.alter_column('character_race',
existing_type=mysql.INTEGER(),
nullable=True)
batch_op.alter_column('name',
existing_type=mysql.VARCHAR(length=255),
nullable=True)
batch_op.alter_column('owner',
existing_type=mysql.INTEGER(),
nullable=True)
# ### end Alembic commands ###

View File

@@ -1,36 +0,0 @@
"""empty message
Revision ID: 8f02337dbef0
Revises:
Create Date: 2022-11-18 17:37:55.798611
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8f02337dbef0'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('first_name', sa.String(length=255), nullable=True),
sa.Column('last_name', sa.String(length=255), nullable=True),
sa.Column('username', sa.String(length=255), nullable=False),
sa.Column('registered_on', sa.DateTime(), nullable=False),
sa.Column('is_admin', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('users')
# ### end Alembic commands ###

View File

@@ -1,32 +0,0 @@
"""empty message
Revision ID: c42d8e7674e6
Revises: 02142c549a8c
Create Date: 2022-11-19 02:48:49.436977
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c42d8e7674e6'
down_revision = '02142c549a8c'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.create_unique_constraint(None, ['owner'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='unique')
# ### end Alembic commands ###

View File

@@ -10,7 +10,7 @@ app = Flask(
"__name__",
)
migrate = Migrate(app, db)
migrate = Migrate(app, db, compare_type=True)
admin = Admin(name="TextSouls")
with open("textsouls/config.json") as config_file:

View File

@@ -11,9 +11,9 @@ class User(db.Model, SerializerMixin):
__tablename__ = "users"
serialize_rules = ("-characters",)
serialize_rules = ("-character",)
id = db.Column(db.Integer, primary_key=True, autoincrement=False)
id = db.Column(db.BigInteger, primary_key=True, autoincrement=False)
first_name = db.Column(db.String(255), nullable=True)
last_name = db.Column(db.String(255), nullable=True)
username = db.Column(db.String(255), nullable=False)
@@ -63,20 +63,18 @@ class Character(db.Model, SerializerMixin):
id = db.Column(db.Integer, primary_key=True)
owner = db.Column(
db.Integer,
db.ForeignKey("users.id"),
unique=True,
nullable=True,
db.BigInteger,
db.ForeignKey("users.id", ondelete="CASCADE"),
)
name = db.Column(db.String(255), nullable=False, unique=True)
character_race = db.Column(
db.Integer,
db.ForeignKey("character_races.id"),
db.ForeignKey("character_races.id", ondelete="CASCADE"),
nullable=False,
)
character_class = db.Column(
db.Integer,
db.ForeignKey("character_classes.id"),
db.ForeignKey("character_classes.id", ondelete="CASCADE"),
nullable=False,
)
created_on = db.Column(