def init_db(self): db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_schema.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_tables.sql')) db.run_sql_script( os.path.join(ADMIN_SQL_DIR, 'create_primary_keys.sql')) db.run_sql_script( os.path.join(ADMIN_SQL_DIR, 'create_foreign_keys.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_indexes.sql'))
def init_msb_db(force, create_db): """Initializes database. This process involves several steps: 1. Table structure is created. 2. Primary keys and foreign keys are created. 3. Indexes are created. """ from listenbrainz import config db.init_db_connection(config.POSTGRES_ADMIN_URI) if force: res = db.run_sql_script_without_transaction( os.path.join(MSB_ADMIN_SQL_DIR, 'drop_db.sql')) if not res: raise Exception( 'Failed to drop existing database and user! Exit code: %s' % res) if create_db: print('Creating user and a database...') res = db.run_sql_script_without_transaction( os.path.join(MSB_ADMIN_SQL_DIR, 'create_db.sql')) if not res: raise Exception( 'Failed to create new database and user! Exit code: %s' % res) print('Creating database extensions...') res = db.run_sql_script_without_transaction( os.path.join(MSB_ADMIN_SQL_DIR, 'create_extensions.sql')) # Don't raise an exception if the extension already exists db.engine.dispose() # print('Creating schema...') # exit_code = run_psql_script('create_schema.sql') # if exit_code != 0: # raise Exception('Failed to create database schema! Exit code: %i' % exit_code) db.init_db_connection(config.MESSYBRAINZ_SQLALCHEMY_DATABASE_URI) print('Creating tables...') db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_tables.sql')) print('Creating primary and foreign keys...') db.run_sql_script( os.path.join(MSB_ADMIN_SQL_DIR, 'create_primary_keys.sql')) db.run_sql_script( os.path.join(MSB_ADMIN_SQL_DIR, 'create_foreign_keys.sql')) print('Creating functions...') db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_functions.sql')) print('Creating indexes...') db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_indexes.sql')) print("Done!")
def init_db(force, create_db): """Initializes database. This process involves several steps: 1. Table structure is created. 2. Primary keys and foreign keys are created. 3. Indexes are created. """ from listenbrainz import config db.init_db_connection(config.POSTGRES_ADMIN_URI) if force: res = db.run_sql_script_without_transaction( os.path.join(ADMIN_SQL_DIR, 'drop_db.sql')) if not res: raise Exception( 'Failed to drop existing database and user! Exit code: %i' % res) if create_db: print('Creating user and a database...') res = db.run_sql_script_without_transaction( os.path.join(ADMIN_SQL_DIR, 'create_db.sql')) if not res: raise Exception( 'Failed to create new database and user! Exit code: %i' % res) db.init_db_connection(config.POSTGRES_ADMIN_LB_URI) print('Creating database extensions...') res = db.run_sql_script_without_transaction( os.path.join(ADMIN_SQL_DIR, 'create_extensions.sql')) # Don't raise an exception if the extension already exists application = webserver.create_app() with application.app_context(): print('Creating schema...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_schema.sql')) print('Creating tables...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_tables.sql')) print('Creating primary and foreign keys...') db.run_sql_script( os.path.join(ADMIN_SQL_DIR, 'create_primary_keys.sql')) db.run_sql_script( os.path.join(ADMIN_SQL_DIR, 'create_foreign_keys.sql')) print('Creating indexes...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_indexes.sql')) print("Done!")
def init_db(force, create_db): """Initializes database. This process involves several steps: 1. Table structure is created. 2. Primary keys and foreign keys are created. 3. Indexes are created. """ db.init_db_connection(config.POSTGRES_ADMIN_URI) if force: res = db.run_sql_script_without_transaction(os.path.join(ADMIN_SQL_DIR, 'drop_db.sql')) if not res: raise Exception('Failed to drop existing database and user! Exit code: %i' % res) if create_db: print('Creating user and a database...') res = db.run_sql_script_without_transaction(os.path.join(ADMIN_SQL_DIR, 'create_db.sql')) if not res: raise Exception('Failed to create new database and user! Exit code: %i' % res) print('Creating database extensions...') res = db.run_sql_script_without_transaction(os.path.join(ADMIN_SQL_DIR, 'create_extensions.sql')) # Don't raise an exception if the extension already exists application = webserver.create_app() with application.app_context(): print('Creating schema...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_schema.sql')) print('Creating tables...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_tables.sql')) print('Creating primary and foreign keys...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_primary_keys.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_foreign_keys.sql')) print('Creating indexes...') db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_indexes.sql')) print("Done!")
def init_msb_db(force, create_db): """Initializes database. This process involves several steps: 1. Table structure is created. 2. Primary keys and foreign keys are created. 3. Indexes are created. """ db.init_db_connection(config.POSTGRES_ADMIN_URI) if force: res = db.run_sql_script_without_transaction(os.path.join(MSB_ADMIN_SQL_DIR, 'drop_db.sql')) if not res: raise Exception('Failed to drop existing database and user! Exit code: %s' % res) if create_db: print('Creating user and a database...') res = db.run_sql_script_without_transaction(os.path.join(MSB_ADMIN_SQL_DIR, 'create_db.sql')) if not res: raise Exception('Failed to create new database and user! Exit code: %s' % res) print('Creating database extensions...') res = db.run_sql_script_without_transaction(os.path.join(MSB_ADMIN_SQL_DIR, 'create_extensions.sql')) # Don't raise an exception if the extension already exists db.engine.dispose() # print('Creating schema...') # exit_code = run_psql_script('create_schema.sql') # if exit_code != 0: # raise Exception('Failed to create database schema! Exit code: %i' % exit_code) db.init_db_connection(config.MESSYBRAINZ_SQLALCHEMY_DATABASE_URI) print('Creating tables...') db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_tables.sql')) print('Creating primary and foreign keys...') db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_primary_keys.sql')) db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_foreign_keys.sql')) print('Creating indexes...') db.run_sql_script(os.path.join(MSB_ADMIN_SQL_DIR, 'create_indexes.sql')) print("Done!")
def drop_schema(self): db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'drop_schema.sql'))
def drop_tables(self): self.drop_schema() db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'drop_tables.sql'))
def init_db(self): db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_schema.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_tables.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_primary_keys.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_foreign_keys.sql')) db.run_sql_script(os.path.join(ADMIN_SQL_DIR, 'create_indexes.sql'))