def setUp(self): # Initialize the database schema. from cnxarchive.database import initdb settings = {'db-connection-string': self.db_connection_string} initdb(settings) # # Initialize the cnxuser users shadow table. # from cnxarchive.database import DB_SCHEMA_DIRECTORY # with psycopg2.connect(self.db_connection_string) as db_connection: # with db_connection.cursor() as cursor: # cnxuser_schema_filepath = os.path.join(DB_SCHEMA_DIRECTORY, # 'cnx-user.schema.sql') # with open(cnxuser_schema_filepath, 'r') as fb: # cursor.execute(fb.read()) # Set the target subject/tag for removal. # Note this is different from the actual one to be removed. This # is because the actual one will eventually be removed from the # schema and therefore not loaded into the database. self.target_subject = 'Business' # Load some data and tie in tag info. with psycopg2.connect(self.db_connection_string) as db_connection: population_records = ['v1/modules-299.json', 'v1/modules-300.json', ] populate_database(db_connection, population_records) with db_connection.cursor() as cursor: cursor.execute("WITH tag AS " " (SELECT tagid as id FROM tags " " WHERE tag = %s) " "INSERT INTO moduletags VALUES " " (199, (select id from tag)), " " (200, (select id from tag));", (self.target_subject,))
def main(argv=None): """Initialize the database.""" parser = create_parser('initdb', description=__doc__) parser.add_argument('--with-example-data', action='store_true', help="Initializes the database with example data.") parser.add_argument('--superuser', action='store', help="NOT IMPLEMENTED") parser.add_argument('--super-password', action='store', help="NOT IMPLEMENTED") args = parser.parse_args(argv) settings = get_app_settings_from_arguments(args) try: initdb(settings) except psycopg2.InternalError as exc: print("Error: {}".format(exc.args[0]), file=sys.stderr) return 1 if args.with_example_data: connection_string = settings[config.CONNECTION_STRING] with psycopg2.connect(connection_string) as db_connection: with db_connection.cursor() as cursor: for filepath in EXAMPLE_DATA_FILEPATHS: with open(filepath, 'r') as fb: cursor.execute(fb.read()) return 0
def setUp(self): from cnxarchive.database import initdb, CONNECTION_SETTINGS_KEY initdb({CONNECTION_SETTINGS_KEY: self.db_connection_string}) with psycopg2.connect(self.db_connection_string) as db_connection: with db_connection.cursor() as cursor: cursor.execute(SQL_FOR_TESTED_DOCUMENTS)
def setUp(self): # Initialize the database schema. from cnxarchive.database import initdb settings = {'db-connection-string': self.connection_string} initdb(settings)
def setUp(self): # Initialize the database schema. from cnxarchive.database import initdb settings = {"db-connection-string": self.connection_string} initdb(settings)