def start_schema(conn): 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) insert_list(cursor, 'scriptnames', 'script', SCRIPTS) newscripts = [s for s in MTSCRIPTS if s not in SCRIPTS] insert_list(cursor, 'scriptnames', 'script', newscripts) cursor.execute(grant_public([x.name for x in tables])) cursor.execute(grant_public(['current_environment'], 'ALL')) cursor.execute(grant_public(['partition_workspace'], 'ALL')) 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 create_database(cfg, default_traits): dsn = cfg.get_dsn() dsn['dbname'] = 'mishmash' conn = QuickConn(dsn) cmd = StatementCursor(conn, 'create_database') for table in cmd.tables(): cmd.execute('drop table %s' %table) start_schema(conn, default_traits) make_suites(conn) cmd.execute(grant_public(cmd.tables())) cmd.execute(grant_public(['current_environment'], 'ALL'))
def create_database(cfg, default_traits): dsn = cfg.get_dsn() dsn['dbname'] = 'mishmash' conn = QuickConn(dsn) cmd = StatementCursor(conn, 'create_database') for table in cmd.tables(): cmd.execute('drop table %s' % table) start_schema(conn, default_traits) make_suites(conn) cmd.execute(grant_public(cmd.tables())) cmd.execute(grant_public(['current_environment'], 'ALL'))
def make_suite_tables(self, suite=None): if suite is None: suite = self.current tables = suite_tables(suite) for table in tables: self.create_table(table) self.execute(grant_public([t.name for t in tables]))
def start_schema(conn): cursor = StatementCursor(conn, 'start_schema') map(cursor.create_sequence, primary_sequences()) tables, mapping = primary_tables() map(cursor.create_table, tables) priorities_table = mapping['priorities'] insert_list(cursor, priorities_table.name, 'priority', PRIORITIES) insert_list(cursor, 'scriptnames', 'script', SCRIPTS) cursor.execute(grant_public([x.name for x in tables])) cursor.execute(grant_public(['current_environment'], 'ALL')) cursor.execute(grant_public(['partition_workspace'], 'ALL')) cursor.execute(plpgsql_delete_trait) cursor.execute(pgsql_delete_profile()) cursor.execute(pgsql_delete_family()) cursor.execute(pgsql_delete_disk()) cursor.execute(pgsql_delete_mtype()) cursor.execute(pgsql_delete_filesystem())
def create_schema(cursor, group): newseqs = [s for s in sequences if s not in cursor.sequences()] for s in newseqs: cursor.create_sequence(Sequence(s)) for t in MAINTABLES: cursor.create_table(t()) tables = [t().name for t in MAINTABLES] full = [ClientInfoTable, ClientTicketTable, ClientTaskTable, LocationTaskTable] insup = [AddressTable, ContactTable, TicketStatusTable, LocationTable, ClientTable, TaskTable] ins = [TicketTable, TicketActionTable, TicketActionParentTable] execute = cursor.execute execute(grant_public(tables)) execute(grant_group('ALL', sequences, group)) execute(grant_group('ALL', [t().name for t in full], group)) execute(grant_group('INSERT', [t().name for t in ins + insup], group)) execute(grant_group('UPDATE', [t().name for t in insup], group))
def _make_suite_tables(self): tables = suite_tables(self.suite) map(self.cursor.create_table, tables) self.cursor.execute(grant_public([x.name for x in tables]))
def make_suite(cursor, suite): tables = suite_tables(suite) map(cursor.create_table, tables) cursor.execute(grant_public([x.name for x in tables]))