MCPcopy Create free account
hub / github.com/apache/madlib / _db_create_objects

Function _db_create_objects

src/madpack/madpack.py:700–825  ·  view source on GitHub ↗

Create MADlib DB objects in the schema @param schema Name of the target schema @param sc ScriptCleaner object @param testcase Command-line args for modules to install @param hawq_debug

(schema, old_schema, upgrade=False, sc=None, testcase="",
                       hawq_debug=False)

Source from the content-addressed store, hash-verified

698
699
700def _db_create_objects(schema, old_schema, upgrade=False, sc=None, testcase="",
701 hawq_debug=False):
702 """
703 Create MADlib DB objects in the schema
704 @param schema Name of the target schema
705 @param sc ScriptCleaner object
706 @param testcase Command-line args for modules to install
707
708 @param hawq_debug
709 """
710 if not upgrade and not hawq_debug:
711 # Create MigrationHistory table
712 try:
713 _info("> Creating %s.MigrationHistory table" % schema.upper(), True)
714 _internal_run_query("DROP TABLE IF EXISTS %s.migrationhistory;" % schema, True)
715 sql = """CREATE TABLE %s.migrationhistory
716 (id serial, version varchar(255),
717 applied timestamp default current_timestamp);""" % schema
718 _internal_run_query(sql, True)
719 except:
720 _error("Cannot crate MigrationHistory table", False)
721 raise Exception
722
723 # Copy MigrationHistory table for record keeping purposes
724 if old_schema:
725 try:
726 _info("> Saving data from %s.MigrationHistory table" % old_schema.upper(), True)
727 sql = """INSERT INTO %s.migrationhistory (version, applied)
728 SELECT version, applied FROM %s.migrationhistory
729 ORDER BY id;""" % (schema, old_schema)
730 _internal_run_query(sql, True)
731 except:
732 _error("Cannot copy MigrationHistory table", False)
733 raise Exception
734
735 # Stamp the DB installation
736 try:
737 _info("> Writing version info in MigrationHistory table", True)
738 _internal_run_query("INSERT INTO %s.migrationhistory(version) "
739 "VALUES('%s')" % (schema, rev), True)
740 except:
741 _error("Cannot insert data into %s.migrationhistory table" % schema, False)
742 raise Exception
743
744 # Run migration SQLs
745 if upgrade:
746 _info("> Creating/Updating objects for modules:", True)
747 else:
748 _info("> Creating objects for modules:", True)
749
750 caseset = (set([test.strip() for test in testcase.split(',')])
751 if testcase != "" else set())
752
753 modset = {}
754 for case in caseset:
755 if case.find('/') > -1:
756 [mod, algo] = case.split('/')
757 if mod not in modset:

Callers 2

_db_installFunction · 0.85
_db_upgradeFunction · 0.85

Calls 5

_infoFunction · 0.85
_internal_run_queryFunction · 0.85
_errorFunction · 0.85
_make_dirFunction · 0.85
_run_sql_fileFunction · 0.85

Tested by

no test coverage detected