Queer European MD passionate about IT
Ver Fonte

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)
Davte há 4 anos atrás
pai
commit
17b26ec23e

+ 2 - 2
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',

+ 21 - 5
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
 

+ 1 - 1
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'):

+ 1 - 1
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',

+ 1 - 1
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',