backend + telegram: добавлено поле chat_id у пользователя

This commit is contained in:
2022-11-20 02:22:35 +03:00
parent b5bd2b908f
commit ce934affe3
6 changed files with 43 additions and 202 deletions

View File

@@ -1,128 +0,0 @@
"""empty message
Revision ID: 231e5697b63e
Revises: 57b47e18fdab
Create Date: 2022-11-19 21:56:35.469495
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '231e5697b63e'
down_revision = '57b47e18fdab'
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.alter_column('endurance_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('strength_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('agility_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('defence_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('wisdom_koef',
existing_type=mysql.FLOAT(),
nullable=False)
with op.batch_alter_table('character_races', schema=None) as batch_op:
batch_op.alter_column('endurance_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('strength_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('agility_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('defence_koef',
existing_type=mysql.FLOAT(),
nullable=False)
batch_op.alter_column('wisdom_koef',
existing_type=mysql.FLOAT(),
nullable=False)
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.alter_column('endurance_base',
existing_type=mysql.INTEGER(),
nullable=False)
batch_op.alter_column('strength_base',
existing_type=mysql.INTEGER(),
nullable=False)
batch_op.alter_column('agility_base',
existing_type=mysql.INTEGER(),
nullable=False)
batch_op.alter_column('defence_base',
existing_type=mysql.INTEGER(),
nullable=False)
batch_op.alter_column('wisdom_base',
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('wisdom_base',
existing_type=mysql.INTEGER(),
nullable=True)
batch_op.alter_column('defence_base',
existing_type=mysql.INTEGER(),
nullable=True)
batch_op.alter_column('agility_base',
existing_type=mysql.INTEGER(),
nullable=True)
batch_op.alter_column('strength_base',
existing_type=mysql.INTEGER(),
nullable=True)
batch_op.alter_column('endurance_base',
existing_type=mysql.INTEGER(),
nullable=True)
with op.batch_alter_table('character_races', schema=None) as batch_op:
batch_op.alter_column('wisdom_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('defence_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('agility_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('strength_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('endurance_koef',
existing_type=mysql.FLOAT(),
nullable=True)
with op.batch_alter_table('character_classes', schema=None) as batch_op:
batch_op.alter_column('wisdom_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('defence_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('agility_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('strength_koef',
existing_type=mysql.FLOAT(),
nullable=True)
batch_op.alter_column('endurance_koef',
existing_type=mysql.FLOAT(),
nullable=True)
# ### end Alembic commands ###

View File

@@ -1,68 +0,0 @@
"""empty message
Revision ID: 57b47e18fdab
Revises: 370968e335df
Create Date: 2022-11-19 20:40:22.680225
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '57b47e18fdab'
down_revision = '370968e335df'
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.add_column(sa.Column('endurance_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('strength_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('agility_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('defence_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('wisdom_koef', sa.Float(), nullable=True))
with op.batch_alter_table('character_races', schema=None) as batch_op:
batch_op.add_column(sa.Column('endurance_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('strength_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('agility_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('defence_koef', sa.Float(), nullable=True))
batch_op.add_column(sa.Column('wisdom_koef', sa.Float(), nullable=True))
with op.batch_alter_table('characters', schema=None) as batch_op:
batch_op.add_column(sa.Column('endurance_base', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('strength_base', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('agility_base', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('defence_base', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('wisdom_base', sa.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.drop_column('wisdom_base')
batch_op.drop_column('defence_base')
batch_op.drop_column('agility_base')
batch_op.drop_column('strength_base')
batch_op.drop_column('endurance_base')
with op.batch_alter_table('character_races', schema=None) as batch_op:
batch_op.drop_column('wisdom_koef')
batch_op.drop_column('defence_koef')
batch_op.drop_column('agility_koef')
batch_op.drop_column('strength_koef')
batch_op.drop_column('endurance_koef')
with op.batch_alter_table('character_classes', schema=None) as batch_op:
batch_op.drop_column('wisdom_koef')
batch_op.drop_column('defence_koef')
batch_op.drop_column('agility_koef')
batch_op.drop_column('strength_koef')
batch_op.drop_column('endurance_koef')
# ### end Alembic commands ###

View File

@@ -1,8 +1,8 @@
"""empty message
Revision ID: 370968e335df
Revision ID: c3b392fdf575
Revises:
Create Date: 2022-11-19 06:44:47.040525
Create Date: 2022-11-20 00:31:12.952336
"""
from alembic import op
@@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '370968e335df'
revision = 'c3b392fdf575'
down_revision = None
branch_labels = None
depends_on = None
@@ -21,23 +21,35 @@ def upgrade():
op.create_table('character_classes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.Column('endurance_koef', sa.Float(), nullable=False),
sa.Column('strength_koef', sa.Float(), nullable=False),
sa.Column('agility_koef', sa.Float(), nullable=False),
sa.Column('defence_koef', sa.Float(), nullable=False),
sa.Column('wisdom_koef', sa.Float(), nullable=False),
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.Column('endurance_koef', sa.Float(), nullable=False),
sa.Column('strength_koef', sa.Float(), nullable=False),
sa.Column('agility_koef', sa.Float(), nullable=False),
sa.Column('defence_koef', sa.Float(), nullable=False),
sa.Column('wisdom_koef', sa.Float(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('users',
sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
sa.Column('chat_id', sa.BigInteger(), 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')
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('chat_id')
)
op.create_table('characters',
sa.Column('id', sa.Integer(), nullable=False),
@@ -46,6 +58,11 @@ def upgrade():
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.Column('endurance_base', sa.Integer(), nullable=False),
sa.Column('strength_base', sa.Integer(), nullable=False),
sa.Column('agility_base', sa.Integer(), nullable=False),
sa.Column('defence_base', sa.Integer(), nullable=False),
sa.Column('wisdom_base', sa.Integer(), 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'),

View File

@@ -14,6 +14,7 @@ class User(db.Model, SerializerMixin):
serialize_rules = ("-character",)
id = db.Column(db.BigInteger, primary_key=True, autoincrement=False)
chat_id = db.Column(db.BigInteger, nullable=False, unique=True)
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)

View File

@@ -16,6 +16,7 @@ async def start(message, state):
tg_user = message.from_user
ts_user = {
"id": tg_user.id,
"chat_id": message.chat.id,
"first_name": tg_user.first_name,
"last_name": tg_user.last_name,
"username": tg_user.username,

View File

@@ -2,16 +2,34 @@ import json
from fastapi import FastAPI
import asyncio
from aiogram import Bot, Dispatcher
from aiogram.fsm.storage.memory import MemoryStorage
from textsouls.handlers import control
from textsouls.handlers import character_creation
with open("textsouls/config.json") as config_file:
config_data = json.load(config_file)
app = FastAPI()
bot = Bot(token=config_data["MAIN_SETTINGS"]["BOT_TOKEN"])
dp = Dispatcher(storage=MemoryStorage())
async def start_bot():
bot = Bot(token=config_data["MAIN_SETTINGS"]["BOT_TOKEN"])
dp = Dispatcher(storage=MemoryStorage())
dp.include_router(control.router)
dp.include_router(character_creation.router)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
@app.on_event("startup")
async def startup_event():
asyncio.create_task(start_bot())
@app.get("/")