Compare commits
2 Commits
v2
...
a39a7bf910
| Author | SHA1 | Date | |
|---|---|---|---|
| a39a7bf910 | |||
| aa88880a52 |
32
alembic/versions/69ef23ef1ed1_init.py
Normal file
32
alembic/versions/69ef23ef1ed1_init.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
"""init
|
||||||
|
|
||||||
|
Revision ID: 69ef23ef1ed1
|
||||||
|
Revises:
|
||||||
|
Create Date: 2025-09-05 13:53:02.737876
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '69ef23ef1ed1'
|
||||||
|
down_revision: Union[str, Sequence[str], None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
pass
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
pass
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: eeb6744b9452
|
|
||||||
Revises:
|
|
||||||
Create Date: 2025-09-05 14:55:12.005564
|
|
||||||
|
|
||||||
"""
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = 'eeb6744b9452'
|
|
||||||
down_revision: Union[str, Sequence[str], None] = None
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Создание всех таблиц согласно моделям."""
|
|
||||||
op.create_table(
|
|
||||||
'admins',
|
|
||||||
sa.Column('id', sa.Integer(), primary_key=True),
|
|
||||||
sa.Column('tg_id', sa.Integer(), unique=True, nullable=False),
|
|
||||||
)
|
|
||||||
op.create_table(
|
|
||||||
'channels',
|
|
||||||
sa.Column('id', sa.Integer(), primary_key=True),
|
|
||||||
sa.Column('name', sa.String, nullable=True),
|
|
||||||
sa.Column('link', sa.String, nullable=True),
|
|
||||||
sa.Column('admin_id', sa.Integer(), sa.ForeignKey('admins.id'), nullable=True),
|
|
||||||
)
|
|
||||||
op.create_table(
|
|
||||||
'groups',
|
|
||||||
sa.Column('id', sa.Integer(), primary_key=True),
|
|
||||||
sa.Column('name', sa.String, nullable=False),
|
|
||||||
sa.Column('link', sa.String, nullable=False),
|
|
||||||
sa.Column('admin_id', sa.Integer(), sa.ForeignKey('admins.id'), nullable=True),
|
|
||||||
)
|
|
||||||
op.create_table(
|
|
||||||
'buttons',
|
|
||||||
sa.Column('id', sa.Integer(), primary_key=True),
|
|
||||||
sa.Column('name', sa.String, nullable=False),
|
|
||||||
sa.Column('url', sa.String, nullable=False),
|
|
||||||
sa.Column('channel_id', sa.Integer(), sa.ForeignKey('channels.id'), nullable=True),
|
|
||||||
sa.Column('group_id', sa.Integer(), sa.ForeignKey('groups.id'), nullable=True),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Удаление всех таблиц."""
|
|
||||||
op.drop_table('buttons')
|
|
||||||
op.drop_table('groups')
|
|
||||||
op.drop_table('channels')
|
|
||||||
op.drop_table('admins')
|
|
||||||
@@ -1,26 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "[update.sh] Проверка bot.db..."
|
|
||||||
if [ -d "bot.db" ]; then
|
|
||||||
echo "Удаляю папку bot.db..."
|
|
||||||
rm -rf bot.db
|
|
||||||
fi
|
|
||||||
if [ ! -f "bot.db" ]; then
|
|
||||||
echo "Создаю пустой файл bot.db..."
|
|
||||||
touch bot.db
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[update.sh] Получение свежего кода..."
|
echo "[update.sh] Получение свежего кода..."
|
||||||
git pull
|
git pull
|
||||||
|
|
||||||
echo "[update.sh] Пересборка контейнера..."
|
echo "[update.sh] Пересборка контейнера..."
|
||||||
docker compose build --no-cache
|
cd ..
|
||||||
|
docker-compose build --no-cache
|
||||||
|
|
||||||
echo "[update.sh] Применение миграций Alembic..."
|
echo "[update.sh] Применение миграций Alembic..."
|
||||||
docker compose run --rm bot alembic upgrade head
|
docker-compose run --rm bot alembic upgrade head
|
||||||
|
|
||||||
echo "[update.sh] Запуск контейнера..."
|
echo "[update.sh] Запуск контейнера..."
|
||||||
docker compose up -d
|
docker-compose up -d
|
||||||
|
|
||||||
echo "[update.sh] Готово!"
|
echo "[update.sh] Готово!"
|
||||||
|
|||||||
10
db.py
10
db.py
@@ -9,13 +9,15 @@ DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///bot.db")
|
|||||||
|
|
||||||
if DATABASE_URL.startswith("sqlite+aiosqlite:///"):
|
if DATABASE_URL.startswith("sqlite+aiosqlite:///"):
|
||||||
db_path = DATABASE_URL.replace("sqlite+aiosqlite:///", "")
|
db_path = DATABASE_URL.replace("sqlite+aiosqlite:///", "")
|
||||||
|
# Убираем лишний слэш в конце, если есть
|
||||||
|
if db_path.endswith(os.sep):
|
||||||
|
db_path = db_path.rstrip(os.sep)
|
||||||
abs_db_path = os.path.abspath(db_path)
|
abs_db_path = os.path.abspath(db_path)
|
||||||
db_dir = os.path.dirname(abs_db_path)
|
db_dir = os.path.dirname(abs_db_path)
|
||||||
# Создаём директорию только если она не равна текущей ('.') и не пустая
|
if db_dir and not os.path.exists(db_dir):
|
||||||
if db_dir and db_dir != os.path.abspath("") and db_dir != '.' and not os.path.exists(db_dir):
|
|
||||||
os.makedirs(db_dir, exist_ok=True)
|
os.makedirs(db_dir, exist_ok=True)
|
||||||
# Если по этому пути уже есть папка, удаляем её
|
# Если по этому пути уже есть папка, удаляем её и создаём файл
|
||||||
if os.path.exists(abs_db_path) and os.path.isdir(abs_db_path):
|
if os.path.isdir(abs_db_path):
|
||||||
import shutil
|
import shutil
|
||||||
shutil.rmtree(abs_db_path)
|
shutil.rmtree(abs_db_path)
|
||||||
# Если файла нет, создаём пустой файл
|
# Если файла нет, создаём пустой файл
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ class Admin(Base):
|
|||||||
class Channel(Base):
|
class Channel(Base):
|
||||||
__tablename__ = 'channels'
|
__tablename__ = 'channels'
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
name = Column(String)
|
name = Column(String, nullable=False)
|
||||||
link = Column(String)
|
link = Column(String, nullable=False)
|
||||||
admin_id = Column(Integer, ForeignKey('admins.id'))
|
|
||||||
buttons = relationship('Button', back_populates='channel')
|
buttons = relationship('Button', back_populates='channel')
|
||||||
|
|
||||||
class Group(Base):
|
class Group(Base):
|
||||||
@@ -20,7 +19,6 @@ class Group(Base):
|
|||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
link = Column(String, nullable=False)
|
link = Column(String, nullable=False)
|
||||||
admin_id = Column(Integer, ForeignKey('admins.id'))
|
|
||||||
buttons = relationship('Button', back_populates='group')
|
buttons = relationship('Button', back_populates='group')
|
||||||
|
|
||||||
class Button(Base):
|
class Button(Base):
|
||||||
|
|||||||
Reference in New Issue
Block a user