New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data migrations v2 #1956
Data migrations v2 #1956
Conversation
We can use udata models in there, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few typos.
CHANGELOG.md
Outdated
|
||
### Breaking changes | ||
|
||
- The new migration system ([#1956](https://github.com/opendatateam/udata/pull/1956)) use a new python based format. Pre-2.0 migrations are not compatible so you might need to upgrade to the latest `udata` version `<2.0.0`, execute migrations and then upgrade to `udata` 2+. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/use/uses/
udata/commands/db.py
Outdated
@click.argument('filename', default=None, required=False, metavar='[FILENAME]') | ||
def info(plugin_or_specs, filename): | ||
''' | ||
Display detailled info about a migration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/detailled/detailed/
udata/migrations/__init__.py
Outdated
''' | ||
Status is the status of the last operation. | ||
|
||
Will be `None` is the record doesn't exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/is/if/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/exists/exist/
udata/migrations/__init__.py
Outdated
self.module.rollback(db) | ||
out = _extract_output(q) | ||
self.add_record('rollback', out, db._state, True) | ||
msg = 'Error while executing migration, rollback has been applyied' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/applyied/applied/
udata/migrations/__init__.py
Outdated
return out | ||
|
||
def unrecord(self): | ||
'''Only record a migration without applying it''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong docstring?
udata/migrations/__init__.py
Outdated
return Migration(plugin, filename) | ||
|
||
|
||
def list_availables(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/list_availables/list_available/
udata/migrations/__init__.py
Outdated
''' | ||
List available migrations for udata and enabled plugins | ||
|
||
Each row is tuple with following signature: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/tuple/a tuple/
udata/migrations/__init__.py
Outdated
|
||
def _iter(plugin, module): | ||
''' | ||
Iter over migrations for a given plugin module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Iter/Iterate/
udata/migrations/__init__.py
Outdated
|
||
|
||
def _module_name(plugin): | ||
'''Get the module namefor a given plugin''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/namefor/name for/
### Breaking changes - Migration to Python 3.7 [#1766](#1766) - The new migration system ([#1956](#1956)) uses a new python based format. Pre-2.0 migrations are not compatible so you might need to upgrade to the latest `udata` version `<2.0.0`, execute migrations and then upgrade to `udata` 2+. - The targeted mongo version is now Mongo 3.6. Backward support is not guaranteed ### New features - New migration system [#1956](#1956): - Use python based migrations instead of relying on mongo internal and deprecated `js_exec` - Handle rollback (optionnal) - Detailled history - Template hooks generalization: allows to dynamically extend template with widgets and snippets from extensions. See [the dedicated documentation section](https://udata.readthedocs.io/en/stable/extending/#hooks) [#2323](#2323) - Markdown now supports [Github Flavored Markdown (GFM) specs](https://github.github.com/gfm/) (ie. the already supported [CommonMark specs](https://spec.commonmark.org) plus tables, strikethrough, autolinks support and predefined disallowed raw HTML) [#2341](#2341)
This PR introduce a new migration engine and drops legacy JS migrations.
Migrations are now python based allowing to reuse some udata helpers.
Migration format
A migration file is structured like this:
Logging
If you want to output some logging, just use the standard python logging facilities
Rollback/revert handling
A migration can optionnaly be reverted. You need to add the optionnal
rollback()
method:Commands
udata db migrate
udata db status
udata db info <migration>
udata db unrecord <migration>
Miscellaneous
As a positive side-effect, migrations are not depending anymore on raw Mongo
db.eval
which:Fixes #981