Commit 77d2a5fb authored by Fabien Amarger's avatar Fabien Amarger
Browse files

fix(db-create): Create database into the ~/etc/cubicweb.d folder

parent f64cf7cc8af1
Pipeline #94953 passed with stages
in 4 minutes and 2 seconds
......@@ -296,6 +296,16 @@
f"The parameters are in ~/etc/cubicweb.d/{args.instance_name}/"
)
os.environ.setdefault("CW_DB_DRIVER", "sqlite")
os.environ.setdefault(
"CW_DB_NAME",
str(
Path.home()
/ "etc"
/ "cubicweb.d"
/ args.instance_name
/ f"{args.instance_name}.sqlite"
),
)
os.environ.setdefault("CW_ANONYMOUS_USER", "anon")
os.environ.setdefault("CW_ANONYMOUS_PASSWORD", "anon")
create_instance = (
......@@ -308,6 +318,7 @@
# The source file has to be modified to include sqlite
driver_regexp = re.compile("db-driver.*")
admin_pass = re.compile("password=(.*)")
dbname_regexp = re.compile("db-name=.*")
with open(source_path, "r") as f:
content = f.read()
replaced_content = driver_regexp.sub("db-driver=sqlite", content)
......@@ -311,6 +322,9 @@
with open(source_path, "r") as f:
content = f.read()
replaced_content = driver_regexp.sub("db-driver=sqlite", content)
replaced_content = dbname_regexp.sub(
f"db-name={os.getenv('CW_DB_NAME')}", replaced_content
)
admin_pwd = next(admin_pass.finditer(content)).group(1)
with open(source_path, "w") as f:
......@@ -330,6 +344,11 @@
)
)
create_db_instance = (
f"cubicweb-ctl db-create {args.instance_name} -a --create-db=y --drop=y"
)
run_and_print_if_error(create_db_instance, custom_env=os.environ)
run_and_print_if_error(f"black {cube_master_folder}")
print(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment