Skip to content

Commit

Permalink
Bugfix for python3.11, table gdrive_ids2 already exists (fix for jane…
Browse files Browse the repository at this point in the history
  • Loading branch information
OzzieIsaacs committed Mar 27, 2023
1 parent 253386b commit a72f0a1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 188 deletions.
18 changes: 0 additions & 18 deletions cps/gdriveutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,12 @@ def __repr__(self):
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):
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ install_requires =

[options.extras_require]
gdrive =
google-api-python-client>=1.7.11,<2.78.0
google-api-python-client>=1.7.11,<2.90.0
gevent>20.6.0,<23.0.0
greenlet>=0.4.17,<2.1.0
httplib2>=0.9.2,<0.22.0
httplib2>=0.9.2,<0.23.0
oauth2client>=4.0.0,<4.1.4
uritemplate>=3.0.0,<4.2.0
pyasn1-modules>=0.0.8,<0.3.0
Expand All @@ -76,7 +76,7 @@ gdrive =
rsa>=3.4.2,<4.10.0
gmail =
google-auth-oauthlib>=0.4.3,<0.9.0
google-api-python-client>=1.7.11,<2.78.0
google-api-python-client>=1.7.11,<2.90.0
goodreads =
goodreads>=0.3.2,<0.4.0
python-Levenshtein>=0.12.0,<0.21.0
Expand Down
Loading

0 comments on commit a72f0a1

Please sign in to comment.