Exemplo n.º 1
0
def install_db(root_login="******", root_password=None, db_name=None, source_sql=None,
	admin_password=None, verbose=True, force=0, site_config=None, reinstall=False):
	make_conf(db_name, site_config=site_config)
	frappe.flags.in_install_db = True
	if reinstall:
		frappe.connect(db_name=db_name)
		dbman = DbManager(frappe.local.db)
		dbman.create_database(db_name)

	else:
		frappe.local.db = get_root_connection(root_login, root_password)
		frappe.local.session = frappe._dict({'user':'******'})
		create_database_and_user(force, verbose)

	frappe.conf.admin_password = frappe.conf.admin_password or admin_password

	frappe.connect(db_name=db_name)
	check_if_ready_for_barracuda()
	import_db_from_sql(source_sql, verbose)
	if not 'tabDefaultValue' in frappe.db.get_tables():
		print('''Database not installed, this can due to lack of permission, or that the database name exists.
Check your mysql root password, or use --force to reinstall''')
		sys.exit(1)

	remove_missing_apps()

	create_auth_table()
	setup_global_search_table()
	create_user_settings_table()

	frappe.flags.in_install_db = False
Exemplo n.º 2
0
def install_db(root_login="******",
               root_password=None,
               db_name=None,
               source_sql=None,
               admin_password=None,
               verbose=True,
               force=0,
               site_config=None,
               reinstall=False):
    make_conf(db_name, site_config=site_config)
    frappe.flags.in_install_db = True
    if reinstall:
        frappe.connect(db_name=db_name)
        dbman = DbManager(frappe.local.db)
        dbman.create_database(db_name)

    else:
        frappe.local.db = get_root_connection(root_login, root_password)
        frappe.local.session = frappe._dict({'user': '******'})
        create_database_and_user(force, verbose)

    frappe.conf.admin_password = frappe.conf.admin_password or admin_password

    frappe.connect(db_name=db_name)
    check_if_ready_for_barracuda()
    import_db_from_sql(source_sql, verbose)
    remove_missing_apps()

    create_auth_table()
    create_list_settings_table()

    frappe.flags.in_install_db = False
Exemplo n.º 3
0
def install_db(root_login="******", root_password=None, db_name=None, source_sql=None,
	admin_password = '******', verbose=True, force=0, site_config=None, reinstall=False):
	frappe.flags.in_install_db = True
	db_name=db_name[:16]
	if "." in db_name: 
		dn=db_name.split('.')
		db_name=dn[0]
	frappe.errprint(db_name)
	make_conf(db_name, site_config=site_config)
	if reinstall:
		frappe.connect(db_name=db_name)
		dbman = DbManager(frappe.local.db)
		dbman.create_database(db_name)

	else:
		frappe.local.db = make_connection(root_login, root_password)
		frappe.local.session = frappe._dict({'user':'******'})
		create_database_and_user(force, verbose)

	frappe.conf.admin_password = admin_password

	frappe.connect(db_name=db_name)
	import_db_from_sql(source_sql, verbose)

	create_auth_table()
	frappe.flags.in_install_db = False
Exemplo n.º 4
0
def install_db(root_login="******",
               root_password=None,
               db_name=None,
               source_sql=None,
               admin_password='******',
               verbose=True,
               force=0,
               site_config=None,
               reinstall=False):
    frappe.flags.in_install_db = True
    db_name = db_name[:16]
    if "." in db_name:
        dn = db_name.split('.')
        db_name = dn[0]
    frappe.errprint(db_name)
    make_conf(db_name, site_config=site_config)
    if reinstall:
        frappe.connect(db_name=db_name)
        dbman = DbManager(frappe.local.db)
        dbman.create_database(db_name)

    else:
        frappe.local.db = make_connection(root_login, root_password)
        frappe.local.session = frappe._dict({'user': '******'})
        create_database_and_user(force, verbose)

    frappe.conf.admin_password = admin_password

    frappe.connect(db_name=db_name)
    import_db_from_sql(source_sql, verbose)

    create_auth_table()
    frappe.flags.in_install_db = False
