Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/database_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This command will:
5. Start the container

The Docker container uses:
- Image: `datajoint/mysql:5.7` (https://github.com/datajoint/mysql-docker)
- Image: `datajoint/mysql:8` (https://github.com/datajoint/mysql-docker)
- Port: 3306 (standard MySQL port)
- Volume: `./data_ethopy_sql_db:/var/lib/mysql` for persistent data storage

Expand All @@ -38,10 +38,9 @@ If you prefer to set up the container manually:

1. Create a `docker-compose.yaml` file:
```yaml
version: '2.4'
services:
ethopy_sql_db:
image: datajoint/mysql:5.7
image: datajoint/mysql:8
environment:
- MYSQL_ROOT_PASSWORD=your_password
ports:
Expand Down
18 changes: 15 additions & 3 deletions src/ethopy/setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import socket
import subprocess
import sys
from pathlib import Path
from time import sleep
from typing import List, Optional, Tuple
Expand Down Expand Up @@ -197,16 +198,27 @@ def setup_dj_docker(mysql_path: Optional[str], container_name: str) -> None:
mysql_dir.mkdir(parents=True, exist_ok=True)
os.chdir(str(mysql_dir))

# MySQL only honours MYSQL_ROOT_PASSWORD when it initialises an empty
# data directory, so a leftover one silently keeps its old credentials.
data_dir = mysql_dir / f"data_{container_name}"
if data_dir.exists():
click.echo(
f"WARNING: a MySQL data directory already exists at {data_dir}.\n"
"MySQL will reuse it and IGNORE the password entered below - the "
"root password stored in that directory stays in force.\n"
"Enter that existing password, or press Ctrl-C and move the "
"directory aside to start from a clean database."
)

# Get password securely using Click's password prompt
mysql_password = click.prompt(
"Enter the MySQL root password", hide_input=True, confirmation_prompt=True
)

docker_content = (
f"version: '2.4'\n"
f"services:\n"
f" {container_name}:\n"
f" image: datajoint/mysql:5.7\n"
f" image: datajoint/mysql:8\n"
f" environment:\n"
f" - MYSQL_ROOT_PASSWORD={mysql_password}\n"
f" ports:\n"
Expand Down Expand Up @@ -294,7 +306,7 @@ def _run_import(schema_name: str, cmd: str) -> Optional[str]:
try:
# Capture both stdout and stderr
_ = subprocess.run(
["python", "-c", cmd], check=True, capture_output=True, text=True
[sys.executable, "-c", cmd], check=True, capture_output=True, text=True
)
click.echo(f"Successfully created tables for: {schema_name}")
return None
Expand Down
Loading