Browse Source

better docs on handling migrations..

main
John-Mark Gurney 2 months ago
parent
commit
7bbb97448b
1 changed files with 34 additions and 2 deletions
  1. +34
    -2
      ui/medashare/alembic/README

+ 34
- 2
ui/medashare/alembic/README View File

@@ -1,7 +1,36 @@
New Version
-----------

To create a revision, update the ORM in medashare/orm.py.
First make a test in `_TestMigrations` with the data that you will need.
Use the first 5 characters for the test name. Then dump the data to a
file so that it can be read back in. From the test fixture that setups
the data, use the code:
```
tf = pathlib.Path('fixtures/test_<oldversion>.sqlite').absolute()
engine_file = sqlalchemy.create_engine('sqlite+pysqlite:///' + str(tf))
raw_connection_file = engine_file.raw_connection()

objcon.backup(raw_connection_file.connection)

raw_connection_file.close()
engine_file.dispose()
objcon.close()
```

Then you can comment it out, or use `if False: #pragma: no cover` and
replace it with the following to load the saved database:
```
<tf from above>
objcon = self._engine.raw_connection()
engine_file = sqlalchemy.create_engine('sqlite+pysqlite:///' + str(tf))
raw_connection_file = engine_file.raw_connection()
raw_connection_file.connection.backup(objcon.connection)
raw_connection_file.close()
engine_file.dispose()
objcon.close()
```

Update the ORM in `medashare/orm.py` as needed.

Then in the medashare directory, run:
```
@@ -9,7 +38,10 @@ Then in the medashare directory, run:
```

This will create a version file. Edit the version file to support the
migration (such as populating new columns).
migration (such as populating new columns or tables).

Finish the test for the migration. Note, you may need to update code
to handle older versions. This can be handled by calling xxx. (TODO)

Once things are tested as good, commit everything.



Loading…
Cancel
Save