Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Fix tuple >< list bug for initial db migration
Browse files Browse the repository at this point in the history
+ Improve log formatting
  • Loading branch information
ovv committed Feb 19, 2018
1 parent 339cbe7 commit 63b5a9f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sirbot/plugins/postgres/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def migrate(self):
async with connection.transaction():
if old_version is None:
await self._init_database(connection)
old_version = (0, 0, 0)
old_version = ['0', '0', '0']

if old_version != current_version:
for version in self._find_update_version(start=old_version, end=current_version):
Expand All @@ -66,7 +66,7 @@ def _find_update_version(self, start, end):
if end >= file_version > start:
files.append(file_version)
files = sorted(files)
LOG.debug('Database migration versions: %s', files)
LOG.debug('Database migration versions: %s', ['.'.join(f) for f in files if f != 'init'])
return files

async def _init_database(self, connection):
Expand All @@ -76,18 +76,18 @@ async def _init_database(self, connection):
INSERT INTO metadata (db_version) VALUES ('0.0.0');
''')
if os.path.exists(os.path.join(self.sql_migration_directory, 'init.sql')):
await self._execute_sql_file(connection, 'init')
await self._execute_sql_file(connection, ('init', ))

async def _execute_sql_file(self, connection, version):
LOG.debug('Database migration to version: %s', version)
LOG.debug('Database migration to version %s: STARTED', '.'.join(version))
if version == 'init':
file = 'init.sql'
else:
file = '{}.sql'.format('.'.join(version))

async with aiofiles.open(os.path.join(self.sql_migration_directory, file), mode='r') as f:
await connection.execute((await f.read()))
LOG.debug('Database migration to version: %s OK', version)
LOG.debug('Database migration to version %s: OK', '.'.join(version))

@staticmethod
async def _check_database_version(connection):
Expand Down

0 comments on commit 63b5a9f

Please sign in to comment.