Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#679 closed defect (fixed)

Database "fixtures" (but not the testing kind)

Reported by: cwebber 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.)

Subtickets

Change History (7)

comment:1 Changed 4 years ago by npigeon

  • Owner set to npigeon
  • Status changed from new to in_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 Changed 4 years ago by npigeon

  • Owner npigeon deleted
  • Status changed from in_progress to review

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 Changed 4 years ago by rodney757

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 Changed 4 years ago by rodney757

  • Owner set to npigeon
  • Status changed from review to in_progress

comment:5 Changed 4 years ago by npigeon

  • Owner npigeon deleted
  • Status changed from in_progress to review

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 Changed 4 years ago by rodney757

  • Resolution set to fixed
  • Status changed from review to closed

Okay cool. Thanks for the tests. Merged!

comment:7 Changed 4 years ago by rodney757

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