Add psycopg2 as an optional dependency and throw error at startup if db is not initialized
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
import sys
|
||||||
|
|
||||||
from alchemysession import AlchemySessionContainer
|
from alchemysession import AlchemySessionContainer
|
||||||
|
|
||||||
@@ -57,6 +58,10 @@ class TelegramBridge(Bridge):
|
|||||||
|
|
||||||
def prepare_db(self) -> None:
|
def prepare_db(self) -> None:
|
||||||
super().prepare_db()
|
super().prepare_db()
|
||||||
|
if not self.db.has_table("alembic_version"):
|
||||||
|
self.log.critical("alembic_version table not found. "
|
||||||
|
"Did you forget to `alembic upgrade head`?")
|
||||||
|
sys.exit(10)
|
||||||
init_db(self.db)
|
init_db(self.db)
|
||||||
self.session_container = AlchemySessionContainer(
|
self.session_container = AlchemySessionContainer(
|
||||||
engine=self.db, table_base=Base, session=False,
|
engine=self.db, table_base=Base, session=False,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
from sqlalchemy.engine.base import Engine
|
||||||
|
|
||||||
from mautrix.bridge.db import UserProfile, RoomState
|
from mautrix.bridge.db import UserProfile, RoomState
|
||||||
|
|
||||||
from .bot_chat import BotChat
|
from .bot_chat import BotChat
|
||||||
@@ -23,7 +25,7 @@ from .telegram_file import TelegramFile
|
|||||||
from .user import User, UserPortal, Contact
|
from .user import User, UserPortal, Contact
|
||||||
|
|
||||||
|
|
||||||
def init(db_engine) -> None:
|
def init(db_engine: Engine) -> None:
|
||||||
for table in (Portal, Message, User, Contact, UserPortal, Puppet, TelegramFile, UserProfile,
|
for table in (Portal, Message, User, Contact, UserPortal, Puppet, TelegramFile, UserProfile,
|
||||||
RoomState, BotChat):
|
RoomState, BotChat):
|
||||||
table.db = db_engine
|
table.db = db_engine
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ cryptg
|
|||||||
Pillow
|
Pillow
|
||||||
moviepy
|
moviepy
|
||||||
prometheus_client
|
prometheus_client
|
||||||
|
psycopg2-binary
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ extras = {
|
|||||||
"fast_crypto": ["cryptg>=0.1,<0.3"],
|
"fast_crypto": ["cryptg>=0.1,<0.3"],
|
||||||
"webp_convert": ["Pillow>=4.3.0,<7"],
|
"webp_convert": ["Pillow>=4.3.0,<7"],
|
||||||
"hq_thumbnails": ["moviepy>=1.0,<2.0"],
|
"hq_thumbnails": ["moviepy>=1.0,<2.0"],
|
||||||
"metrics": ["prometheus-client>=0.6.0,<0.8.0"],
|
"metrics": ["prometheus_client>=0.6.0,<0.8.0"],
|
||||||
|
"postgres": ["psycopg2-binary>=2,<3"],
|
||||||
}
|
}
|
||||||
extras["all"] = list({dep for deps in extras.values() for dep in deps})
|
extras["all"] = list({dep for deps in extras.values() for dep in deps})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user