Bugfix for python3.11, table gdrive_ids2 already exists (fix for #2729)
This commit is contained in:
@@ -174,30 +174,12 @@ class PermissionAdded(Base):
|
||||
return str(self.gdrive_id)
|
||||
|
||||
|
||||
def migrate():
|
||||
if not engine.dialect.has_table(engine.connect(), "permissions_added"):
|
||||
PermissionAdded.__table__.create(bind = engine)
|
||||
for sql in session.execute(text("select sql from sqlite_master where type='table'")):
|
||||
if 'CREATE TABLE gdrive_ids' in sql[0]:
|
||||
currUniqueConstraint = 'UNIQUE (gdrive_id)'
|
||||
if currUniqueConstraint in sql[0]:
|
||||
sql=sql[0].replace(currUniqueConstraint, 'UNIQUE (gdrive_id, path)')
|
||||
sql=sql.replace(GdriveId.__tablename__, GdriveId.__tablename__ + '2')
|
||||
session.execute(sql)
|
||||
session.execute(text("INSERT INTO gdrive_ids2 (id, gdrive_id, path) SELECT id, "
|
||||
"gdrive_id, path FROM gdrive_ids;"))
|
||||
session.commit()
|
||||
session.execute(text('DROP TABLE %s' % 'gdrive_ids'))
|
||||
session.execute(text('ALTER TABLE gdrive_ids2 RENAME to gdrive_ids'))
|
||||
break
|
||||
|
||||
if not os.path.exists(cli_param.gd_path):
|
||||
try:
|
||||
Base.metadata.create_all(engine)
|
||||
except Exception as ex:
|
||||
log.error("Error connect to database: {} - {}".format(cli_param.gd_path, ex))
|
||||
raise
|
||||
migrate()
|
||||
|
||||
|
||||
def getDrive(drive=None, gauth=None):
|
||||
|
||||
Reference in New Issue
Block a user