Create users table if missing

This commit is contained in:
Davte 2020-04-07 14:00:39 +02:00
parent 06d3569fbd
commit 87d95fbfed
2 changed files with 33 additions and 13 deletions

View File

@ -14,7 +14,7 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it"
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
__license__ = "GNU General Public License v3.0"
__version__ = "2.4.15"
__version__ = "2.4.16"
__maintainer__ = "Davide Testa"
__contact__ = "t.me/davte"

View File

@ -223,18 +223,38 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
self.shared_data = dict()
self.Role = None
# Add `users` table with its fields if missing
self.db['users'].upsert(
dict(
telegram_id=000000000,
privileges=100,
username="username",
first_name="First",
last_name="Last",
language_code="en",
selected_language_code="en"
),
['telegram_id']
)
if 'users' not in self.db.tables:
table = self.db.create_table(
table_name='users'
)
table.create_column(
'telegram_id',
self.db.types.integer
)
table.create_column(
'privileges',
self.db.types.integer
)
table.create_column(
'username',
self.db.types.string
)
table.create_column(
'first_name',
self.db.types.string
)
table.create_column(
'last_name',
self.db.types.string
)
table.create_column(
'language_code',
self.db.types.string
)
table.create_column(
'selected_language_code',
self.db.types.string
)
return
@property