Skip to content
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

alembic: documentation #88

Merged
merged 1 commit into from
Jun 23, 2017
Merged

Conversation

dinosk
Copy link
Member

@dinosk dinosk commented Jun 21, 2017

No description provided.

@dinosk dinosk self-assigned this Jun 21, 2017
alembic.rst Outdated
@@ -0,0 +1,84 @@
Alembic
=======
Alembic is a database migration tool for usage with SQLAlchemy Database. The full documentation can be found here:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can be found here: -> missing link
  • s/tool for usage with SQLAlchemy Database/library used with the SQLAlchemy ORM/

alembic.rst Outdated
Alembic
=======
Alembic is a database migration tool for usage with SQLAlchemy Database. The full documentation can be found here:
In invenio the alembic environment is already defined in invenio-db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invenio-DB fully supports Alembic and each Invenio module having a database model is also expected to provide the corresponding alembic scripts.

alembic.rst Outdated
Creating new revisions
----------------------

When working with an invenio module that already has alembic revisions, after modifying a model we can create a new alembic revision with:
Copy link
Member

@nharraud nharraud Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if users could follow the script from top to bottom without jumping back and forth. Also we need to explain as if the user just discovered alembic and/or invenio-db and does not now how to search for alembic scripts.

What do you think instead of this:

===

Create an alembic upgrade script

The following procedure will add an alembic upgrade script to invenio-unicorn for demonstration purpose.

First you need to check if your module has already some alembic scripts. Open the setup.py file and see if there is an invenio_db.alembic entrypoints property like this:

setup(
    ...
    entry_points={
        ...
        'invenio_db.alembic': [
            'invenio_unicorn = invenio_unicorn:alembic',
        ]
...
})

If there is one, go the the package invenio_unicorn.alembic and check if there is a python script in it. It should have a name similar to: 843bc79c426f_create_invenio_unicorn_branch.py (the numbers and letters at the beginning will not be the same).

If the setup.py file does not contain the invenio_db.alembic property or if the invenio_unicorn.alembic package is empty you need to create an upgrade branch first, continue to the next section. Otherwise you can skip the next section.

Adding Alembic support

... (setup.py + alembic branch)

Create the new upgrade script

...

alembic.rst Outdated

$ invenio alembic revision "Added some column." --path alembic_directory_path

A short message describing the changes is required and the path parameter should point to the alembic directory of the module. If the path is not given the new revision will be placed in the invenio_db/alembic directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the path is not given the new revision will be placed in the invenio_db/alembic directory which is not the desired behavior.

alembic.rst Outdated

.. code-block:: console

$ invenio alembic upgrade heads
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we start by running this before creating the new script so that everything is up to date? The user can normally run this without worrying about breaking anything as long as he didn't create his migration script.

alembic.rst Outdated
A short message describing the changes is required and the path parameter should point to the alembic directory of the module. If the path is not given the new revision will be placed in the invenio_db/alembic directory.

The directories accepted are registered by the invenio_db.alembic entrypoints.
If the DB has not been updated to show the last changes, there is some alembic revision that needs to be applied by:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear if this talks about the "last changes" as the newly created migration script or any previous script which was not yet ran.

alembic.rst Outdated

$ invenio alembic mkdir

in invenio_unicorn and add the invenio_db.alembic entrypoint in setup.py:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove in invenio_unicorn and. The sentence is hard to read if it is split by code.
=> Add the invenio_db.alembic entrypoint in setup.py:

@dinosk dinosk force-pushed the alembic-doc branch 4 times, most recently from 56d0192 to df0f229 Compare June 22, 2017 09:05
@dinosk dinosk changed the title wip alembic: addition of documentation alembic: addition of documentation Jun 22, 2017
@dinosk dinosk requested a review from krzysztof June 22, 2017 10:47
@dinosk dinosk changed the title alembic: addition of documentation alembic: documentation Jun 22, 2017
@dinosk dinosk force-pushed the alembic-doc branch 2 times, most recently from 9b097d6 to 7ba9085 Compare June 22, 2017 11:20
@dinosk dinosk removed the request for review from jmartinm June 22, 2017 13:43
Signed-off-by: Dinos Kousidis <konstantinos.kousidis@cern.ch>
Co-authored-by: Nicolas Harraudeau <nicolas.harraudeau@cern.ch>
@lnielsen lnielsen merged commit 1562354 into inveniosoftware:master Jun 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants