|
|
@ -21,7 +21,7 @@ Base = declarative_base()
|
|
|
|
# Open session for database connection
|
|
|
|
# Open session for database connection
|
|
|
|
Session = sessionmaker()
|
|
|
|
Session = sessionmaker()
|
|
|
|
Session.configure(bind=engine)
|
|
|
|
Session.configure(bind=engine)
|
|
|
|
session = Session()
|
|
|
|
session = scoped_session(Session)
|
|
|
|
|
|
|
|
|
|
|
|
class GdriveId(Base):
|
|
|
|
class GdriveId(Base):
|
|
|
|
__tablename__='gdrive_ids'
|
|
|
|
__tablename__='gdrive_ids'
|
|
|
@ -29,16 +29,33 @@ class GdriveId(Base):
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
gdrive_id = Column(Integer, unique=True)
|
|
|
|
gdrive_id = Column(Integer, unique=True)
|
|
|
|
path = Column(String)
|
|
|
|
path = Column(String)
|
|
|
|
|
|
|
|
__table_args__ = (UniqueConstraint('gdrive_id', 'path', name='_gdrive_path_uc'),)
|
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self.path)
|
|
|
|
return str(self.path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def migrate():
|
|
|
|
|
|
|
|
for sql in session.execute("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('INSERT INTO gdrive_ids2 (id, gdrive_id, path) SELECT id, gdrive_id, path FROM gdrive_ids;')
|
|
|
|
|
|
|
|
session.commit()
|
|
|
|
|
|
|
|
session.execute('DROP TABLE %s' % 'gdrive_ids')
|
|
|
|
|
|
|
|
session.execute('ALTER TABLE gdrive_ids2 RENAME to gdrive_ids')
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(dbpath):
|
|
|
|
if not os.path.exists(dbpath):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
Base.metadata.create_all(engine)
|
|
|
|
Base.metadata.create_all(engine)
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
raise
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
migrate()
|
|
|
|
|
|
|
|
|
|
|
|
def getDrive(gauth=None):
|
|
|
|
def getDrive(gauth=None):
|
|
|
|
if not gauth:
|
|
|
|
if not gauth:
|
|
|
|
gauth=GoogleAuth(settings_file='settings.yaml')
|
|
|
|
gauth=GoogleAuth(settings_file='settings.yaml')
|
|
|
|