Skip to content

Commit

Permalink
feat: support custom default database name (#288) (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoyException authored Dec 20, 2024
1 parent 78284ce commit ee43328
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/backup-restore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
- name: Backup MyDuck and Insert more data into source PG
run: |
psql "postgres://postgres:@127.0.0.1:5432" <<-EOSQL
BACKUP DATABASE mysql TO 's3c://myduck-backup/myduck/myduck.bak'
BACKUP DATABASE myduck TO 's3c://myduck-backup/myduck/myduck.bak'
ENDPOINT = '127.0.0.1:9001'
ACCESS_KEY_ID = 'minioadmin'
SECRET_ACCESS_KEY = 'minioadmin';
Expand All @@ -141,7 +141,7 @@ jobs:
mc stat myminio/myduck-backup/myduck/myduck.bak
pkill myduckserver
rm -f ./mysql.db
rm -f ./myduck.db
# Insert more data in primary while MyDuck is down
psql "postgres://postgres:password@localhost:15432/testdb" \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/psql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ jobs:
run: |
# for each SQL script in the `pgtest/psql` directory (recursively)
for f in pgtest/psql/**/*.sql; do
psql -h 127.0.0.1 -U mysql -f $f
psql -h 127.0.0.1 -U postgres -d postgres -f $f
done
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ run: build
# Build image locally using Docker Buildx (for testing)
.PHONY: build-image-local
build-image-local:
docker buildx build -t $(IMAGE_NAME):$(IMAGE_TAG) --load .
docker buildx build -f docker/Dockerfile -t $(IMAGE_NAME):$(IMAGE_TAG) --load .

.PHONY: run-image
run-image:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ With MyDuck's powerful analytics capabilities, you can create an hybrid transact

### Customizing the Docker Container

To rename the default database, pass the `DEFAULT_DB` environment variable to the Docker container:

```bash
docker run -p 13306:3306 -p 15432:5432 --env=DEFAULT_DB=mydbname apecloud/myduckserver:latest
```

To initialize MyDuck Server with custom SQL statements, mount your `.sql` file to either `/docker-entrypoint-initdb.d/mysql/` or `/docker-entrypoint-initdb.d/postgres/` inside the Docker container, depending on the SQL dialect you're using.

For example:
Expand Down
6 changes: 5 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ run_replica_setup() {

run_server_in_background() {
cd "$DATA_PATH" || { echo "Error: Could not change directory to ${DATA_PATH}"; exit 1; }
nohup myduckserver $LOG_LEVEL $PROFILER_PORT $RESTORE_FILE $RESTORE_ENDPOINT $RESTORE_ACCESS_KEY_ID $RESTORE_SECRET_ACCESS_KEY|tee -a "${LOG_PATH}/server.log" 2>&1 &
nohup myduckserver $DEFAULT_DB $LOG_LEVEL $PROFILER_PORT $RESTORE_FILE $RESTORE_ENDPOINT $RESTORE_ACCESS_KEY_ID $RESTORE_SECRET_ACCESS_KEY|tee -a "${LOG_PATH}/server.log" 2>&1 &
echo "$!" > "${PID_FILE}"
}

Expand Down Expand Up @@ -203,6 +203,10 @@ setup() {
# Setup signal handlers
trap cleanup SIGTERM SIGINT SIGQUIT

if [ -n "$DEFAULT_DB" ]; then
export DEFAULT_DB="--default-db=$DEFAULT_DB"
fi

if [ -n "$LOG_LEVEL" ]; then
export LOG_LEVEL="--loglevel=$LOG_LEVEL"
fi
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ var (
address = "0.0.0.0"
port = 3306
socket string
defaultDb = "mysql"
defaultDb = "myduck"
dataDirectory = "."
dbFileName = defaultDb + ".db"
dbFileName string
logLevel = int(logrus.InfoLevel)

replicaOptions replica.ReplicaOptions
Expand Down Expand Up @@ -94,6 +94,7 @@ func ensureSQLTranslate() {

func main() {
flag.Parse() // Parse all flags
dbFileName = defaultDb + ".db"

if replicaOptions.ReportPort == 0 {
replicaOptions.ReportPort = port
Expand Down

0 comments on commit ee43328

Please sign in to comment.