You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f4f51a2
Browse filesBrowse the repository at this point in the historyBrowse files
Script to run v2 migration commands (Zipstack#791)
* Script to run migration commands, some docs added for migration to v2, minor fix to run on OSS
* Apply suggestions from code review
Co-authored-by: Hari John Kuriakose <hari@zipstack.com>
Signed-off-by: Chandrasekharan M <117059509+chandrasekharan-zipstack@users.noreply.github.com>
* Script to support printing release warnings, addressed review comments
* Addressed review comments, restructured migrating README.md, updated run-platform.sh to support showing release notes
* Apply suggestions from code review
Co-authored-by: Hari John Kuriakose <hari@zipstack.com>
Signed-off-by: Chandrasekharan M <117059509+chandrasekharan-zipstack@users.noreply.github.com>
* Minor formatting changes
---------
Signed-off-by: Chandrasekharan M <117059509+chandrasekharan-zipstack@users.noreply.github.com>
Co-authored-by: Hari John Kuriakose <hari@zipstack.com>
Copy file name to clipboardExpand all lines: backend/migrating/v2/README.md
+114-8Lines changed: 114 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,119 @@
1
-
# V2 Migrations and Commands
1
+
# V2 Migration Guide
2
2
3
3
This folder contains scripts and management commands for performing data migrations from v1 to v2 for the Unstract Multitenancy system.
4
+
From version `v0.93.0` onwards, there have been signifcant changes in how data is stored. This warrants a data migration and the below steps can come in handy.
4
5
5
-
## Overview
6
+
> [!WARNING]
7
+
> If you're updating from a very old version of Unstract and you face issues, its recommended to update to `v0.92.1` with
8
+
`./run-platform.sh -u -v v0.92.1` first and then perform this data migration.
6
9
7
-
The commands provided here help you manage the migration process, including creating and dropping schemas and applying the necessary migrations to transition from v1 to v2.
10
+
## Performing the migration
11
+
12
+
> [!TIP]
13
+
> If the existing data is important to you, consider [backing up and restoring to a new database](/backend/migrating/v2/README.md#preparing-for-the-migration-safest-approach) beforehand.
14
+
15
+
Run the `migrate-to-v2.sh` script to perform schema and data migrations in one shot.
16
+
17
+
```shell
18
+
./migrate-to-v2.sh
19
+
```
20
+
21
+
If you prefer explicitly executing the migration commands, refer [these steps below](/backend/migrating/v2/README.md#manually-performing-V2-migration)
22
+
23
+
## Preparing for the migration (safest approach)
24
+
25
+
Follow below steps to backup existing data in case of any issues during the migration
26
+
27
+
### Backup existing data
28
+
29
+
- Make sure `pg_dump` is installed. This would usually be bundled with postgres and can be installed with
30
+
31
+
```shell
32
+
sudo apt-get install postgresql-client
33
+
```
34
+
35
+
- Take a backup of the existing data with the below command (provide the appropriate options)
- Make sure to update all the necessary `.env` files
64
+
- For example, in case of `v2` ensure `backend`, `prompt-service`, and `platform-service``.env` contain `DB_SCHEMA=unstract_v2`
65
+
66
+
### Create a new schema
67
+
68
+
- Create a new schema within the above DB, for example `unstract_v2`
69
+
- This can be done directly in the DB or
70
+
- Run the command supported from [/backend/manage.py](/backend/manage.py), for example in case of `v2`
8
71
72
+
```shell
73
+
python manage.py create_v2_schema
74
+
```
75
+
76
+
### Run schema migrations
77
+
78
+
- Schema migrations are run by django, this gets invoked when running the backend service
79
+
- Or run it explicitly with
80
+
81
+
```shell
82
+
python manage.py migrate
83
+
```
84
+
85
+
- This ensures that the required tables are created or altered
86
+
87
+
### Run data migrations
88
+
89
+
- This helps move the existing data from your current schema to the new schema
90
+
- It can either be run locally or within the backend container
91
+
92
+
```shell
93
+
docker exec -it unstract-backend /bin/bash
94
+
```
95
+
96
+
- Make sure to activate the virtual environment
97
+
98
+
```shell
99
+
source .venv/bin/activate
100
+
```
101
+
102
+
- Perform the data migration
103
+
104
+
```shell
105
+
python manage.py migrate_to_v2
106
+
```
107
+
108
+
- Test to see if the applied migrations work as expected.
109
+
110
+
## Django Commands Reference
111
+
112
+
The commands provided here help you manage the migration process, including creating and dropping schemas and applying the necessary migrations to transition from v1 to v2.
9
113
10
114
**Pre-requisites:**
11
115
Ensure that `migrating.v2` is added to the `SHARED_APPS` in your Django settings.
12
116
13
-
## Available Commands
14
-
15
117
### 1. List Commands
16
118
17
119
To view all available management commands, use:
@@ -27,6 +129,7 @@ To set up the v2 schema in your database, execute:
27
129
```bash
28
130
python manage.py create_v2_schema
29
131
```
132
+
30
133
This command initializes the schema required for v2 migrations.
31
134
32
135
### 3. Drop V2 Schema
@@ -36,9 +139,11 @@ To remove the v2 schema from your database, run:
36
139
```bash
37
140
python manage.py drop_v2_schema
38
141
```
142
+
39
143
Note: Use this command with caution as it will permanently delete the v2 schema and its associated data.
40
144
41
145
### 4. Migrate to V2 Schema
146
+
42
147
To apply migrations and transition data from v1 to v2, use:
0 commit comments