def start_schema(conn, installuser='******'): cursor = conn.cursor(statement=True) tables, mapping = primary_tables() current_tables = cursor.tables() primary_table_names = [t.name for t in tables] startup = True for tname in primary_table_names: if tname in current_tables: startup = False if startup: map(cursor.create_sequence, primary_sequences()) map(cursor.create_table, tables) both = [s for s in MACHINE_SCRIPTS if s in TRAIT_SCRIPTS] print both traitscripts = [s for s in TRAIT_SCRIPTS if s not in both] print traitscripts machinescripts = [s for s in MACHINE_SCRIPTS if s not in both] print machinescripts for script in both: cursor.insert(table='scriptnames', data=dict(script=script, type='both')) for script in traitscripts: cursor.insert(table='scriptnames', data=dict(script=script, type='trait')) for script in machinescripts: cursor.insert(table='scriptnames', data=dict(script=script, type='machine')) paella_select = grant_user('SELECT', [x.name for x in tables], installuser) paella_full = grant_user('ALL', ['current_environment'], installuser) paella_insert = grant_user('INSERT', ['default_environment'], installuser) for grant in paella_select, paella_full, paella_insert: cursor.execute(grant) create_pgsql_functions(cursor) else: all_there = True for table in primary_table_names: if table not in current_tables: all_there = False # the AlreadyPresentError is a convenience error # it doesn't mean the schema is a-ok if all_there: raise AlreadyPresentError, 'it seems everything is already here' else: raise SchemaError, 'some primary tables already exist in the database'
def make_suite_tables(self, suite=None): suite, ignore = self._mod_suite(suite) tables = suite_tables(suite) for table in tables: self.create_table(table) #self.execute(grant_public([t.name for t in tables])) paella_select = grant_user('SELECT', [t.name for t in tables], 'paella') self.execute(paella_select)
def make_suite_tables(self, suite=None): suite, ignore = self._mod_suite(suite) tables = suite_tables(suite) for table in tables: self.create_table(table) # self.execute(grant_public([t.name for t in tables])) paella_select = grant_user("SELECT", [t.name for t in tables], "paella") self.execute(paella_select)