Method to add table columns if missing
This commit is contained in:
parent
cf492f0c8b
commit
41f38d0b23
@ -11,7 +11,7 @@ __author__ = "Davide Testa"
|
||||
__email__ = "davide@davte.it"
|
||||
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
||||
__license__ = "GNU General Public License v3.0"
|
||||
__version__ = "2.9.5"
|
||||
__version__ = "2.9.6"
|
||||
__maintainer__ = "Davide Testa"
|
||||
__contact__ = "t.me/davte"
|
||||
|
||||
|
@ -21,6 +21,7 @@ from typing import Tuple, Union
|
||||
# Third party modules
|
||||
|
||||
import aiohttp
|
||||
import dataset
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
@ -1747,3 +1748,18 @@ async def aio_subprocess_shell(command: str,
|
||||
|
||||
def join_path(*args):
|
||||
return os.path.abspath(os.path.join(*args))
|
||||
|
||||
|
||||
def add_table_and_columns_if_not_existent(database: dataset.Database,
|
||||
table_name: str,
|
||||
columns: Tuple[Tuple, ...]):
|
||||
if table_name not in database.tables:
|
||||
table = database.create_table(table_name=table_name)
|
||||
else:
|
||||
table = database[table_name]
|
||||
for column_name, column_type in columns:
|
||||
if not table.has_column(column_name):
|
||||
table.create_column(
|
||||
column_name,
|
||||
column_type
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user