Exemplo n.º 5
0
def install_db(root_login="******", root_password=None, db_name=None, source_sql=None,
	admin_password=None, verbose=True, force=0, site_config=None, reinstall=False):
	make_conf(db_name, site_config=site_config)
	frappe.flags.in_install_db = True
	if reinstall:
		frappe.connect(db_name=db_name)
		dbman = DbManager(frappe.local.db)
		dbman.create_database(db_name)

	else:
		frappe.local.db = get_root_connection(root_login, root_password)
		frappe.local.session = frappe._dict({'user':'******'})
		create_database_and_user(force, verbose)

	frappe.conf.admin_password = frappe.conf.admin_password or admin_password

	frappe.connect(db_name=db_name)
	check_if_ready_for_barracuda()
	import_db_from_sql(source_sql, verbose)
	remove_missing_apps()

	create_auth_table()
	create_list_settings_table()

	frappe.flags.in_install_db = False
Exemplo n.º 6
0
def install_db(root_login="******", root_password=None, db_name=None, source_sql=None,
	admin_password=None, verbose=True, force=0, site_config=None, reinstall=False,
	no_mariadb_socket=False):
	make_conf(db_name, site_config=site_config)
	frappe.flags.in_install_db = True
	if reinstall:
		frappe.connect(db_name=db_name)
		dbman = DbManager(frappe.local.db)
		dbman.create_database(db_name)

	else:
		frappe.local.db = get_root_connection(root_login, root_password)
		frappe.local.session = frappe._dict({'user':'******'})
		create_database_and_user(force, verbose, no_mariadb_socket)

	frappe.conf.admin_password = frappe.conf.admin_password or admin_password

	frappe.connect(db_name=db_name)
	check_if_ready_for_barracuda()
	import_db_from_sql(source_sql, verbose)
	if not 'tabDefaultValue' in frappe.db.get_tables():
		print('''Database not installed, this can due to lack of permission, or that the database name exists.
Check your mysql root password, or use --force to reinstall''')
		sys.exit(1)

	remove_missing_apps()

	create_auth_table()
	setup_global_search_table()
	create_user_settings_table()

	frappe.flags.in_install_db = False
Exemplo n.º 7
0
	def make_database(self):
		dbman = DbManager(get_root_connection())

		# make database
		if not help_db_name in dbman.get_database_list():
			dbman.create_user(help_db_name, help_db_name)
			dbman.create_database(help_db_name)
			dbman.grant_all_privileges(help_db_name, help_db_name)
			dbman.flush_privileges()
Exemplo n.º 8
0
def import_db_from_sql(source_sql, verbose):
	if verbose: print "Starting database import..."
	db_name = frappe.conf.db_name
	if not source_sql:
		source_sql = os.path.join(os.path.dirname(frappe.__file__), 'data', 'Framework.sql')
		production_forecast_sql = os.path.join(os.path.dirname(frappe.__file__), 'data', 'Production_Forecast.sql')
	DbManager(frappe.local.db).restore_database(db_name, source_sql, db_name, frappe.conf.db_password)
	DbManager(frappe.local.db).restore_database(db_name, production_forecast_sql, 'root', 'password')
	if verbose: print "Imported from database %s" % source_sql
Exemplo n.º 9
0
def import_db_from_sql(source_sql, verbose):
	if verbose: print("Starting database import...")
	db_name = frappe.conf.db_name
	if not source_sql:
		source_sql = os.path.join(os.path.dirname(frappe.__file__), 'data', 'Framework.sql')
	DbManager(frappe.local.db).restore_database(db_name, source_sql, db_name, frappe.conf.db_password)
	if verbose: print("Imported from database %s" % source_sql)
Exemplo n.º 10
0
def drop_site(site, root_login='******', root_password=None):
	from frappe.installer import get_current_host, make_connection
	from frappe.model.db_schema import DbManager
	from frappe.utils.backups import scheduled_backup

	frappe.init(site=site)
	frappe.connect()
	scheduled_backup(ignore_files=False, force=True)

	db_name = frappe.local.conf.db_name
	frappe.local.db = make_connection(root_login, root_password)
	dbman = DbManager(frappe.local.db)
	dbman.delete_user(db_name, get_current_host())
	dbman.drop_database(db_name)

	archived_sites_dir = os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived_sites')
	if not os.path.exists(archived_sites_dir):
		os.mkdir(archived_sites_dir)
	move(archived_sites_dir, site)
