Closed Bug 777650 Opened 12 years ago Closed 10 years ago

Add a db migration script for the tokenserver

Categories

(Cloud Services Graveyard :: Server: Token, defect, P3)

x86
Linux
defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: alexis+bugs, Assigned: rfkelly)

References

Details

(Whiteboard: [qa+])

Attachments

(1 file)

We need a way to do proper migrations of our schema for the tokenserver / wimms.

I'm thinking in terms of alter tables mainly. I don't know if something exists already that would solve our issues. but having a way to apply some files in one way or the other sounds like a welcome addition.
Whiteboard: [qa?]
Not sure if we need to handle this from the dev side or from the ops side. Feedback appreciated.
Alembic seems to be the best in class SQLAlchemy migration tool, written by Michael Bayer (SQLAlchemy author):

http://pypi.python.org/pypi/alembic/0.3.5
http://alembic.readthedocs.org/en/latest/index.html

After getting Alembic set up ops would run `alembic upgrade head` to apply all database migrations and `alembic downgrade <REV_UUID>` to revert.
(In reply to Alexis Metaireau (:alexis) from comment #1)
> Not sure if we need to handle this from the dev side or from the ops side.
> Feedback appreciated.

Something else to consider here is third-party deployments of our stack.  It would be great if the migrations are exposed in a way that's easy for the to apply, so I think something like alembic would be useful even if ops don't use it directly.
Blocks: 956217
Priority: -- → P3
Summary: Add a migration script for the tokenserver → Add a db migration script for the tokenserver
Related: (via :mostlygeek) Regarding schema handling the FxA guys have this: https://github.com/mozilla/fxa-auth-server/blob/master/bin/db_patcher.js
Status: NEW → ASSIGNED
Whiteboard: [qa?] → [qa+]
Blocks: 988643
Depends on: 995767
This patch adds a basic alembic setup to the tokenserver repo, and includes migrations for the two not-yet-in-production deployment requests that I have open in Bug 986204 and Bug 993537.

To use them, you first have to "stamp" the database with its current version.  This creates a special table called "alembic_version" to track the schema version.

For prod, which has neither of the two migrations, do:

    ./bin/alembic stamp base

(It will find the token-prod.ini file and read it automatically, or you can pass a TOKEN_INI=/path/to/token.ini environment variable)

For stage, which has Bug 986204 already, we should probably downgrade to match prod so that we can test the entire deployment/migration setup.  This is facilitated by:

  ./bin/alembic stamp 17d209a72e2f
  ./bin/alembic downgrade base

Deployments will be able to migrate the schema by doing:

  ./bin/alembic upgrade head

And if you need to roll back to a previous version then you can:

  ./bin/alembic downgrade 17d209a72e2f

For now the upgrade process is manual, and IMO it should stay that way.  But I'm happy to consider further automation once we get comfortable with the 
workflow.

Thoughts?
Assignee: nobody → rfkelly
Attachment #8405897 - Flags: review?(telliott)
Attachment #8405897 - Flags: feedback?(bwong)
Blocks: 993537
No longer blocks: 993537
Comment on attachment 8405897 [details] [diff] [review]
tokenserver-alembic-migrations.diff

Review of attachment 8405897 [details] [diff] [review]:
-----------------------------------------------------------------

Why do we need mako? I see the system already has it, but it seems like an odd dependency to have on a pure backend system. Otherwise, looks OK.
Attachment #8405897 - Flags: review?(telliott) → review+
> Why do we need mako? 

I think pyramid pulls this in by default.  We don't use it, but we might as well pin in the deps so they're a more realistic portrayal of what's on the system.
Committed in:
https://github.com/mozilla-services/tokenserver/commit/be018f5613d3290b863649266dc782432cc63bc7
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Comment on attachment 8405897 [details] [diff] [review]
tokenserver-alembic-migrations.diff

I chatted with benson about this IRL, clearing feedback flag.
Attachment #8405897 - Flags: feedback?(bwong)
I do believe we have completed this work as of last week...
Status: RESOLVED → VERIFIED
Product: Cloud Services → Cloud Services Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: