Skip to content

Commit 03e4bef

Browse files
committed
feat: [#56] remove unused scripts and write basic upgrage guide
1 parent 0b3aefa commit 03e4bef

File tree

4 files changed

+22
-137
lines changed

4 files changed

+22
-137
lines changed
Lines changed: 22 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,34 @@
1-
# DB migration
1+
# Upgrade from v1.0.0 to v2.0.0
22

3-
With the console command `cargo run --bin upgrade` you can migrate data from `v1.0.0` to `v2.0.0`. This migration includes:
3+
## How-to
44

5-
- Changing the DB schema.
6-
- Transferring the torrent files in the dir `uploads` to the database.
5+
To upgrade from version `v1.0.0` to `v2.0.0` you have to follow these steps:
76

8-
## SQLite3
7+
- Back up your current database and the `uploads` folder. You can find which database and upload folder are you using in the `Config.toml` file in the root folder of your installation.
8+
- Set up a local environment exactly as you have it in production with your production data (DB and torrents folder).
9+
- Run the application locally with: `cargo run`.
10+
- Execute the upgrader command: `cargo run --bin upgrade`
11+
- A new SQLite file should have been created in the root folder: `data_v2.db`
12+
- Stop the running application and change the DB configuration to use the newly generated configuration:
913

10-
TODO
11-
12-
## MySQL8
13-
14-
Please,
15-
16-
> WARNING: MySQL migration is not implemented yet. We also provide docker infrastructure to run mysql during implementation of a migration tool.
17-
18-
and also:
19-
20-
> WARNING: We are not using a persisted volume. If you remove the volume used by the container you lose the database data.
21-
22-
Run the docker container and connect using the console client:
23-
24-
```s
25-
./upgrades/from_v1_0_0_to_v2_0_0/docker/start_mysql.sh
26-
./upgrades/from_v1_0_0_to_v2_0_0/docker/mysql_client.sh
27-
```
28-
29-
Once you are connected to the client you can create databases with:
30-
31-
```s
32-
create database torrust_v1;
33-
create database torrust_v2;
34-
```
35-
36-
After creating databases you should see something like this:
37-
38-
```s
39-
mysql> show databases;
40-
+--------------------+
41-
| Database |
42-
+--------------------+
43-
| information_schema |
44-
| mysql |
45-
| performance_schema |
46-
| sys |
47-
| torrust_v1 |
48-
| torrust_v2 |
49-
+--------------------+
50-
6 rows in set (0.001 sec)
51-
```
52-
53-
How to connect from outside the container:
54-
55-
```s
56-
mysql -h127.0.0.1 -uroot -pdb-root-password
57-
```
58-
59-
## Create DB for backend `v2.0.0`
60-
61-
You need to create an empty new database for v2.0.0.
62-
63-
You need to change the configuration in `config.toml` file to use MySQL:
64-
65-
```yml
14+
```toml
6615
[database]
67-
connect_url = "mysql://root:[email protected]/torrust_v2"
68-
```
69-
70-
After running the backend with `cargo run` you should see the tables created by migrations:
71-
72-
```s
73-
mysql> show tables;
74-
+-------------------------------+
75-
| Tables_in_torrust_v2 |
76-
+-------------------------------+
77-
| _sqlx_migrations |
78-
| torrust_categories |
79-
| torrust_torrent_announce_urls |
80-
| torrust_torrent_files |
81-
| torrust_torrent_info |
82-
| torrust_torrent_tracker_stats |
83-
| torrust_torrents |
84-
| torrust_tracker_keys |
85-
| torrust_user_authentication |
86-
| torrust_user_bans |
87-
| torrust_user_invitation_uses |
88-
| torrust_user_invitations |
89-
| torrust_user_profiles |
90-
| torrust_user_public_keys |
91-
| torrust_users |
92-
+-------------------------------+
93-
15 rows in set (0.001 sec)
94-
```
95-
96-
### Create DB for backend `v1.0.0`
97-
98-
The `upgrade` command is going to import data from version `v1.0.0` (database and `uploads` folder) into the new empty database for `v2.0.0`.
99-
100-
You can import data into the source database for testing with the `mysql` DB client or docker.
101-
102-
Using `mysql` client:
103-
104-
```s
105-
mysql -h127.0.0.1 -uroot -pdb-root-password torrust_v1 < ./upgrades/from_v1_0_0_to_v2_0_0/db_schemas/db_migrations_v1_for_mysql_8.sql
16+
connect_url = "sqlite://data_v2.db?mode=rwc"
10617
```
10718

108-
Using dockerized `mysql` client:
19+
- Run the application again.
20+
- Perform some tests.
21+
- If all tests pass, stop the production service, replace the DB, and start it again.
10922

110-
```s
111-
docker exec -i torrust-index-backend-mysql mysql torrust_v1 -uroot -pdb-root-password < ./upgrades/from_v1_0_0_to_v2_0_0/db_schemas/db_migrations_v1_for_mysql_8.sql
112-
```
23+
## Tests
11324

114-
### Commands
25+
Before replacing the DB in production you can make some tests like:
11526

116-
Connect to `mysql` client:
117-
118-
```s
119-
mysql -h127.0.0.1 -uroot -pdb-root-password torrust_v1
120-
```
27+
- Try to log in with a preexisting user. If you do not know any you can create a new "test" user in production before starting with the upgrade process. Users had a different hash algorithm for the password in v1.
28+
- Try to create a new user.
29+
- Try to upload and download a new torrent containing a single file.
30+
- Try to upload and download a new torrent containing a folder.
12131

122-
Connect to dockerized `mysql` client:
32+
## Notes
12333

124-
```s
125-
docker exec -it torrust-index-backend-mysql mysql torrust_v1 -uroot -pdb-root-password
126-
```
127-
128-
Backup DB:
129-
130-
```s
131-
mysqldump -h127.0.0.1 torrust_v1 -uroot -pdb-root-password > ./upgrades/from_v1_0_0_to_v2_0_0/db_schemas/v1_schema_dump.sql
132-
mysqldump -h127.0.0.1 torrust_v2 -uroot -pdb-root-password > ./upgrades/from_v1_0_0_to_v2_0_0/db_schemas/v2_schema_dump.sql
133-
```
34+
The `db_schemas` contains the snapshots of the source and destiny databases for this upgrade.

upgrades/from_v1_0_0_to_v2_0_0/docker/start_mysql.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

upgrades/from_v1_0_0_to_v2_0_0/docker/start_mysql_client.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

upgrades/from_v1_0_0_to_v2_0_0/docker/stop_mysql.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)