I have a pattern that's something like this:

  1. Create a database model UsagePlan which stores how many usage tokens a paid customer receives in exchange for its respective monthly fee. Through my ORM (Django), I override the save method to not allow any writes to this table from my code.

  2. I create a fixture that specifies the usage plans as my client specified them. Every time I deploy, this fixture gets loaded into the database (idempotently).

  3. I create another model LiveUsagePlan. When a user turns into a paid customer, an instance of this model is related to the user and stores a copy of the UsagePlanthat they picked.

  4. My client updates their usage plans, so I update the fixture and deploy. Current customers aren't affected since their LiveUsagePlans don't change ("grandfathered"), however all new customers' LiveUsagePlans will copy the new UsagePlans

I am skeptical of this pattern, as I made it up and have never seen it anywhere else. I've also never seen fixtures used outside of the context of tests. Are there any glaring problems that I'm not seeing? What's the best way to handle this kind of mostly-static state?

  • This sounds a bit like seeding the database - useful for testing data in non-production environments before releasing. – HorusKol Jan 21 '17 at 15:25
  • And steps 3 and 4 resemble how e-commerce sites record purchase information on products that can vary or be deleted after purchase. Sometimes, simply relating the data from an order to the product (or usage plan) is not enough. – HorusKol Jan 21 '17 at 15:27
  • This is used in production. Like I said, I've never seen fixtures used outside the context of testing. – Julien Jan 21 '17 at 17:49
  • Sorry - should have been more clear. It's a good way to first test a dataset before you ship it to production. Using a fixture like this means you are delivering the data the same way into the production database as you did in your test environments - and so you should be confident in its application. – HorusKol Jan 21 '17 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.