Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#679 closed defect (fixed)

Database "fixtures" (but not the testing kind)

Reported by: Christopher Allan Webber Owned by:
Priority: major Milestone: 0.5.0
Component: programming Keywords:
Cc: Parent Tickets:

Description

(Note: this is *not* the best name, because it could be confused with unit testing fixtures... I don't know if there's a better name that does not have that overlap.)

We're using a relational database, and this means there may be expectations that certain rows are installed in tables. This could be for several reasons:

  • we might have a table that contains different license options; by default, we would want to prepopulate with some good ones
  • we might store permissions in the database with certain roles, such as in #678. But in order to check if someone is in the admin group, that group would need to already exist!
  • maybe we could stop storing media type information on media models as a string! Instead, we could have media types like images, video, etc, on a table. But that also means that every time we install a media type it needs to set up a fixture in the application for itself.

As far as I can tell, installing fixtures will happen in a couple of ways:

  • The first time that mediagoblin core or an extension such as a plugin/media type is installed, it will need to set up some common fixtures. We need new tooling for this!
  • Later, new fixtures may be added or changed. This is easy; we do not need a new tooling for this, we can use our existing migrations infrastructure.

So in theory, the above two can be handled both by ./bin/gmg dbupdate... we just need to add new tooling for the former.

(There's one more possibile tool we could add to this: a convenience method that queries for a certain row, and if it doesn't see it, creates it. That's not super necessary though.)

Change History (7)

comment:1 by NattilyPidgin, 11 years ago

Owner: set to NattilyPidgin
Status: newin_progress

I realized that I need to create this in order to effectively do Group permissions #678 in order to effectively add in Admin & Moderation Tools for my OPW project, so I'll grab it then~

check out my progress at my blog @ nattilypf.dreamwidth.org

comment:2 by NattilyPidgin, 11 years ago

Owner: NattilyPidgin removed
Status: in_progressreview

Okay, here's my solution in this ticket.
https://gitorious.org/~npigeon/mediagoblin/npigeons-mediagoblin/commits/ticket-679

I called the fixtures FOUNDATIONS and I basically applied the same rules to them that are already being applied to MIGRATIONS and MODELS. So if a list called FOUNDATIONS exists in a plugin, dbupdate will create those foundations. It is important that people read the documentation in mediagoblin/db/models.py to understand the proper typing of FOUNDATIONS however, because that is the most complex part of this system.

It was a surprisingly small amount of code.

comment:3 by rodney757, 11 years ago

Great!

So I tested this out and everything looks good and works as expected. If you could write tests for this, I will merge this.

Thanks!

comment:4 by rodney757, 11 years ago

Owner: set to NattilyPidgin
Status: reviewin_progress

comment:5 by NattilyPidgin, 11 years ago

Owner: NattilyPidgin removed
Status: in_progressreview

Okay, so I've added a few tests to tests/test_sql_migration.py
the updates are in the same repo in the link below

https://gitorious.org/~npigeon/mediagoblin/npigeons-mediagoblin/commits/ticket-679

comment:6 by rodney757, 11 years ago

Resolution: fixed
Status: reviewclosed

Okay cool. Thanks for the tests. Merged!

comment:7 by rodney757, 11 years ago

Milestone: 0.5.0
Note: See TracTickets for help on using tickets.