def testSetupAndTeardownDatabase(): """ testSetupAndTeardownDatabase(): - test that when we setupDatabase, we get all the expected tables - test that when we teardownDatabase, we remove all the expected tables """ global me tcon,tcur = schema.connectToDatabase(me.config,me.logger) tcur.execute("DROP TABLE IF EXISTS %s CASCADE"%','.join(me.expectedTableNames)) tcon.commit() try: schema.setupDatabase(me.config,me.logger) try: for t in me.expectedTableNames: # next line raises if the table does not exist tcur.execute("SELECT count(*) from %s"%t) tcon.commit() count = tcur.fetchone()[0] assert 0 == count finally: schema.teardownDatabase(me.config,me.logger) for t in me.expectedTableNames: try: tcur.execute("SELECT count(*) from %s"%t) assert False, 'Expected table %s does not exist'%t except psycopg2.ProgrammingError: tcon.rollback() except Exception,x: assert False, 'Expected psycopg2.ProgrammingError, not %s: %s'%(type(x),x) finally: tcon.close()
def testPartitionInsert(self): """ TestPartitionedTable.testPartitionInsert(): - check that we automagically create the needed partition on insert """ global me tz = dtutil.UTC() # test in this order, because other things depend on reports insertRows = [ [schema.ReportsTable,['0bba61c5-dfc3-43e7-dead-8afd20071025',dt.datetime(2007,12,25,5,4,3,21,tz),dt.datetime(2007,12,25,5,4,3,33),'product','version','build','url',3000,0,22,'email',dt.date(2007,12,1),None,"","","",""]], [schema.ExtensionsTable,[1,dt.datetime(2007,12,25,5,4,3,33),1,'extensionid','version']], [schema.FramesTable,[1,2,dt.datetime(2007,12,25,5,4,3,33),'somesignature']], [schema.DumpsTable,[1,dt.datetime(2007,12,25,5,4,3,33),"data"]], ] # call insert, expecting auto-creation of partitions cursor = self.connection.cursor() me.dsn = "host=%s dbname=%s user=%s password=%s" % (me.config.databaseHost,me.config.databaseName, me.config.databaseUserName,me.config.databasePassword) schema.setupDatabase(me.config,me.logger) before = set([x for x in socorro_psg.tablesMatchingPattern('%',cursor) if not 'pg_toast' in x]) for t in insertRows: obj = t[0](logger=me.logger) obj.insert(cursor,t[1],self.altConnectionCursor,date_processed=dt.datetime(2007,12,25,5,4,3,33)) self.connection.commit() current = set([x for x in socorro_psg.tablesMatchingPattern('%',cursor) if not 'pg_toast' in x]) diff = current - before assert set(['%s_20071224'%obj.name]) == diff,'Expected set([%s_20071224]), got %s'%(obj.name,diff) before = current
def testSetupAndTeardownDatabase(): """ testSetupAndTeardownDatabase(): - test that when we setupDatabase, we get all the expected tables - test that when we teardownDatabase, we remove all the expected tables """ global me tcon, tcur = schema.connectToDatabase(me.config, me.logger) tcur.execute("DROP TABLE IF EXISTS %s CASCADE" % ','.join(me.expectedTableNames)) tcon.commit() try: schema.setupDatabase(me.config, me.logger) try: for t in me.expectedTableNames: if '_enum' in t: continue # next line raises if the table does not exist tcur.execute("SELECT count(*) from %s" % t) tcon.commit() count = tcur.fetchone()[0] assert 0 == count finally: schema.teardownDatabase(me.config, me.logger) for t in me.expectedTableNames: try: tcur.execute("SELECT count(*) from %s" % t) assert False, 'Expected table %s does not exist' % t except psycopg2.ProgrammingError: tcon.rollback() except Exception, x: assert False, 'Expected psycopg2.ProgrammingError, not %s: %s' % ( type(x), x) finally: tcon.close()
def createTables(self): # DETAIL: exceptions.ImportError: No module named socorro.database.server self.log.info("Creating tables using schema.py setupDatabase"); schema.setupDatabase(self.configContext, self.log) triggers = ["dumps", "dumps", " extensions", "frames", "reports"] cur = self.conn.cursor() for triggerName in triggers: triggerFullName = "%s_insert_trigger" % triggerName self.log.debug("dropping trigger %s ON %s" % (triggerFullName, triggerName)) cur.execute("DROP TRIGGER IF EXISTS %s ON %s;" % (triggerFullName, triggerName)) self.conn.commit() foo = """self.log.info("Creating tables");
def createDB(self, config, logger): """Convenience: Forward to schema to get actual work done each thing in exactly one place""" db_schema.setupDatabase(config, logger)
def larscreateTables(self): #print "using schema.setupDatabase( self.configContext)" schema.setupDatabase( self.configContext, self.log)
def createDB(self, config, logger): """Convenience: Forward to schema to get actual work done each thing in exactly one place""" db_schema.setupDatabase(config,logger)
import logging.handlers try: import config.setupdatabaseconfig as configModule except ImportError: import setupdatabaseconfig as configModule import socorro.database.schema as socorro_schema import socorro.lib.ConfigurationManager as configurationManager import socorro.lib.util as sutil try: config = configurationManager.newConfiguration(configurationModule=configModule, applicationName="Socorro Database Setup 1.0") except configurationManager.NotAnOptionError, x: print >>sys.stderr, x print >>sys.stderr, "for usage, try --help" sys.exit() logger = logging.getLogger("setupDatabase") logger.setLevel(logging.DEBUG) sutil.setupLoggingHandlers(logger, config) sutil.echoConfig(logger, config) try: socorro_schema.setupDatabase(config, logger) finally: logger.info("done.")