Exemplo n.º 11
0
def drop_site(site,
              root_login='******',
              root_password=None,
              archived_sites_path=None):
    "Remove site from database and filesystem"
    from frappe.installer import get_current_host, make_connection
    from frappe.model.db_schema import DbManager
    from frappe.utils.backups import scheduled_backup

    frappe.init(site=site)
    frappe.connect()
    scheduled_backup(ignore_files=False, force=True)

    db_name = frappe.local.conf.db_name
    frappe.local.db = make_connection(root_login, root_password)
    dbman = DbManager(frappe.local.db)
    dbman.delete_user(db_name, get_current_host())
    dbman.drop_database(db_name)

    if not archived_sites_path:
        archived_sites_path = os.path.join(frappe.get_app_path('frappe'), '..',
                                           '..', '..', 'archived_sites')

    if not os.path.exists(archived_sites_path):
        os.mkdir(archived_sites_path)

    move(archived_sites_path, site)
Exemplo n.º 12
0
def _drop_site(site, root_login='******', root_password=None, archived_sites_path=None, force=False):
	"Remove site from database and filesystem"
	from frappe.installer import get_root_connection
	from frappe.model.db_schema import DbManager
	from frappe.utils.backups import scheduled_backup

	frappe.init(site=site)
	frappe.connect()

	try:
		scheduled_backup(ignore_files=False, force=True)
	except SQLError as err:
		if err[0] == ER.NO_SUCH_TABLE:
			if force:
				pass
			else:
				click.echo("="*80)
				click.echo("Error: The operation has stopped because backup of {s}'s database failed.".format(s=site))
				click.echo("Reason: {reason}{sep}".format(reason=err[1], sep="\n"))
				click.echo("Fix the issue and try again.")
				click.echo(
					"Hint: Use 'bench drop-site {s} --force' to force the removal of {s}".format(sep="\n", tab="\t", s=site)
				)
				sys.exit(1)

	db_name = frappe.local.conf.db_name
	frappe.local.db = get_root_connection(root_login, root_password)
	dbman = DbManager(frappe.local.db)
	dbman.delete_user(db_name)
	dbman.drop_database(db_name)

	if not archived_sites_path:
		archived_sites_path = os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived_sites')

	if not os.path.exists(archived_sites_path):
		os.mkdir(archived_sites_path)

	move(archived_sites_path, site)
Exemplo n.º 13
0
def drop_site(site, root_login='******', root_password=None, archived_sites_path=None):
	"Remove site from database and filesystem"
	from frappe.installer import get_root_connection
	from frappe.model.db_schema import DbManager
	from frappe.utils.backups import scheduled_backup

	frappe.init(site=site)
	frappe.connect()
	scheduled_backup(ignore_files=False, force=True)

	db_name = frappe.local.conf.db_name
	frappe.local.db = get_root_connection(root_login, root_password)
	dbman = DbManager(frappe.local.db)
	dbman.delete_user(db_name)
	dbman.drop_database(db_name)

	if not archived_sites_path:
		archived_sites_path = os.path.join(frappe.get_app_path('frappe'), '..', '..', '..', 'archived_sites')

	if not os.path.exists(archived_sites_path):
		os.mkdir(archived_sites_path)

	move(archived_sites_path, site)
