This document explains how to test migrated schema of Optuna's RDBStorage. The test consists of following two parts:
- Test for values
- Test for schema
Each section describes the test instruction for each database.
The following software is required:
- docker
- Python 3.6+
Then, please in stall DB drivers:
$ pip install PyMySQL psycopg2-binary
Install the current version of optuna and create tables:
$ pip uninstall optuna # if necessary
$ pip install optuna
$ python migration-prepare.py sqlite:///example.db
Upgrade optuna to the patched version
$ pip uninstall optuna
$ pip install git+https://github.com/HideakiImamura/optuna.git@refactoring/change-rdb-schema-for-mo-refactoring
Check if RuntimeError
occurs due to the incompatibility of the schema.
$ python migration-assert.py sqlite:///example.db
optuna version: 2.3.0
...
RuntimeError: The runtime optuna version 2.3.0 is no longer compatible with the table schema (set up by optuna 2.3.0). Please execute `$ optuna storage upgrade --storage $STORAGE_URL` for upgrading the storage.
Upgrade the schema
$ optuna storage upgrade --storage sqlite:///example.db
Check the migration results
$ python migration-assert.py sqlite:///example.db
OK
Please run following two scripts. The first one execute migration-prepare.py
with optuna@master
while the second one execute it with optuna v2.3.0 and upgrade the DB.
rm -f example.db
pip install -U git+https://github.com/optuna/optuna.git
python migration-prepare.py sqlite:///example.db
echo ".dump" | sqlite3 example.db > master.sqlite
rm -f example.db
pip install -U optuna
python migration-prepare.py sqlite:///example.db
pip install -U git+https://github.com/optuna/optuna.git
optuna storage upgrade --storage sqlite:///example.db
echo ".dump" | sqlite3 example.db > upgrade.sqlite
The schema of these two should be identical except for trials' result. Please check the diff of the dump files, for example, as follows:
python sqlite_extract_create.py master.sqlite > master-create.sqlite
python sqlite_extract_create.py upgrade.sqlite > upgrade-create.sqlite
diff master-create.sqlite upgrade-create.sqlite | less -S
Install the current version of optuna, launch a DB server, and create tables:
$ pip uninstall optuna # if necessary
$ pip install optuna
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -p 33060:33060 -d mysql:5.7
$ docker run --network host -it --rm mysql:5.7 mysql -h 127.0.0.1 -uroot -p -e "create database optunatest;"
$ python migration-prepare.py mysql+pymysql://root:test@localhost/optunatest
Upgrade optuna to the patched version
$ pip uninstall optuna
$ pip install git+https://github.com/HideakiImamura/optuna.git@refactoring/change-rdb-schema-for-mo-refactoring
Check if RuntimeError
occurs due to the incompatibility of the schema.
$ python migration-assert.py mysql+pymysql://root:test@localhost/optunatest
optuna version: 2.3.0
...
RuntimeError: The runtime optuna version 2.3.0 is no longer compatible with the table schema (set up by optuna 2.3.0). Please execute `$ optuna storage upgrade --storage $STORAGE_URL` for upgrading the storage.
Upgrade the schema
$ optuna storage upgrade --storage mysql+pymysql://root:test@localhost/optunatest
Check the migration results
$ python migration-assert.py mysql+pymysql://root:test@localhost/optunatest
OK
Please run following two scripts. The first one execute migration-prepare.py
with optuna@master
while the second one execute it with optuna v2.3.0 and upgrade the DB.
docker rm -f some-mysql
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -p 33060:33060 -d mysql:5.7
sleep 20
docker run --network host -it --rm mysql:5.7 mysql -h 127.0.0.1 -uroot -p -e "create database optunatest;"
pip install git+https://github.com/optuna/optuna.git
python migration-prepare.py mysql+pymysql://root:test@localhost/optunatest
mysqldump --skip-column-statistics -u root -p -h 127.0.0.1 optunatest > master.mysql
docker rm -f some-mysql
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -p 33060:33060 -d mysql:5.7
sleep 20
docker run --network host -it --rm mysql:5.7 mysql -h 127.0.0.1 -uroot -p -e "create database optunatest;"
pip install optuna
python migration-prepare.py mysql+pymysql://root:test@localhost/optunatest
pip install git+https://github.com/optuna/optuna.git
optuna storage upgrade --storage mysql+pymysql://root:test@localhost/optunatest
echo "test" | mysqldump --skip-column-statistics -u root -p -h 127.0.0.1 optunatest > upgrade.mysql
The schema of these two should be identical except for trials' result. Please check the diff of the dump files, for example, as follows:
diff master.mysql upgrade.mysql | less -S
Install the current version of optuna and create tables:
$ pip uninstall optuna # if necessary
$ pip install optuna
$ docker run -it --rm --name postgres-test -e POSTGRES_PASSWORD=test -p 15432:5432 -d postgres
$ python migration-prepare.py postgresql+psycopg2://postgres:test@localhost:15432/postgres
Upgrade optuna to the patched version
$ pip uninstall optuna
$ pip install git+https://github.com/HideakiImamura/optuna.git@refactoring/change-rdb-schema-for-mo-refactoring
Check if RuntimeError
occurs due to the incompatibility of the schema.
$ python migration-assert.py postgresql+psycopg2://postgres:test@localhost:15432/postgres
optuna version: 2.3.0
...
RuntimeError: The runtime optuna version 2.3.0 is no longer compatible with the table schema (set up by optuna 2.3.0). Please execute `$ optuna storage upgrade --storage $STORAGE_URL` for upgrading the storage.
Upgrade the schema
$ optuna storage upgrade --storage postgresql+psycopg2://postgres:test@localhost:15432/postgres
Check the migration results
$ python migration-assert.py postgresql+psycopg2://postgres:test@localhost:15432/postgres
OK
Please run following two scripts. The first one execute migration-prepare.py
with optuna@master
while the second one execute it with optuna v2.3.0 and upgrade the DB.
docker rm -f postgres-test
docker run -it --rm --name postgres-test -e POSTGRES_PASSWORD=test -p 15432:5432 -d postgres
sleep 10
pip install git+https://github.com/optuna/optuna.git
python migration-prepare.py postgresql+psycopg2://postgres:test@localhost:15432/postgres
pg_dump -h localhost -p 15432 -U postgres -d postgres > master.psql
docker rm -f postgres-test
docker run -it --rm --name postgres-test -e POSTGRES_PASSWORD=test -p 15432:5432 -d postgres
sleep 10
pip install optuna
python migration-prepare.py postgresql+psycopg2://postgres:test@localhost:15432/postgres
pip install git+https://github.com/optuna/optuna.git
optuna storage upgrade --storage postgres+psycopg2://postgres:test@localhost:15432/postgres
pg_dump -h localhost -p 15432 -U postgres -d postgres > upgrade.psql
The schema of these two should be identical except for trials' result. Please check the diff of the dump files, for example, as follows:
diff master.psql upgrade.psql | less -S