def testPatchDatabaseWithoutSchema(self): """L{patchDatabase} creates a schema if one isn't already in place.""" schema = createSchema(self.patchPackage) self.assertRaises(OperationalError, self.store.execute, 'SELECT * FROM patch') patchDatabase(self.store, schema) self.assertEqual([], list(self.store.execute('SELECT * FROM patch')))
def run(self, path, database_uri, old_format=None): setupLogging(self.outf) store = setupStore(database_uri, 'logs') schema = logs.createSchema() logging.info('Creating schema') patchDatabase(store, schema) logging.info('Loading trace logs from %s', path) loadTraceLogs(path, store, old_format) logging.info('Finished loading trace logs from %s', path)
def run(self, path, database_uri): setupLogging(self.outf) store = setupStore(database_uri, 'logs') schema = logs.createSchema() logging.info('Creating schema') patchDatabase(store, schema) logging.info('Loading log file %s', path) loadLogs(path, store) logging.info('Finished loading log file %s', path)
def testPatchDatabaseWithoutPatches(self): """ L{patchDatabase} is basically a no-op if no patches are available. """ schema = createSchema(self.patchPackage) patchDatabase(self.store, schema) self.assertEqual([], list(self.store.execute('SELECT * FROM patch'))) patchDatabase(self.store, schema) self.assertEqual([], list(self.store.execute('SELECT * FROM patch')))
def run(self, database_uri): setConfig(setupConfig(None)) setupLogging(self.outf) store = setupStore(database_uri, 'main') schema = main.createSchema() logging.info('Creating schema.') patchDatabase(store, schema) logging.info('Creating system data.') bootstrapSystemData(store) logging.info('Creating web admin data.') bootstrapWebAdminData()
def testGetPatchStatusWithUnknownPatches(self): """ L{getPatchStatus} returns information about patch versions that exist in the database, but not in the code base. """ schema = createSchema(self.patchPackage) patchDatabase(self.store, schema) self.store.execute('INSERT INTO patch (version) VALUES (1)') status = getPatchStatus(self.store, schema) self.assertEqual([], status.unappliedPatches) self.assertEqual([1], status.unknownPatches)
def testGetPatchStatus(self): """ L{getPatchStatus} returns a L{PatchStatus} with information about outstanding and unknown patches. If the database is up-to-date and no unknown patches have been applied to it, both of these values are empty C{list}s. """ schema = createSchema(self.patchPackage) patchDatabase(self.store, schema) status = getPatchStatus(self.store, schema) self.assertEqual([], status.unappliedPatches) self.assertEqual([], status.unknownPatches)
def testPatchDatabaseWithoutUnappliedPatches(self): """L{patchDatabase} only applies unapplied patches.""" schema = createSchema(self.patchPackage) patchDatabase(self.store, schema) self.packageBuilder.createModule('patch_1', dedent("""\ def apply(store): store.execute('INSERT INTO person (name) VALUES (\\'Bob\\')') """)) self.store.execute('INSERT INTO patch (version) VALUES (1)') patchDatabase(self.store, schema) self.assertEqual([(1,)], list(self.store.execute('SELECT * FROM patch'))) self.assertEqual([], list(self.store.execute('SELECT * FROM person')))
def testGetPatchStatusWithUnappliedPatches(self): """ L{getPatchStatus} returns information about patch versions that need to be applied to a database to make it up-to-date with the code base. """ schema = createSchema(self.patchPackage) patchDatabase(self.store, schema) self.packageBuilder.createModule('patch_1', dedent("""\ def apply(store): store.execute('INSERT INTO person (name) VALUES (\\'Bob\\')') """)) status = getPatchStatus(self.store, schema) self.assertEqual([1], status.unappliedPatches) self.assertEqual([], status.unknownPatches)
def testPatchDatabase(self): """ L{patchDatabase} applies all outstanding patches. The C{patch} table contains a row for every patch version that has been applied to the database. """ schema = createSchema(self.patchPackage) patchDatabase(self.store, schema) self.packageBuilder.createModule('patch_1', dedent("""\ def apply(store): store.execute('INSERT INTO person (name) VALUES (\\'Bob\\')') """)) patchDatabase(self.store, schema) self.assertEqual([(1,)], list(self.store.execute('SELECT * FROM patch'))) self.assertEqual([('Bob',)], list(self.store.execute('SELECT * FROM person')))
def run(self, database_uri): setConfig(setupConfig(None)) setupLogging(self.outf) store = setupStore(database_uri, 'main') schema = main.createSchema() status = getPatchStatus(store, schema) if status.unknownPatches: unknownPatches = ', '.join( 'patch_%d' % version for version in status.unknownPatches) logging.critical('Database has unknown patches: %s', unknownPatches) return 1 if status.unappliedPatches: unappliedPatches = ', '.join( 'patch_%d' % version for version in status.unappliedPatches) logging.info('Applying patches: %s', unappliedPatches) patchDatabase(store, schema) else: logging.info('Database is up-to-date.')
def run(self, database_uri): setConfig(setupConfig(None)) setupLogging(self.outf) store = setupStore(database_uri, 'main') schema = main.createSchema() status = getPatchStatus(store, schema) if status.unknownPatches: unknownPatches = ', '.join('patch_%d' % version for version in status.unknownPatches) logging.critical('Database has unknown patches: %s', unknownPatches) return 1 if status.unappliedPatches: unappliedPatches = ', '.join( 'patch_%d' % version for version in status.unappliedPatches) logging.info('Applying patches: %s', unappliedPatches) patchDatabase(store, schema) else: logging.info('Database is up-to-date.')