Skip to content

Commit 45ad11f

Browse files
committed
restore the original alembic comments - moving to separate PR
1 parent 2341a10 commit 45ad11f

File tree

2 files changed

+9
-98
lines changed

2 files changed

+9
-98
lines changed

mlos_bench/mlos_bench/storage/sql/alembic.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
6363
# output_encoding = utf-8
6464

6565
# See README.md for details.
66-
# Uncomment one of these:
6766
sqlalchemy.url = sqlite:///mlos_bench.sqlite
68-
#sqlalchemy.url = mysql+pymysql://root:password@localhost:3306/mlos_bench
69-
#sqlalchemy.url = postgresql+psycopg2://root:password@localhost:5432/mlos_bench
7067

7168

7269
[post_write_hooks]

mlos_bench/mlos_bench/storage/sql/alembic/README.md

Lines changed: 9 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,17 @@ This document contains some notes on how to use [`alembic`](https://alembic.sqla
44

55
## Overview
66

7-
1. Create a blank database instance in the [`mlos_bench/storage/sql`](../) directory with the current schema using the following command:
7+
1. Create a blank `mlos_bench.sqlite` database file in the [`mlos_bench/storage/sql`](../) directory with the current schema using the following command:
88

9-
This allows `alembic` to automatically generate a migration script from the current schema.
10-
11-
> NOTE: If your schema changes target a particular backend engine (e.g., using `with_variant`) you will need to use an engine with that config for this step.
12-
> \
13-
> In the remainder of this document we should some examples for different DB types.
14-
> Pick the one you're targeting and stick with it thru the example.
15-
> You may need to repeat the process several times to test all of them.
16-
>
17-
> - [ ] TODO: Add scripts to automatically do this for several different backend engines all at once.
18-
19-
For instance:
20-
21-
1. Start a temporary server either as a local file or in a docker instance
22-
23-
```sh
24-
# sqlite
25-
cd mlos_bench/storage/sql
26-
rm -f mlos_bench.sqlite
27-
```
28-
29-
```sh
30-
# mysql
31-
docker run -it --rm --name mysql-alembic --env MYSQL_ROOT_PASSWORD=password --env MYSQL_DATABASE=mlos_bench -p 3306:3306 mysql:latest
32-
```
33-
34-
```sh
35-
# postgres
36-
docker run -it --rm --name postgres-alembic --env POSTGRES_PASSWORD=password --env POSTGRES_DB=mlos_bench -p 5432:5432 postgres:latest
37-
```
38-
39-
1. Adjust the `sqlalchemy.url` in the [`alembic.ini`](../alembic.ini) file.
40-
41-
```ini
42-
# Uncomment one of these.
43-
# See README.md for details.
44-
45-
#sqlalchemy.url = sqlite:///mlos_bench.sqlite
46-
sqlalchemy.url = mysql+pymysql://root:password@localhost:3306/mlos_bench
47-
#sqlalchemy.url = postgresql+psycopg2://root:password@localhost:5432/mlos_bench
48-
```
49-
50-
1. Prime the DB schema
51-
52-
```sh
53-
# sqlite
54-
mlos_bench --storage storage/sqlite.jsonc --create-update-storage-schema-only --password=password
55-
```
56-
57-
```sh
58-
# mysql
59-
mlos_bench --storage storage/mysql.jsonc --create-update-storage-schema-only --password=password
60-
```
9+
```sh
10+
cd mlos_bench/storage/sql
11+
rm mlos_bench.sqlite
12+
mlos_bench --storage storage/sqlite.jsonc --create-update-storage-schema-only
13+
```
6114

62-
```sh
63-
# postgres
64-
mlos_bench --storage storage/postgresql.jsonc --create-update-storage-schema-only --password=password
65-
```
15+
> This allows `alembic` to automatically generate a migration script from the current schema.
6616
67-
1. Now, adjust the [`mlos_bench/storage/sql/schema.py`](../schema.py) file to reflect the new desired schema.
17+
1. Adjust the [`mlos_bench/storage/sql/schema.py`](../schema.py) file to reflect the new desired schema.
6818

6919
> Keep each change small and atomic.
7020
> For example, if you want to add a new column, do that in one change.
@@ -73,66 +23,30 @@ This document contains some notes on how to use [`alembic`](https://alembic.sqla
7323
1. Generate a new migration script with the following command:
7424

7525
```sh
76-
alembic revision --autogenerate -m "CHANGEME: Descriptive text about the change."
26+
alembic revision --autogenerate -m "Descriptive text about the change."
7727
```
7828

7929
1. Review the generated migration script in the [`mlos_bench/storage/sql/alembic/versions`](./versions/) directory.
8030

8131
1. Verify that the migration script works by running the following command:
8232

8333
```sh
84-
# sqlite
8534
mlos_bench --storage storage/sqlite.jsonc --create-update-storage-schema-only
8635
```
8736

88-
```sh
89-
# mysql:
90-
mlos_bench --storage storage/mysql.jsonc --create-update-storage-schema-only --password=password
91-
```
92-
93-
```sh
94-
# postgres:
95-
mlos_bench --storage storage/postgresql.jsonc --create-update-storage-schema-only --password=password
96-
```
97-
9837
> Normally this would be done with `alembic upgrade head`, but this command is convenient to ensure if will work with the `mlos_bench` command line interface as well.
9938
10039
Examine the results using something like:
10140

10241
```sh
103-
# For sqlite:
10442
sqlite3 mlos_bench.sqlite .schema
10543
sqlite3 mlos_bench.sqlite "SELECT * FROM alembic_version;"
10644
```
10745

108-
```sh
109-
# For mysql:
110-
mysql --user root --password=password --host localhost --protocol tcp --database mlos_bench -e "SHOW TABLES; SELECT * FROM alembic_version;"
111-
```
112-
113-
```sh
114-
# For postgres:
115-
PGPASSWORD=password psql -h localhost -p 5432 -U postgres mlos_bench -c "SELECT table_name FROM information_schema.tables WHERE table_schema='public' and table_catalog='mlos_bench'; SELECT * FROM alembic_version;"
116-
```
117-
118-
> Use different CLI clients for targeting other engines.
119-
12046
1. If the migration script works, commit the changes to the [`mlos_bench/storage/sql/schema.py`](../schema.py) and [`mlos_bench/storage/sql/alembic/versions`](./versions/) files.
12147

12248
> Be sure to update the latest version in the [`test_storage_schemas.py`](../../../tests/storage/test_storage_schemas.py) file as well.
12349
124-
1. Cleanup any server instances you started.
125-
126-
For instance:
127-
128-
```sh
129-
rm mlos_bench/storage/sql/mlos_bench.sqlite
130-
```
131-
132-
```sh
133-
docker kill mysql-alembic
134-
```
135-
13650
1. Merge that to the `main` branch.
13751

13852
1. Might be good to cut a new `mlos_bench` release at this point as well.

0 commit comments

Comments
 (0)