From 17b26ec23ee0e62063b1372f811e50183a3a638d Mon Sep 17 00:00:00 2001 From: Davte Date: Wed, 7 Oct 2020 16:19:03 +0200 Subject: [PATCH] MySQL compatibility: specify VARCHAR length `db.types.string` becomes now `db.types.string(n)` `db.types.text` is the wrong type to use (text blobs) --- davtelepot/administration_tools.py | 4 ++-- davtelepot/bot.py | 26 +++++++++++++++++++++----- davtelepot/database.py | 2 +- davtelepot/suggestions.py | 2 +- davtelepot/useful_tools.py | 2 +- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/davtelepot/administration_tools.py b/davtelepot/administration_tools.py index 76fcfe0..8051dbb 100644 --- a/davtelepot/administration_tools.py +++ b/davtelepot/administration_tools.py @@ -1824,11 +1824,11 @@ def init(telegram_bot: Bot, ) table.create_column( 'command', - db.types.string + db.types.string(100) ) table.create_column( 'description', - db.types.string + db.types.string(300) ) table.create_column( 'hidden', diff --git a/davtelepot/bot.py b/davtelepot/bot.py index ce28b21..28ca0bc 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -255,23 +255,39 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): ) table.create_column( 'username', - self.db.types.string + self.db.types.string(64) ) table.create_column( 'first_name', - self.db.types.string + self.db.types.string(64) ) table.create_column( 'last_name', - self.db.types.string + self.db.types.string(64) ) table.create_column( 'language_code', - self.db.types.string + self.db.types.string(8) ) table.create_column( 'selected_language_code', - self.db.types.string + self.db.types.string(8) + ) + if 'user_profile_photos' not in self.db.tables: + table = self.db.create_table( + table_name='user_profile_photos' + ) + table.create_column( + 'user_id', + self.db.types.integer + ) + table.create_column( + 'telegram_file_id', + self.db.types.string(128) + ) + table.create_column( + 'update_datetime', + self.db.types.datetime ) return diff --git a/davtelepot/database.py b/davtelepot/database.py index 0e73dbb..baf264c 100644 --- a/davtelepot/database.py +++ b/davtelepot/database.py @@ -26,7 +26,7 @@ class ObjectWithDatabase(object): """Instantiate object and open connection with database.""" if database_url is None: database_url = 'database.db' - if ':///' not in database_url: + if '://' not in database_url: # Default database engine is sqlite, which operates on a # single-file database having `.db` extension if not database_url.endswith('.db'): diff --git a/davtelepot/suggestions.py b/davtelepot/suggestions.py index 63f72b8..3972c1c 100644 --- a/davtelepot/suggestions.py +++ b/davtelepot/suggestions.py @@ -262,7 +262,7 @@ def init(telegram_bot: davtelepot.bot.Bot, suggestion_messages=None): ) table.create_column( 'suggestion', - types.text + types.string(2048) ) table.create_column( 'created', diff --git a/davtelepot/useful_tools.py b/davtelepot/useful_tools.py index 922e0b6..b8ccd3c 100644 --- a/davtelepot/useful_tools.py +++ b/davtelepot/useful_tools.py @@ -664,7 +664,7 @@ def init(telegram_bot: Bot, useful_tools_messages=None): ) table.create_column( 'expression', - types.string + types.string(8192) ) @telegram_bot.command(command='/calc',