Exemplo n.º 14
0
def _drop_site(site,
               root_login='******',
               root_password=None,
               archived_sites_path=None,
               force=False):
    "Remove site from database and filesystem"
    from frappe.installer import get_root_connection
    from frappe.model.db_schema import DbManager
    from frappe.utils.backups import scheduled_backup

    frappe.init(site=site)
    frappe.connect()

    try:
        scheduled_backup(ignore_files=False, force=True)
    except SQLError as err:
        if err[0] == ER.NO_SUCH_TABLE:
            if force:
                pass
            else:
                click.echo("=" * 80)
                click.echo(
                    "Error: The operation has stopped because backup of {s}'s database failed."
                    .format(s=site))
                click.echo("Reason: {reason}{sep}".format(reason=err[1],
                                                          sep="\n"))
                click.echo("Fix the issue and try again.")
                click.echo(
                    "Hint: Use 'bench drop-site {s} --force' to force the removal of {s}"
                    .format(sep="\n", tab="\t", s=site))
                sys.exit(1)

    db_name = frappe.local.conf.db_name
    frappe.local.db = get_root_connection(root_login, root_password)
    dbman = DbManager(frappe.local.db)
    dbman.delete_user(db_name, host="%")
    dbman.delete_user(db_name)
    dbman.drop_database(db_name)

    if not archived_sites_path:
        archived_sites_path = os.path.join(frappe.get_app_path('frappe'), '..',
                                           '..', '..', 'archived_sites')

    if not os.path.exists(archived_sites_path):
        os.mkdir(archived_sites_path)

    move(archived_sites_path, site)
Exemplo n.º 15
0
def create_database_and_user(force, verbose):
    db_name = frappe.local.conf.db_name
    dbman = DbManager(frappe.local.db)
    if force or (db_name not in dbman.get_database_list()):
        dbman.delete_user(db_name)
        dbman.drop_database(db_name)
    else:
        raise Exception("Database %s already exists" % (db_name, ))

    dbman.create_user(db_name, frappe.conf.db_password)
    if verbose: print("Created user %s" % db_name)

    dbman.create_database(db_name)
    if verbose: print("Created database %s" % db_name)

    dbman.grant_all_privileges(db_name, db_name)
    dbman.flush_privileges()
    if verbose:
        print("Granted privileges to user %s and database %s" %
              (db_name, db_name))

    # close root connection
    frappe.db.close()
Exemplo n.º 16
0
def create_database_and_user(force, verbose):
	db_name = frappe.local.conf.db_name
	dbman = DbManager(frappe.local.db)
	if force or (db_name not in dbman.get_database_list()):
		dbman.delete_user(db_name)
		dbman.drop_database(db_name)
	else:
		raise Exception("Database %s already exists" % (db_name,))

	dbman.create_user(db_name, frappe.conf.db_password)
	if verbose: print "Created user %s" % db_name

	dbman.create_database(db_name)
	if verbose: print "Created database %s" % db_name

	dbman.grant_all_privileges(db_name, db_name)
	dbman.flush_privileges()
	if verbose: print "Granted privileges to user %s and database %s" % (db_name, db_name)

	# close root connection
	frappe.db.close()
Exemplo n.º 17
0
    def make_database(self):
        dbman = DbManager(get_root_connection())

        # make database
        if not help_db_name in dbman.get_database_list():
            dbman.create_user(help_db_name, help_db_name)
            dbman.create_database(help_db_name)
            dbman.grant_all_privileges(help_db_name, help_db_name)
            dbman.flush_privileges()
Exemplo n.º 18
0
	def make_database(self):
		'''make database for global help setup'''
		if not self.global_help_setup:
			return

		dbman = DbManager(get_root_connection())
		dbman.drop_database(self.help_db_name)

		# make database
		if not self.help_db_name in dbman.get_database_list():
			try:
				dbman.create_user(self.help_db_name, self.help_db_name)
			except Exception as e:
				# user already exists
				if e.args[0] != 1396: raise
			dbman.create_database(self.help_db_name)
			dbman.grant_all_privileges(self.help_db_name, self.help_db_name)
			dbman.flush_privileges()
Exemplo n.º 19
0
    def make_database(self):
        '''make database for global help setup'''
        if not self.global_help_setup:
            return

        dbman = DbManager(get_root_connection())
        dbman.drop_database(self.help_db_name)

        # make database
        if not self.help_db_name in dbman.get_database_list():
            try:
                dbman.create_user(self.help_db_name, self.help_db_name)
            except Exception as e:
                # user already exists
                if e.args[0] != 1396: raise
            dbman.create_database(self.help_db_name)
            dbman.grant_all_privileges(self.help_db_name, self.help_db_name)
            dbman.flush_privileges()